Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

xaml - DataTemplate.DataTriggers not found?

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...