嗨,我有那种按钮:
XAML:
...
<Window.Resources>
<Style x:Key="NoChromeButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="Chrome" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
<Setter Property="Opacity" TargetName="Chrome" Value="0.5"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
...
<Button Name="aaa" Style="{DynamicResource NoChromeButton}" Margin="5" Height="30" Width="40" Click="Button_Click">
<StackPanel>
<Image Name="bbb" Source="C:\Users\Daniel\Desktop\WPF\Paint\skew.png"/>
</StackPanel>
</Button>
C#:
private void Button_Click(object sender, RoutedEventArgs e)
{
BitmapImage bmi = new BitmapImage(new Uri("C:\\Users\\Daniel\\Desktop\\WPF\\Paint\\skew2.png", UriKind.Relative));
bbb.Source = bmi ;
}
当我单击按钮图像消失时,我尝试了其他几种方法来做到这一点,但我做不到。我搜索了这个论坛,但我没有找到任何可以真正帮助我的东西。