tags:

views:

62

answers:

1

Hi there

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 have 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

A: 

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>  
Meleak
Thanks for your reply.Still not working.It must be to do with the DataContext. Heres an Example :My ListView items source is 'ItemsSource="{Binding Path=Types}"' then further on I have a TextBlock Text as :Text="{Binding Path=.}" // This WorksText="{Binding Path=DisplayTypes}" // This doesn't :-/ Any pointers?Thanks very much
Joe.Net
Sorry, it should read : Thanks for your reply. Still not working. It must be to do with the DataContext. Heres an Example : My ListView items source is 'ItemsSource="{Binding Path=Types}"' then further on I have a TextBlock Text as : Text="{Binding Path=.}" // This Works Text="{Binding Path=Types}" // This doesn't :-/ Any pointers? Thanks very much –
Joe.Net
It's a little hard to tell based on the info, I don't really know what else is going on. But when I try to do this ItemsSource="{Binding=.}" I get '{Binding=.}' "value is not a valid MarkupExtension expression. Cannot resolve 'Binding=.'... You should just use Text="{Binding}" there, meaning you're binding directly to your DataContext and not a Property on it
Meleak
Sure - Thanks very much Meleak
Joe.Net