Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Why can't I have a grid inside a datatemplate?

 
 
Old 03-22-2006   #1 (permalink)
Philippe Lavoie


 
 

Why can't I have a grid inside a datatemplate?

The following

<DataTemplate DataType="{x:Type src:ApparelProduct}">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Width="Auto" Height="Auto" HorizontalAlignment="Stretch"
VerticalAlignment="Center" Grid.RowSpan="3" Grid.ColumnSpan="1"
MinWidth="0" MinHeight="0" ClipToBounds="False" Margin="0,0,0,0"
RenderTransformOrigin="0.5,0.5" IsEnabled="True">
<Image.Source>
<BitmapImage UriSource="{Binding Path=ImageUri}"/>
</Image.Source>
</Image>

<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Name}"
Foreground="{Binding Path=/TemplatedControl}"/>
<TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"
Text="{Binding Path=ShortDescription}" Foreground="{Binding
Path=/TemplatedControl}"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Price}"
Foreground="{Binding Path=/TemplatedControl}"/>
</Grid>
</DataTemplate>


Returns the lovely error:

Error at element 'Grid' in markup file '' : The property
'ColumnDefinitions' cannot be set as a property element on Template.
Only Triggers and Resources are allowed as property elements. Line 106
Position 6.

How can I do the above?

Phil

My System SpecsSystem Spec
Old 03-22-2006   #2 (permalink)
Rob Relyea [MSFT]


 
 

Re: Why can't I have a grid inside a datatemplate?

If you are using a CTP from before February, then you need to embed the
ColumnDefinitions and RowDefintions as direct children of Grid.
That is fixed in Feb CTP.

"Philippe Lavoie" <philippe.lavoie@cactus.ca> wrote in message
news:OHAefIdTGHA.5044@TK2MSFTNGP09.phx.gbl...
> The following
>
> <DataTemplate DataType="{x:Type src:ApparelProduct}">
> <Grid Margin="10">
> <Grid.ColumnDefinitions>
> <ColumnDefinition Width="50"/>
> <ColumnDefinition Width="150"/>
> </Grid.ColumnDefinitions>
> <Grid.RowDefinitions>
> <RowDefinition Height="*"/>
> <RowDefinition Height="*"/>
> <RowDefinition Height="*"/>
> </Grid.RowDefinitions>
> <Image Width="Auto" Height="Auto" HorizontalAlignment="Stretch"
> VerticalAlignment="Center" Grid.RowSpan="3" Grid.ColumnSpan="1"
> MinWidth="0" MinHeight="0" ClipToBounds="False" Margin="0,0,0,0"
> RenderTransformOrigin="0.5,0.5" IsEnabled="True">
> <Image.Source>
> <BitmapImage UriSource="{Binding Path=ImageUri}"/>
> </Image.Source>
> </Image>
>
> <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Name}"
> Foreground="{Binding Path=/TemplatedControl}"/>
> <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"
> Text="{Binding Path=ShortDescription}" Foreground="{Binding
> Path=/TemplatedControl}"/>
> <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Price}"
> Foreground="{Binding Path=/TemplatedControl}"/>
> </Grid>
> </DataTemplate>
>
>
> Returns the lovely error:
>
> Error at element 'Grid' in markup file '' : The property
> 'ColumnDefinitions' cannot be set as a property element on Template. Only
> Triggers and Resources are allowed as property elements. Line 106 Position
> 6.
>
> How can I do the above?
>
> Phil



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
DataTemplate .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46