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>
If Button.Content
is set in the <Button>
tag itself like you have, it will take precedence over any styled values.
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>
See MSDN's Dependency Property Precedence List for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With