2012-02-06 3 views
2

リストボックス項目のToggleButtonコントロールテンプレートを実現しようとしています。これは、ユーザーがリストボックス項目をクリックして特定の機能を表示できるアプリケーションで使用されます。ListBox内のTogglebutton内のテキストブロック内でのテキストラブItemTemplate

リストボックス項目テンプレートは以下のように定義されます。

<Style x:Key="ExampleListBoxItemStyle" TargetType="{x:Type ListBoxItem}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate> 
        <ToggleButton IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" 
            HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch"> 
         <StackPanel Orientation="Vertical"> 
          <TextBlock x:Name="ExampleTitle" Grid.Row="0" Foreground="#333333" 
             FontFamily="pack://application:,,,/Resources/Fonts/#Neuropol Regular" 
             FontSize="16" Height="26" TextAlignment="Left" HorizontalAlignment="Left" 
             VerticalAlignment="Top" Text="{Binding ExampleDisplayName}" 
             Margin="5"></TextBlock> 
          <TextBlock Grid.Row="1" Foreground="#333333" Margin="5,-5,5,3" HorizontalAlignment="Stretch" 
             TextAlignment="Left" FontFamily="Verdana" VerticalAlignment="Top" 
             TextWrapping="Wrap" Text="{Binding ExampleDescription}"/> 
         </StackPanel> 
        </ToggleButton> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

とリストボックスがここ

 <ListBox x:Name="_examplesListBox" 
       SelectionMode="Single" 
       BorderBrush="Transparent" 
       Background="Transparent" 
       ItemsSource="{Binding AllExamples}" 
       ItemContainerStyle="{StaticResource ExampleListBoxItemStyle}" 
       SelectedItem="{Binding SelectedExample, Mode=TwoWay}"/> 

として定義されている私は2つのテキストブロック、ExampleDisplayNameに結合した1つ、ExampleDescriptionにバインドされた他のを持っています。私が達成しようとしている効果は、2番目のテキストブロック(記述)をラップアラウンドすることです。利用可能なスペースによって制約されます。

これは私が今取得していますものです:

SciChart Beta Examples Listbox Styling

私が好きな何リストボックスのサイズに基づいてラップする記述例を示す第2のラインのためです。アプリケーションが起動すると、リストボックスは最初の行+マージンに自動的にサイズ変更されます。

提案がありますか?

答えて

3

水平スクロールバーは、テキストの折り返しを支援する必要があることを削除する:私はどのように唯一のXAMLを使用して最初のテキスト行のサイズに基づいて、起動時に自動サイズListBoxに非常によく分からない

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"> 

+0

ブーム! 1行の修正。テキストの折り返しを含むTextBlocksは基本的に親に合わせて伸縮します。最初の行は特定のサイズを要求しているので、リストボックスの水平スクロールバーをオフにするだけで、サイズやラップが正しく行われました。ありがとう! –