问题描述
在Windows 8 Metro应用程序的XAML中尝试使用DataTemplate.DataTriggers时,发生了一件非常奇怪的事情.在我的App.xaml中,我正在为数据定义模板.我想使用DataTriggers,但是当我在VS2012编辑器中键入它时,出现错误提示
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
和
当我尝试为DataTemplate设置DataType属性时,也会发生类似的问题:
A similar issue happens when I try to set the DataType property for DataTemplate:
我在这里想念什么?没有这些东西,DataTemplate可以很好地工作,但是对于我来说,在项目中使用它们仍然会容易得多.这是我的XAML的简短片段:
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>
推荐答案
触发器仅在WPF中可用,而在任何其他XAML平台上均不可用.常见的替代方法是VisualStates,转换器或从代码进行更改.
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.
这篇关于找不到DataTemplate.DataTriggers吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!