为什么“<controltemplate.triggers>”无法识别或无法访问?</controltemplate.triggers>

时间:2015-04-02 09:48:00

标签: c# wpf xaml

我想点击某些按钮的样式(IsPressed)(例如,将BorderThickness更改为1, 1, 1, 0)。我已经尝试了<ControlTemplate.Triggers>但是有一个错误:&#34;会员&#39;触发&#39;无法识别或访问&#34;。
这是我的代码:

<UserControl
<!-- ... -->
>
<UserControl.Resources>
    <Style TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border Name="border" Background="LightGray" BorderThickness="2, 2, 2, 1" BorderBrush="Black" CornerRadius="5,5,0,0">
                        <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </Border>
                <ControlTemplate.Triggers> <!-- Here is the error -->
                        <Trigger Property="Button.IsPressed" Value="True">
                            <Setter TargetName="border" Property="BorderThickness" Value="2, 2, 2, 0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</UserControl.Resources>

<Grid x:Name="LayoutRoot" Background="White">
    <!-- some definitions --> 
    <Button Grid.Column="0" Content="1" />
    <Button Grid.Column="1" Content="2" />
    <Button Grid.Column="2" Content="3" />
</Grid>

如何在单击按钮时处理样式更改并应用样式?

编辑:填写&#34; //...&#34;代码

1 个答案:

答案 0 :(得分:1)

它无法识别也无法访问,因为Silverlight不支持它。请参阅此MSDN文章:https://msdn.microsoft.com/en-us/library/system.windows.visualstatemanager%28v=vs.95%29.aspx