Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you mean something like this screenshot</p> <p><a href="http://www.bendewey.com/code/treeViewFullWidth2.png" rel="noreferrer">Full Width TreeViewItem http://www.bendewey.com/code/treeViewFullWidth2.png</a></p> <p><strong>Update</strong> As noted this example has the downfall of being indented on the subitems</p> <p><a href="http://www.bendewey.com/code/treeViewFullWidth2a.png" rel="noreferrer">Full Width TreeViewItem http://www.bendewey.com/code/treeViewFullWidth2a.png</a></p> <p>Then this should help you. Its also based on <a href="http://msdn.microsoft.com/en-us/library/ms788727.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms788727.aspx</a> you can change the TreeViewItem's Template to a StackPanel and set the ItemsPanel left Margin to 19. Then in the TreeView you set the HorizontalContentAlignment="Stretch". I'm attaching the entire resource below, but here is the important part.</p> <pre><code>&lt;ControlTemplate TargetType="{x:Type TreeViewItem}"&gt; &lt;StackPanel&gt; &lt;Border Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="19" /&gt; &lt;ColumnDefinition /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/&gt; &lt;ContentPresenter x:Name="PART_Header" Grid.Column="1" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;ItemsPresenter x:Name="ItemsHost" Margin="19,0,0,0" /&gt; &lt;/StackPanel&gt; &lt;!-- Triggers --&gt; &lt;/ControlTemplate&gt; </code></pre> <p><strong>Control</strong></p> <pre><code>&lt;TreeView Margin="50" HorizontalContentAlignment="Stretch"&gt; &lt;TreeViewItem Header="test2"/&gt; &lt;TreeViewItem Header="test2"&gt; &lt;TreeViewItem Header="sub test"/&gt; &lt;TreeViewItem Header="sub test2"/&gt; &lt;/TreeViewItem&gt; &lt;TreeViewItem Header="test3"/&gt; &lt;/TreeView&gt; </code></pre> <p><strong>Resources</strong></p> <pre><code>&lt;SolidColorBrush x:Key="GlyphBrush" Color="#444" /&gt; &lt;!--================================================================= TreeViewItem ==================================================================--&gt; &lt;Style x:Key="ExpandCollapseToggleStyle" TargetType="ToggleButton"&gt; &lt;Setter Property="Focusable" Value="False"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="ToggleButton"&gt; &lt;Grid Width="15" Height="13" Background="Transparent"&gt; &lt;Path x:Name="ExpandPath" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="1,1,1,1" Fill="{StaticResource GlyphBrush}" Data="M 4 0 L 8 4 L 4 8 Z"/&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsChecked" Value="True"&gt; &lt;Setter Property="Data" TargetName="ExpandPath" Value="M 0 4 L 8 4 L 4 8 Z"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;Style x:Key="TreeViewItemFocusVisual"&gt; &lt;Setter Property="Control.Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;Border&gt; &lt;Rectangle Margin="0,0,0,0" StrokeThickness="5" Stroke="Black" StrokeDashArray="1 2" Opacity="0"/&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}"&gt; &lt;Setter Property="Background" Value="Transparent"/&gt; &lt;Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/&gt; &lt;Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/&gt; &lt;Setter Property="Padding" Value="1,0,0,0"/&gt; &lt;Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/&gt; &lt;Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type TreeViewItem}"&gt; &lt;StackPanel&gt; &lt;Border Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="19" /&gt; &lt;ColumnDefinition /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/&gt; &lt;ContentPresenter x:Name="PART_Header" Grid.Column="1" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;ItemsPresenter x:Name="ItemsHost" Margin="19,0,0,0" /&gt; &lt;/StackPanel&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsExpanded" Value="false"&gt; &lt;Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="HasItems" Value="false"&gt; &lt;Setter TargetName="Expander" Property="Visibility" Value="Hidden"/&gt; &lt;/Trigger&gt; &lt;MultiTrigger&gt; &lt;MultiTrigger.Conditions&gt; &lt;Condition Property="HasHeader" Value="false"/&gt; &lt;Condition Property="Width" Value="Auto"/&gt; &lt;/MultiTrigger.Conditions&gt; &lt;Setter TargetName="PART_Header" Property="MinWidth" Value="75"/&gt; &lt;/MultiTrigger&gt; &lt;MultiTrigger&gt; &lt;MultiTrigger.Conditions&gt; &lt;Condition Property="HasHeader" Value="false"/&gt; &lt;Condition Property="Height" Value="Auto"/&gt; &lt;/MultiTrigger.Conditions&gt; &lt;Setter TargetName="PART_Header" Property="MinHeight" Value="19"/&gt; &lt;/MultiTrigger&gt; &lt;Trigger Property="IsSelected" Value="true"&gt; &lt;Setter TargetName="Bd" Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/&gt; &lt;Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/&gt; &lt;/Trigger&gt; &lt;MultiTrigger&gt; &lt;MultiTrigger.Conditions&gt; &lt;Condition Property="IsSelected" Value="true"/&gt; &lt;Condition Property="IsSelectionActive" Value="false"/&gt; &lt;/MultiTrigger.Conditions&gt; &lt;Setter TargetName="Bd" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/&gt; &lt;Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/&gt; &lt;/MultiTrigger&gt; &lt;Trigger Property="IsEnabled" Value="false"&gt; &lt;Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload