2012-03-01 10 views
0

リストボックスを小さくしたときに省略記号が表示されるように、変更しようとしているListBoxItemスタイルがあります。これを行うために私はコード内のContentPresenterを取り除き、TextBlockで置き換える必要がありました。これが適用されるListBoxは、すべてItemSourceプロパティを介してバインドされています。TextBoxをListBoxItemにバインドするItemSource

ここに私のコードです。

<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}"> 
    <Setter Property="Background" Value="White"/> 
    <Setter Property="Margin" Value="0,0,0,0"/> 
    <Setter Property="Padding" Value="0,0,0,0"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
       <Grid> 
        <Border x:Name="Bd" SnapsToDevicePixels="true"> 
         <!-- Before this used to be ContentPresenter but I switched it to TextBlock to get it the TextTrimming property. I can't find the right way to bind the data though.--> 
         <TextBlock Text="{TemplateBinding DisplayMemberPath}" TextTrimming="CharacterEllipsis" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
        </Border> 
        <Rectangle x:Name="HoverRectangle" 
           Stroke="{StaticResource Gold}" 
           StrokeDashCap="Square" 
           StrokeThickness="0" 
           SnapsToDevicePixels="True" /> 
        <Rectangle x:Name="KeyboardFocusRectangle" 
           Height="Auto" 
           SnapsToDevicePixels="True" 
           Stroke="{StaticResource BrightBlue}" 
           StrokeDashCap="Square" 
           StrokeThickness="0" /> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <!-- Bunch of Triggers in here --> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

私の現在のTextBlockテキストバインディング(Text = "{TemplateBinding DisplayMemberPath}")は機能しません。正しく動作させるためには、バインディングはどのようにすべきでしょうか?

+0

あなたはあなたのコードの中であなたの「質問」を埋めてきた - 私はお勧めあなたは編集します。 –

答えて

0

ここにあなたの唯一の合理的な選択は、ListBoxItemのデータコンテキストを仮定することであるが、文字列であるか、などのように表示することができます。

<TextBlock Text="{Binding}" .../> 
+0

それは実際に私の問題を解決しませんでしたが、正しい方向に私を指摘した情報を私に提供しました。私はそれのためのDataTemplateを作成するために探していたはずです。私はそれをし、それは問題を解決した。ありがとうございました! – Rumel

関連する問題