Domanda

A pretty strange thing happens when trying to use DataTemplate.DataTriggers in my XAML for Windows 8 Metro app. In my App.xaml, I am defining template for my data. I'd like to use the DataTriggers, but when I type it my VS2012 editor, I get errors stating that

The attachable property 'DataTriggers' was not found in type 'DataTemplate'.

and

The member "DataTriggers" is not recognized or is not accessible.

A similar issue happens when I try to set the DataType property for DataTemplate:

The property 'DataType' was not found in type 'DataTemplate'.

What am I missing here? The DataTemplate works fine without these things, but still it would be much easier for me to use them in my project. Here a short snippet of my XAML:

<DataTemplate x:Key="MyTemplate" >                
            <Grid HorizontalAlignment="Left" Width="450" Height="100">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Rectangle Grid.Row="0" Grid.RowSpan="3" Stretch="UniformToFill" Width="10">
                    <Rectangle.Fill>
                        <SolidColorBrush Color="#FF425400" />
                    </Rectangle.Fill>
                </Rectangle>
                <TextBlock Text="{Binding Title}" Style="{StaticResource TitleTextStyle}" Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2"   />
                <TextBlock Text="{Binding Teaser}" Style="{StaticResource SubtitleTextStyle}"  Grid.Column="1" Grid.Row="1"  Grid.ColumnSpan="2"/>
                <TextBlock Text="{Binding Content}" Style="{StaticResource BasicTextStyle}" Grid.Column="1" Grid.Row="2"  />
                <TextBlock Text="{Binding TimeDesc}" Style="{StaticResource BasicTextStyle}" Grid.Column="2" Grid.Row="2"  />
            </Grid>       
            <DataTemplate.DataTriggers>

            </DataTemplate.DataTriggers>
        </DataTemplate>
È stato utile?

Soluzione

Triggers are only available in WPF, and not on any of the other XAML platforms. Common alternatives are VisualStates, converters, or making changes from code.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top