Skip to main content

Microsoft Silverlight

Unanswered Question DataField not respecting VerticalAlignment for ContentRSS Feed

(0)

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

DataField not respecting VerticalAlignment for Content

DataField does not want to respect the VerticalAlignment rules for its content.

 

<dataFormToolkit:DataField Width="400" Height="400">
  <TextBox Text="Some Text" />
</dataFormToolkit:DataField>

 

All you can do is set a Height on the TextBox, to get some kind of results. But it won't strecth the textbox.

msalsbery
msalsbery

Contributor

Contributor

2066 points

379 Posts

Re: DataField not respecting VerticalAlignment for Content

MComeauS2S:
DataField does not want to respect the VerticalAlignment rules for its content.

I haven't dug around to see what's going on in the DataField template, but have you tried setting the HorizontalAlignment and/or HorizontalContentAlignment properties on the DataField?

Mark Salsbery
Microsoft MVP - Visual C++

Min-Hong Tang - MSFT
Min-Hong...

Contributor

Contributor

3584 points

411 Posts

Re: DataField not respecting VerticalAlignment for Content

Hi,

   I looked at DataField's template and it shows that the verticalAlignment and horizontalContentAlighment is assigned to a certain value.

   It looks like this:

   <ControlTemplate TargetType="dataFormToolkit:DataField">
      <ContentControl x:Name="ContentControl" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="Stretch" IsTabStop="False" VerticalAlignment="Center"/>
  </ControlTemplate>

  It seems you have to edit the template.

Best Regards

Min-Hong Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

Re: DataField not respecting VerticalAlignment for Content

Hi Min-Hong,

I've tried to modify the template, but its still does not want to work. No matter what i do.

All i could do for now, and there is no Guarantee that it will be flawless, was to subclass DataField, and intercept LayoutUpdated event to change the ContentControl's Grid at Row[1], Column[2] from Auto to 1 Star.

public class MyDataField : DataField
{
	public MyDataField() { this.LayoutUpdated += new EventHandler(MyDataField_LayoutUpdated); }

	private void  MyDataField_LayoutUpdated(object sender, EventArgs e)
	{
		if (this.Content != null)
		{
			System.Windows.Controls.Grid grid = VisualTreeHelper.GetParent(this.Content) as System.Windows.Controls.Grid;
			if (grid != null && grid.RowDefinitions.Count > 1)
			{
				grid.RowDefinitions[1].Height = new GridLength(1.0, GridUnitType.Star);
			}
		}
	}
}
 

msalsbery
msalsbery

Contributor

Contributor

2066 points

379 Posts

Re: DataField not respecting VerticalAlignment for Content

MComeauS2S:
But it won't strecth the textbox.

 

I'm not sure what you are seeing here.  My TextBoxes stretch without setting any alignment properties on the DataField or the TextBox.  I haven't altered the DataField template in any way.

I have DataFields contained in a StackPanel with its alignment settings set to Stretch.  For example, this is taken right from a working app....the textboxes are all stretched...

 

    <df:DataForm.EditTemplate>
        <DataTemplate>
            <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                <df:DataField Label="Session" >
                    <TextBlock Text="{Binding Path=xxxx, Mode=OneWay}" />
                </df:DataField>
                <df:DataField Label="Case" >
                    <TextBlock Text="{Binding Path=xxxx, Mode=OneWay}" />
                </df:DataField>
                <df:DataField Label="Corresponding Submitter" >
                    <TextBox Text="{Binding Path=xxxx, Mode=TwoWay}" />
                </df:DataField>
                <df:DataField Label="Organization" >
                    <TextBox Text="{Binding Path=xxxx, Mode=TwoWay}" TextWrapping="Wrap" />
                </df:DataField>
                <df:DataField Label="Proposed Diagnosis" >
                    <TextBox Text="{Binding Path=xxxx, Mode=TwoWay}" TextWrapping="Wrap" />
                </df:DataField>
                <df:DataField Label="Abstract Page #" >
                    <TextBox Text="{Binding Path=xxxx, Mode=TwoWay}" />
                </df:DataField>
                <df:DataField Label="Slide" >
                    <TextBox Text="{Binding Path=xxxx, Mode=TwoWay}" />
                </df:DataField>
            </StackPanel>
        </DataTemplate>
    </df:DataForm.EditTemplate>
  

 

 

Mark Salsbery
Microsoft MVP - Visual C++

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

Re: DataField not respecting VerticalAlignment for Content

Mark, you're right about Horizontal Stretch  .. but try in Vertically !

Best way to try, have a 2 column grid, in column 1 put a stack panel with 4 DataFields,

In column 2, put a single DataField with a TextBox or DataGrid, and try to have them stretch.

Think of it like if you had a Memo Field on the right side !

msalsbery
msalsbery

Contributor

Contributor

2066 points

379 Posts

Re: DataField not respecting VerticalAlignment for Content

MComeauS2S:
you're right about Horizontal Stretch  .. but try in Vertically !
 


Ok, I see what you mean.  I still haven't looked at the actual template but I assume the necessary properties aren't being propagated down to the content, as you already know.

If you haven't already, you may want to post the issue on the toolkit site (on CodePlex).  They'll generally fix it for the next release (or say it's by design).

As a workaround, if you don't need any of the DataField features and can use just a TextBox, you can eliminate the DataField and just use a TextBox alone in column 2.

Or you can maybe fix the template :)


Mark Salsbery
Microsoft MVP - Visual C++

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

Re: DataField not respecting VerticalAlignment for Content

Mark,

The problem is not dependent on the templates. Using Reflector, i was able to figure out that the Content of the DataField is rewired inside a Grid created at run-time.

Take a look at DataField.GenerateUI().

The reason i say that my previous solution is probably not Flawless is because this UI is regenerated from multiple points, and i can't guarantee that all of them trigger a LayoutUpdated event. But other than that, its been working good for me.

Its sad that they make their systems so closed that we can't adapt to them.

I'm wondering if it would it have been possible to make a few templates and choose the required layout with the VisualStateManager!

Anyway, if i find something else, i'll post it here !

msalsbery
msalsbery

Contributor

Contributor

2066 points

379 Posts

Re: DataField not respecting VerticalAlignment for Content

MComeauS2S:
Anyway, if i find something else, i'll post it here !
 


Cool....thanks for the update!

I would still post the issue on CodePlex, because if it's something that needs to be fixed they will certainly look into it.

 

Mark Salsbery
Microsoft MVP - Visual C++

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

Re: DataField not respecting VerticalAlignment for Content

I posted it there, then i thought that maybe someone had a fix for it in here.

msalsbery
msalsbery

Contributor

Contributor

2066 points

379 Posts

Re: DataField not respecting VerticalAlignment for Content

MComeauS2S:
I posted it there, then i thought that maybe someone had a fix for it in here.
 


Ah....then never mind then :)

 

Mark Salsbery
Microsoft MVP - Visual C++
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities