0

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");
    }
Clemens
  • 123,504
  • 12
  • 155
  • 268
jwize
  • 4,230
  • 1
  • 33
  • 51
  • Try to return the proper target type from the Converter, i.e. `return new BitmapImage(new Uri("pack://application:,,,/Media/control-bar/move.png"));`. There was also a comma missing in the Pack URI. It must be `:,,,/` instead of `:,,/`. – Clemens Jan 24 '22 at 09:17
  • I will try. How come it works in the new property metadata? – jwize Jan 24 '22 at 10:30

0 Answers0