ListBox
のDisplayMemberPath
プロパティを使用していくつかの情報を示すカスタムListBoxItemTemplate
のListBox
があります。contentpresenterのツールチップを表示する値に設定するにはどうすればよいですか?
ListBoxItemTemplate
は、ContentPresenter
です。
ContentPresenter
のツールチッププロパティをContentPresenter
と同じに設定するだけです。
私はこれを行うにしようとしました:
<ContenPresenter Tooltip={Path Content, RelativeSource={RelativeSource Self}}/>
しかし、私はDisplayMemberPath
ロジック(全体のDataContextオブジェクト)なしのコンテキストを取得します。
「DisplayMemberPath」を適用してContentPresenterで表示される値を取得するにはどうすればよいですか?
ありがとうございます。
EDIT:
ここツールチップ(コントロールがバインドして、このスタイルとDisplayMemberPath
プロパティを設定している)なしスタイル:
<Style x:Key="CheckListBoxStyle" TargetType="{x:Type ListBox}" >
<Setter Property="SelectionMode" Value="Multiple" />
<Setter Property="ItemContainerStyle" Value="{StaticResource CheckListBoxItemStyle}"/>
<Setter Property="Width" Value="177"/>
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Height" Value="70"/>
</Style>
<Style x:Key="CheckListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="Padding" Value="2,0,0,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Bd"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<CheckBox HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}" Tag="CheckBox1">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</CheckBox>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
が、私は同時にリストボックスの両方にDisplayMemberPathプロパティとItemTemplateにを使用することが可能であるとは思わない:あなたは、例えば、コンバータを使用することができます。コードを表示してください。 –
@DTsawant:done。 –