Reputation: 17
I have a problem when trying binding from combobox to tooltip. I want to bind SelectedValue to tooltip and add a string before SelectedValue on tooltip. EX: SelectedValue: ID_001. Tooltip = Your ID: ID_001. My xaml:
<ComboBox ToolTip="{Binding ElementName=cbb_ma_kh, Path=SelectedValue}"
Height="32"
Margin="115,39,24,0"
Name="cbb_ma_kh"
VerticalAlignment="Top"
Grid.ColumnSpan="2" />
Thanks so much
Upvotes: 1
Views: 1375
Reputation: 11221
As suggested in the comments, the simplest solution would be a Converter to prepend the text.
<ComboBox
ItemsSource="{Binding Ids}"
ToolTip="{Binding SelectedValue,
RelativeSource={RelativeSource Self},
Converter={StaticResource StringConverter}}"
...
>
Building the string in XAML is a bit trickier. ElementName and RelativeSource no longer work once you get inside the <ComboBox.ToolTip> ... </ComboBox.ToolTip>
. So you would have to bind the SelectedValue to your DataContext to access it later on.
<ComboBox
ItemsSource="{Binding Ids}"
SelectedValue="{Binding SelectedIdValue}"
...
>
<ComboBox.ToolTip>
<ToolTip
Content="{Binding SelectedIdValue}"
ContentStringFormat="Your ID: {0}"
/>
</ComboBox.ToolTip>
</ComboBox>
Upvotes: 1