Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF图像按钮_Wpf_Vb.net - Fatal编程技术网

WPF图像按钮

WPF图像按钮,wpf,vb.net,Wpf,Vb.net,我在WPF中使用了两个按钮我想更改他们的图像,即禁用上的图像按钮。有人能帮我吗?在WPF中,图像按钮只是一个按钮,其内容设置为图像。因此,如果您想更改图像,只需将另一个图像分配给按钮的内容属性,您无法更改图像,因为在WPF中,按钮只是@Daniel Hilgarth所写的按钮。但是,您可以为按钮式按钮创建新样式,并将其应用于您的按钮。这可能与您的需求类似 <Style x:Key="BtnStyle" TargetType="{x:Type Button}">

我在WPF中使用了两个按钮我想更改他们的图像,即禁用上的图像按钮。有人能帮我吗?

在WPF中,图像按钮只是一个
按钮,其
内容设置为图像。因此,如果您想更改图像,只需将另一个图像分配给
按钮的
内容
属性
,您无法更改图像,因为在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>