Note that there are some explanatory texts on larger screens.

plurals
  1. PORefreshing a binding that uses a value converter
    primarykey
    data
    text
    <p>I have a WPF UI that is bound to an object. I'm using a ValueConverter to convert a property to a specific image by a business rule:</p> <pre> <code> public class ProposalStateImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var proposal = value as Proposal; var basePath = "pack://application:,,,/ePub.Content;component/Images/General/Flag_{0}.png"; string imagePath; if(proposal.Invoice != null) { imagePath = string.Format(basePath, "Good"); } else { imagePath = string.Format(basePath, "Warning"); } var uri = new Uri(imagePath); var src = uri.GetImageSource(); //Extention method return src; } } </code> </pre> <p>The element is a TreeView where the image is on the 2nd level:</p> <pre> <code> &lt;TreeView x:Name="tree" ItemsSource="{Binding People}" SelectedItemChanged="OnTreeItemChanged"&gt; &lt;TreeView.Resources&gt; &lt;HierarchicalDataTemplate DataType="{x:Type dmn:Person}" ItemsSource="{Binding Proposals}"&gt; &lt;StackPanel Orientation="Horizontal" ToolTip="{Binding Path=Fullname}" Margin="3"&gt; &lt;Image Margin="5,0,5,0" Width="16" Height="16" Source="pack://application:,,,/ePub.Content;component/Images/General/Person_Active.png" /&gt; &lt;TextBlock Text="{Binding Path=Firstname}" /&gt; &lt;TextBlock Text="{Binding Path=Lastname}" Margin="5,0,0,0" /&gt; &lt;/StackPanel&gt; &lt;/HierarchicalDataTemplate&gt; &lt;HierarchicalDataTemplate DataType="{x:Type dmn:Proposal}"&gt; &lt;StackPanel Orientation="Horizontal" Margin="3"&gt; <b>&lt;Image x:Name="invoiceImage" Width="16" Height="16" Margin="5,0,5,0" Source="{Binding, Converter={StaticResource ProposalStateImageConverter}, UpdateSourceTrigger=PropertyChanged}" /&gt;</b> &lt;TextBlock Text="{Binding DeliveryDate, Converter={StaticResource textCulturedDateConverter}}" /&gt; &lt;/StackPanel&gt; &lt;/HierarchicalDataTemplate&gt; &lt;/TreeView.Resources&gt; &lt;/TreeView&gt; </code> </pre> <p>It is working fine, but later, when the object's state changes, I want to refresh the image and make the value converter reevaluate. How is this possible?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload