相关疑难解决方法(0)

'灰显'WPF按钮图像?

我有一个简单的Button控件,其中包含一个Image对象作为其内容.我想ImageButton禁用时将不透明度设置为0.5 ,以便为Button状态提供额外的视觉提示.

在XAML中实现该结果的最简单方法是什么?谢谢你的帮助.

wpf wpf-controls

58
推荐指数
3
解决办法
4万
查看次数

元素被禁用时按钮上的灰色图像(简单而美观)

当按钮被禁用时,我希望灰显我的图像(在按钮上).当我在按钮上有文本(没有图像)时,文本显示为灰色(将图像作为按钮内容,它们不会变灰).有没有简单而美丽的方法呢?

这是我的xaml文件:

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <ToolBarTray VerticalAlignment="Top" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" IsLocked="true" Grid.Row="0">
            <ToolBar Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Band="1" BandIndex="1">
                <Button Command="{Binding Button1}" RenderOptions.BitmapScalingMode="NearestNeighbor">
                    <Button.Content>
                        <Image Source="open.ico"></Image>
                    </Button.Content>
                </Button>
                <Button Command="{Binding Button2}" RenderOptions.BitmapScalingMode="NearestNeighbor">
                    <Button.Content>
                        <Image Source="open.ico"></Image>
                    </Button.Content>
                </Button>
            </ToolBar>
        </ToolBarTray>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

这是我的代码隐藏文件:

public partial class MainWindow : Window
{
    private RelayCommand _button1;
    private RelayCommand _button2;

    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
    }

    public ICommand Button1
    {
        get
        { …
Run Code Online (Sandbox Code Playgroud)

wpf xaml command image button

21
推荐指数
3
解决办法
2万
查看次数

标签 统计

wpf ×2

button ×1

command ×1

image ×1

wpf-controls ×1

xaml ×1