WPF按钮命令捆绑后触发属性格式变化 [英] wpf button command binding after trigger the propery changes

查看:106
本文介绍了WPF按钮命令捆绑后触发属性格式变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的WPF的形​​式有一个按钮,该按钮具有MVVM应用图像的文字时,我按一下按钮,将附加的文件,我的要求是当连接成功文本改为核准,我想。写改为批准的文本之后这个命令另一个命令属性格式

 <按钮工具提示=附加批准
高度=25
命令={结合AddAttachmentCommand}
保证金=5,10,5,10>
< Button.Style>
<风格的TargetType ={X:类型按钮}>
<! - 默认内容的价值 - >
< setter属性=内容>
< Setter.Value>
< StackPanel的方向=横向>
<图像源=/ UILibrary;组件/主题/默认/图片/ Attach.PNG/>
< / StackPanel的>
< /Setter.Value>
< /二传手>

<! - 触发值 - >
< Style.Triggers>
< D​​ataTrigger绑定={结合IsAttachmentAvailable}VALUE =真>
< setter属性=能见度VALUE =可见/>
< setter属性=内容VALUE =Appprove/>
< / DataTrigger>
< D​​ataTrigger绑定={结合IsAttachmentAvailable}VALUE =FALSE>
< setter属性=能见度VALUE =可见/>
< / DataTrigger>
< /Style.Triggers>
< /样式和GT;
< /Button.Style>


解决方案

如果你想改变一个属性(你的情况命令)的触发器,你必须初始化在样式的setter属性。为了使你的代码工作从按钮删除命令属性并添加命令属性的风格二传手

 <按钮工具提示=附加批准
高度=25

保证金=5,10,5,10>
< Button.Style>
<风格的TargetType ={X:类型按钮}>
<! - 默认内容的价值 - >
< setter属性=命令VALUE ={结合AddAttachmentCommand}/>
< setter属性=内容>
< Setter.Value>
< StackPanel的方向=横向>
<图像源=/ UILibrary;组件/主题/默认/图片/ Attach.PNG/>
< / StackPanel的>
< /Setter.Value>
< /二传手>

<! - 触发值 - >
< Style.Triggers>
< D​​ataTrigger绑定={结合IsAttachmentAvailable}VALUE =真>
< setter属性=能见度VALUE =可见/>
< setter属性=内容VALUE =Appprove/>
< setter属性=命令VALUE =一些命令/>
< / DataTrigger>
< D​​ataTrigger绑定={结合IsAttachmentAvailable}VALUE =FALSE>
< setter属性=能见度VALUE =可见/>
< / DataTrigger>
< /Style.Triggers>
< /样式和GT;
< /Button.Style>


i have a button in my wpf form and the button is having the image text in mvvm application when i click the button it will attach the file, my requirement is when it attached successfully the text is changed to Approve , I want to write another command propery for this command after changed the text to Approve.

<Button ToolTip="Attach Approval" 
        Height="25" 
        Command="{Binding AddAttachmentCommand}" 
        Margin="5,10,5,10">
    <Button.Style>
        <Style TargetType="{x:Type Button}">
            <!-- Default Content value -->
            <Setter Property="Content">
                <Setter.Value>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/UILibrary;component/Themes/Default/Images/Attach.PNG"/>
                    </StackPanel>
                </Setter.Value>
            </Setter>

            <!-- Triggered values -->
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsAttachmentAvailable}" Value="True">
                    <Setter Property="Visibility" Value="Visible"/>
                    <Setter Property="Content" Value="Appprove"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsAttachmentAvailable}" Value="False">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>

解决方案

If you want to change a property (in your case the Command) in a trigger, you have to initialise the property in the style setter. To make your code work remove the command property from the button and add the command property to the style setter.

<Button ToolTip="Attach Approval" 
        Height="25" 

        Margin="5,10,5,10">
    <Button.Style>
        <Style TargetType="{x:Type Button}">
            <!-- Default Content value -->
            <Setter Property="Command" Value="{Binding AddAttachmentCommand}"/>
            <Setter Property="Content">
                <Setter.Value>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/UILibrary;component/Themes/Default/Images/Attach.PNG"/>
                    </StackPanel>
                </Setter.Value>
            </Setter>

            <!-- Triggered values -->
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsAttachmentAvailable}" Value="True">
                    <Setter Property="Visibility" Value="Visible"/>
                    <Setter Property="Content" Value="Appprove"/>
                    <Setter Property="Command" Value="SOME OTHER COMMAND"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsAttachmentAvailable}" Value="False">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>

这篇关于WPF按钮命令捆绑后触发属性格式变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆