I have a converter that takes in a bool and will return A or B depending on if it was true or false. The converter picks the right value depending on what the bool is, but only at start, if i change the bool at runtime the converter does not update.
Basically, i have a User Control that has a button in it, this button toggles the "IsOpen" property, this works. But i have a multibinder who binds IsOpen to Image (of button) which will toggle the image depending on IsOpen. But it is not updating, only keeps the value at start. (IsOpen does toggle on click, that's not the problem)
My User Control where i do the multibinding:
<v:IconButton ColorPalette="{StaticResource MilkySolid}" ColorPaletteFore="{StaticResource BlackToBrightPalette}" IconMargin="0" Content="" VerticalAlignment="Top" Margin="0" HorizontalAlignment="Left" FontSize="1" Height="26" IconWidth="26" Click="IconButton_Click">
<v:IconButton.Image>
<MultiBinding Converter="{StaticResource AorBConverter}">
<Binding Path="IsOpen"/>
<Binding Source="{StaticResource collapseBTN}"/>
<Binding Source="{StaticResource expandBTN}"/>
</MultiBinding>
</v:IconButton.Image>
</v:IconButton>
CodeBehind (this part works)
private void IconButton_Click(object sender, RoutedEventArgs e)
{
IsOpen = !IsOpen;
}
public bool IsOpen
{
get { return (bool)GetValue(IsOpenProperty); }
set { SetValue(IsOpenProperty, value); }
}
public static readonly DependencyProperty IsOpenProperty =
DependencyProperty.Register("IsOpen", typeof(bool),
typeof(ParamNodeV), new PropertyMetadata(false));
Viewmodel for the user control (this also works)
public bool IsOpen
{
get { return isOpen; }
set
{
isOpen = value;
OnPropertyChanged(nameof(IsOpen));
}
}
So, like i said, the converter chooses the right image depedning on the bool value. But it does not update if i update the bool value at runtime.
And if you will ask me why im not just using a trigger: I'm trying to change the image on a CustomControl (IconButton) from my UserControl (ParamNodeV), and i don't know how to access the properties of IconButton from ParamNodeV, without completely overriding the style/template. So either if someone helps me with my converter or helps me on how to navigate to the Image property of IconButton from UserControl without having to override the style/template
The expression
takes the current DataContext as source object.
In the code behind you are apparently changing the IsOpen property of the UserControl - which should be a different object.
The Binding should therefore use that property as source, i.e. use the UserControl as source object: