2

我正在构建一个小型 wp7 应用程序,其中有一个星形用户控件,当单击星形时,它的颜色会发生变化。这是我得到的代码:

    <Grid.Resources>
        <ControlTemplate x:Key="starTemplate"  TargetType="ToggleButton">
             <Viewbox>
                 <Path Name="star" Fill="Gray" Data="F1 M 145.637,174.227L 127.619,110.39L 180.809,70.7577L 114.528,68.1664L 93.2725,5.33333L 70.3262,67.569L 4,68.3681L 56.0988,109.423L 36.3629,172.75L 91.508,135.888L 145.637,174.227 Z"/>
              </Viewbox>
              <ControlTemplate.Triggers>
                  <Trigger Property="IsChecked" Value="True">
                     <Setter TargetName="star" Property="Fill" Value="White"/>
                   </Trigger>
              </ControlTemplate.Triggers>
       </ControlTemplate>
    </Grid.Resources>
    <Grid.ColumnDefinitions>
         <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <ToggleButton Grid.Column="0" Tag="1" Cursor="Hand" Template="{StaticResource starTemplate}" Click="RatingButtonClickEventHandler"/>

问题是它在触发器上给了我一个错误:

The attachable property 'Triggers' was not found in type 'ControlTemplate'

我在此链接中读到 Silverlight 3 不支持样式触发器,我必须在某处实现 DataTrigger。问题是如何?

4

0 回答 0