Geeks With Blogs
Scott Van Vliet Once a Developer, Always a Developer

Update 2010-03-23 – Sorry, but the images and downloads were hosted on a server that is no longer available.  I will try to find the sample code bits and images on a backup sometime!

As noted in the WinFXReadme.htm file included with the WinFX January CTP, the preferred syntax for RowDefinitions and Column Definitions is as outlined in the following XAML listing.

 

<Window x:Class="TestApplication.Window2"

    xmlns="http://schemas.microsoft.com/winfx/avalon/2005"

    xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"

    Title="Test Window"

    >

  <Window.Resources>

    <DataTemplate x:Key="MyTemplate">

      <Grid>

        <Grid.RowDefinitions>

          <RowDefinition Height="100" />

        </Grid.RowDefinitions>

      </Grid>

    </DataTemplate>

  </Window.Resources>

    <Grid>

      <Grid.ColumnDefinitions>

        <ColumnDefinition Width="100" />

        <ColumnDefinition Width="Auto" />

      </Grid.ColumnDefinitions>

      <TextBlock Grid.Column="0" Grid.Row="0">My Label</TextBlock>

      <ContentControl Grid.Column="1" Grid.Row="0" ContentTemplate="{StaticResource MyTemplate}" />

    </Grid>

</Window>

 

Although this is the preferred syntax and will compile, it will fail at runtime with the following error.

 

 

BamlParseException was unhandled

Error at element 'Grid' in markup file 'Window2.xaml' : The property 'RowDefinitions' cannot be set as a property element on Template.  Only Triggers and Resources are allowed as property elements..

 

Note that if you include the RowDefinition element at the root of the Grid element (e.g. <Grid><RowDefinition> vs. <Grid><Grid.RowDefinition>) the ContentControl binds and renders as expected.  Thus, I'm really not sure if this error is just misleading based on schema issues, or if Grid.RowDefinition and/or RowDefinition elements cannot be included in a DataTemplate.  I'll post more on this as I dig into it further.

Posted on Monday, January 30, 2006 9:09 AM C# | Back to top


Comments on this post: XAML Grid.RowDefinitions Syntax in DataTemplate Disallowed

# re: XAML Grid.RowDefinitions Syntax in DataTemplate Disallowed
Requesting Gravatar...
In current CTPs you must omit the Grid.RowDefinitions element inside of a ControlTemplate.
<br>For now, the fact that intellisense complains is a limitation of the XSD.
<br>
<br>In future CTPs, you'll see the right syntax (with the .RowDefinitions) supported inside of templates.
<br>
<br>Thx, Rob Relyea
<br>Program Manager, WPF Team
Left by Rob Relyea on Jan 30, 2006 3:34 PM

# re: XAML Grid.RowDefinitions Syntax in DataTemplate Disallowed
Requesting Gravatar...
Thanks for your feedback, Rob! It's good to know that it will be corrected in future versions :)
<br>
<br>For now, I'll track where I'm using ControlTemplates with RowDefinitions and revist those areas when the future versions are released.
Left by Scott Van Vliet on Jan 30, 2006 4:36 PM

# re: XAML Grid.RowDefinitions Syntax in DataTemplate Disallowed
Requesting Gravatar...
I'll be trying out this process. Hope, I'll get this to work well. - Sophia Wong YOR Health
Left by Sophia on Jul 04, 2015 8:16 PM

Your comment:
 (will show your gravatar)


Copyright © svanvliet | Powered by: GeeksWithBlogs.net