WPF按钮数据触发器

编程入门 行业动态 更新时间:2024-10-27 14:18:25
本文介绍了WPF按钮数据触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在wpf表单中有一个按钮,当我单击按钮时它将在mvvm应用程序中显示图像文本,它将附加文件,我的要求是在成功附加时我要从按钮中删除图像,想要用一些文本更新按钮.

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 i want to remove the image from the button and want to update the button with some text.

<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right"> <Button ToolTip="Attach Approval" Height="25" Command="{Binding AddAttachmentCommand}" Margin="5,10,5,10"> <StackPanel Orientation="Horizontal"> <Image Source="/UILibrary;component/Themes/Default/Images/Attach.PNG"/> </StackPanel> <Button.Style> <Style TargetType="{x:Type Button}"> <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> </Button> <StackPanel Orientation="Horizontal" Height="25" Margin="5,10,5,10" Visibility="{Binding IsAttachmentAvailable, Converter={StaticResource BooleanToVisibilityConverter}}"> <TextBlock Margin="3"> <Hyperlink Command="{Binding OpenAttachmentCommand}"> <TextBlock Text="{Binding Attachment.FileName}"/> </Hyperlink> </TextBlock> <customControls:CloseButton Width="15" Height="15" Command="{Binding RemoveAttachmentCommand}"> <customControls:CloseButton> Remove attachment </customControls:CloseButton> </customControls:CloseButton> </StackPanel> <Button Height="25" Width="80" Margin="5,10,5,10" Content="Approve" Command="{Binding ApproveTemplateCommand}"/> <Button Height="25" Width="80" Margin="5,10,5,10" Content="Preview" Command="{Binding PreviewTemplateCommand}"/> <Button Content="Save" Command="{Binding SaveTemplateCommand}" Height="25" Width="80" Margin="5,10,5,10"/> <Button Height="25" Width="80" Margin="5,10,10,10" Content="Cancel" Command="{Binding CancelCommand}"/> </StackPanel>

推荐答案

如果像您一样在<Button>标记本身中设置了Button.Content,它将优先于任何样式化的值.

If Button.Content is set in the <Button> tag itself like you have, it will take precedence over any styled values.

您需要将StackPanel直接移出<Button.Content>标记,然后将其置于样式或其他数据触发器中.

You need to move your StackPanel out of the <Button.Content> tag directly, and put it in the style or another data trigger instead.

<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>

请参见 MSDN的依赖属性优先级列表更多信息.

更多推荐

WPF按钮数据触发器

本文发布于:2023-11-06 04:51:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562754.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   按钮   数据   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!