开发者

XAML Tool Tip Data Context and Multi Binding

I have a ListView in my XAML and I am trying to hook up a MultiBinding Converter.

<ListView
Grid.Column="4"
Grid.Row="1"
Grid.RowSpan="5"
Margin="8,0,8,8"
HorizontalAlignment="Stretch" 
            Name="lvDisplayType" 
ItemsSource="{Binding Path=Types}" 
SelectedItem="{Binding Path=Current.Opt}"
VerticalAlignment="Stretch" 
SelectionChanged="lvType_SelectionChanged" 
SelectionMode="Single"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <DockPanel 
   HorizontalAlignment="Center">
                        <TextBlock 
    Text="{Binding Path=., Converter={StaticResource DisplayConverter}}" 
    HorizontalAlignment="Center" 
    Padding="6" 
    VerticalAlignment="Center" 
                            TextWrapping="Wrap">
                            <TextBlock.ToolTip>
                                <ToolTip DataContext="{Binding Path=Current}">
                                    <MultiBinding Converter="{StaticResource OptConverter}">
                                        <Binding Path="Opt" />
                                        <Binding Path="Type" />
                                    </MultiBinding>
                                </ToolTip>
                            </TextBlock.ToolTip>
                        </TextBlock>    
                    </DockPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

The code not working is:

                                <TextBlock.ToolTip>
                                <ToolTip DataContext="{Binding Path=Current}">
                                    <MultiBinding Converter="{StaticResource OptConverter}">
                                        <Binding Path="Opt" />
                                        <Binding Path="Type" />
                                    </MultiBinding>
                                </ToolTip>
                            </TextBlock.ToolTip>

At present the Converter is returning an empty string as both 'values[0] == System.Windows.DependencyProperty.UnsetValue' and 'values[1] == System.Windows.DependencyProperty.UnsetValue' return true. These values are never set.

Because of the logical tree (I think) the TextBlock.ToolTip default binding is 'Current.Opt'. For the MultiBinding I also need to refer to 'Type' which is another property of 'Current'. So to get around this I hav开发者_C百科e set 'ToolTip DataContext="{Binding Path=Current}"' - this isn't working as expected - what am I doing wrong?

I know I could do this easily in the Code behind, but we are employing MVVM, so would like to avoid it if possible.

Any help greatly appreciated!

Thank you


Try to do it in this way,

1.Does this give DependencyProperty.UnsetValue in the Converter? Otherwise, what is coming in to the converter?

<TextBlock.ToolTip>
    <MultiBinding Converter="{StaticResource OptConverter}"> 
        <Binding RelativeSource="{RelativeSource Self}" /> 
        <Binding RelativeSource="{RelativeSource Self}" /> 
    </MultiBinding>
</TextBlock.ToolTip>

2.Does this give DependencyProperty.UnsetValue in the Converter?

<TextBlock.ToolTip>
    <MultiBinding Converter="{StaticResource OptConverter}"> 
        <Binding RelativeSource="{RelativeSource Self}" Path="Current"/> 
        <Binding RelativeSource="{RelativeSource Self}" Path="Current"/> 
    </MultiBinding>
</TextBlock.ToolTip>  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜