我在窗口上有 2 个按钮。我正在应用这种风格。但得到了这个例外。
'设置属性'System.Windows.FrameworkElement.Style' 引发异常。' 行号“38”和行位置“7”。
我的代码。
<Window.Resources>
<Image x:Key="btnconnect" Source="images/img-1.png" />
<Image x:Key="btnshow" Source="images/img-2.png" />
<Image x:Key="btnclick" Source="images/img-2clicked.png"/>
<Style x:Key="buttonconnect" TargetType="Button">
<Setter Property="Content" Value="{StaticResource btnconnect}">
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="grid">
<Border x:Name="border" CornerRadius="8" BorderThickness="2">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
TextElement.FontWeight="Bold"></ContentPresenter>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Value="{StaticResource btnclick}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" TargetName="grid" Value="0.25"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="buttonshow" TargetType="{x:Type Button}">
<Setter Property="Content" Value="{StaticResource btnshow}" />
</Style>
</Window.Resources>
<Grid>
<Button Margin="50 100 50 100" Style="{StaticResource buttonconnect}" Height="50" Width="120"/>
<Button Margin="50 110 50 10" Style="{StaticResource buttonshow}" Height="50" Width="120"/>
</Grid>