1 Replies - 295 Views - Last Post: 17 August 2019 - 02:12 AM Rate Topic: -----

#1 HitCZ   User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 8
  • Joined: 14-October 15

MultiBinding - UnsetValue

Posted 16 August 2019 - 11:10 AM

Hello Everyone,
I've been trying to implement a dynamic ToolTip (WPF) for RadioButton (the ToolTip switches, when IsEnabled of the RadioButton changes). I wanted to achieve this with a MultiValueConverter, which would be sort of a general Converter, that accepts 3 values - the IsEnabled value, enabled ToolTip and disabled ToolTip in this exact order.

But sadly I have encountered an issue, that I haven't been able to solve yet. Basically when the code reaches the Convert Method, the Array of values is filled with DependencyProperty.UnsetValue items, as shown in the screenshot I enclosed in the attachments.

And this is the XAML code of the View:

<Window x:Class="DynamicToolTipSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DynamicToolTipSample"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <window.Resources>
        <local:BooleanToStringConverter x:Key="BooleanToStringConverter"/>
    </window.Resources>
    <Grid>
        <RadioButton x:Name="RadioButton" ToolTipService.ShowOnDisabled="True"
            IsEnabled="{Binding IsRadioButtonEnabled}" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Radio">
            <RadioButton.ToolTip>
                <ToolTip>
                    <TextBlock>
                        <TextBlock.Text>
                            <MultiBinding Converter="{StaticResource BooleanToStringConverter}">
                                <Binding ElementName="RadioButton"  Path="IsEnabled"/>
                                <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:MainWindow}}"  Path="ViewModel.Enabled"/>
                                <Binding RelativeSource="{RelativeSource AncestorType={x:Type local:MainWindow}}"  Path="ViewModel.Disabled"/>
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </ToolTip>
            </RadioButton.ToolTip>
        </RadioButton>

        <Button x:Name="btn" Content="Change Enabled" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
    </Grid>
</Window>




What I managed to find while googling was, that the problem is propably caused by having a wrong DataContext as mentioned here , but I feel like I have tried every combination that I could come up with and nothing helped. I would very much appreciate if someone could point me in the right direction. I'm enclosing the sample code here, in case someone would like to take a closer look.

Thanks in advance.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: MultiBinding - UnsetValue

#2 HitCZ   User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 8
  • Joined: 14-October 15

Re: MultiBinding - UnsetValue

Posted 17 August 2019 - 02:12 AM

I managed to fix this by explicitly setting DataContext on the RadioButton and removing the RelativeSources within the MultiBinding. Though I don't understand why it did not work with the RelativeSources, it works. Here is the code, in case of anyone reading this in the future:

<RadioButton x:Name="RadioButton" ToolTipService.ShowOnDisabled="True" 
                     DataContext="{Binding ViewModel, RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}}"
            IsEnabled="{Binding IsRadioButtonEnabled}" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Radio">
            <RadioButton.ToolTip>
                <ToolTip>
                    <TextBlock>
                        <TextBlock.Text>
                            <MultiBinding Converter="{StaticResource BooleanToStringConverter}">
                                <Binding Path="IsRadioButtonEnabled"/>
                                <Binding Path="EnabledToolTip"/>
                                <Binding Path="DisabledToolTip"/>
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </ToolTip>
            </RadioButton.ToolTip>
        </RadioButton>


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1