【发布时间】:2019-06-08 17:20:15
【问题描述】:
我正在尝试为我的组合框中的每个用户名(CreatedBy)添加一个工具提示,以防用户名对于组合框的宽度来说太长。
我知道这个问题已经被问过一百万次了,我尝试过使用 Style.Triggers 方法,我也尝试过 ToolTip="{Binding Path=SelectedCreatedBy.ToolTip, RelativeSource={RelativeSource Self}}
<ComboBox ItemsSource="{Binding CreatedBys.DefaultView}" SelectedValue="{Binding SelectedCreatedBy,UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="CreatedBy" DisplayMemberPath="CreatedBy" ToolTip="{Binding SelectedCreatedBy}"
Grid.Row="3" Grid.Column="12" Height="22" Width="85" FontSize="11" IsEditable="{Binding IsCreatedByEditable}" VerticalAlignment="Top" HorizontalAlignment="Left" >
编辑:我找到了解决方案,我将在此处发布代码
<ComboBox ItemsSource="{Binding CreatedBys.DefaultView}" SelectedValue="{Binding SelectedCreatedBy,UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="CreatedBy" DisplayMemberPath="CreatedBy" ToolTip="{Binding SelectedCreatedBy}"
Grid.Row="3" Grid.Column="12" Height="22" Width="85" FontSize="11" IsEditable="{Binding IsCreatedByEditable}" VerticalAlignment="Top" HorizontalAlignment="Left" >
<ComboBox.ItemContainerStyle>
<Style>
<Setter Property="Control.ToolTip" Value="{Binding CreatedBy}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
【问题讨论】: