使用触发器更改内容按钮
change content button with trigger
我想在按下按钮时将按钮的内容更改为另一个图像,但没有任何反应。
<Grid>
<Button Height="120" Width="75">
<Button.Template>
<ControlTemplate TargetType="Button">
<Image Source="no-press.png"/>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Content">
<Setter.Value>
<DataTemplate>
<Image Source="press.png"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
谢谢你:)
给你:
<Grid>
<Button Height="120" Width="75">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Transparent" BorderThickness="1" BorderBrush="Black">
<ContentPresenter Name="content"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter TargetName="content" Property="ContentPresenter.Content">
<Setter.Value>
<Image Source="pressed.png"/>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
<Image Source="no-pressed.png"/>
</Button>
</Grid>
我想在按下按钮时将按钮的内容更改为另一个图像,但没有任何反应。
<Grid>
<Button Height="120" Width="75">
<Button.Template>
<ControlTemplate TargetType="Button">
<Image Source="no-press.png"/>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Content">
<Setter.Value>
<DataTemplate>
<Image Source="press.png"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
谢谢你:)
给你:
<Grid>
<Button Height="120" Width="75">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Transparent" BorderThickness="1" BorderBrush="Black">
<ContentPresenter Name="content"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter TargetName="content" Property="ContentPresenter.Content">
<Setter.Value>
<Image Source="pressed.png"/>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
<Image Source="no-pressed.png"/>
</Button>
</Grid>