WPF图像按钮
我在WPF中使用了两个按钮我想更改他们的图像,即禁用上的图像按钮。有人能帮我吗?在WPF中,图像按钮只是一个WPF图像按钮,wpf,vb.net,Wpf,Vb.net,我在WPF中使用了两个按钮我想更改他们的图像,即禁用上的图像按钮。有人能帮我吗?在WPF中,图像按钮只是一个按钮,其内容设置为图像。因此,如果您想更改图像,只需将另一个图像分配给按钮的内容属性,您无法更改图像,因为在WPF中,按钮只是@Daniel Hilgarth所写的按钮。但是,您可以为按钮式按钮创建新样式,并将其应用于您的按钮。这可能与您的需求类似 <Style x:Key="BtnStyle" TargetType="{x:Type Button}">
按钮,其内容设置为图像。因此,如果您想更改图像,只需将另一个图像分配给按钮的内容属性,您无法更改图像,因为在WPF中,按钮只是@Daniel Hilgarth所写的按钮。但是,您可以为按钮式按钮创建新样式,并将其应用于您的按钮。这可能与您的需求类似
<Style x:Key="BtnStyle" TargetType="{x:Type Button}">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<!--Image-->
<Image x:Name="BtnImage" Stretch="Fill" />
<ContentPresenter Margin="2" HorizontalAlignment="Center" RecognizesAccessKey="True" VerticalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<!--Trigger for IsEnabled-->
<Trigger Property="IsEnabled" Value="false">
<!--Set the source of the image-->
<Setter TargetName="BtnImage" Property="Source" Value="pack://application:,,,/YouAppShortName;component/Image.png" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>