1 year ago
#88610
jwize
How to properly compute URI from ValueConverter in WPF
I have a simple application where I want to swap out image based on a value converter. Upon testing the images shows fine when directly bound to the code behind of a user control.
public partial class HypercombControls : Grid
{
public static readonly DependencyProperty MoveImageSourceProperty =
DependencyProperty.Register("MoveImageSource", typeof(Uri), typeof(HypercombControls),
new PropertyMetadata(new Uri("pack://application:,,/Media/control-bar/move.png")));
...
}
<Button Click="MoveButton_OnClick" Style="{StaticResource DragModeButtonStyle}">
<Image Source="{Binding ElementName=HyperControls, Path=MoveImageSource}">
</Image>
</Button>
The image shows as expected. I then added a MultiBinding with a MultiValueConverter to change the image source dynamically based on some logic. The image always comes up blank when I return the URI even if I return the exact same image URI as constructed initially. Is there something I am missing?
public object Convert(object[] values, Type targetType, object parameter,
CultureInfo culture)
{
// logic omitted but tested with the following ouput.
// same as new PropertyMetadata(...)
return new Uri("pack://application:,,/Media/control-bar/move.png");
}
wpf
uri
ivalueconverter
multibinding
imultivalueconverter
0 Answers
Your Answer