Another Fix...

Jun 4, 2013 at 1:27 PM
Would it be possible to Replace the StackPanel in TreeViewItems Default Style with a DockPanel, so that it is possible that a DataTemplate can use the full width of the TreeView. Without this, the Binding from the HorizontalAlignment of the ContentPresenter is useless because the Stackpanel always minimizes the items size.

And you can Replace the Dockpanel wich is a subelemnt of the dockpanel with FrameworkElement, this uses less resources:

Then it looks like this:

<DockPanel x:Name="ct" >
                        <FrameworkElement DockPanel.Dock="Left" Width="{TemplateBinding Offset}"/>
                        <ToggleButton DockPanel.Dock="Left"
                                IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:TreeViewExItem}},Path=IsExpanded,FallbackValue=False}"
                                Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:TreeViewExItem}},Path=IsExpandable, Converter={StaticResource boolToVisiblityConverterHidden},FallbackValue=Hidden}"
                                ClickMode="Press" Name="Expander" HorizontalAlignment="Right">
                            <ToggleButton.Style>
                                <Style TargetType="{x:Type ToggleButton}">
                                    <Style.Resources>
                                        <ResourceDictionary />
                                    </Style.Resources>
                                    <Setter Property="UIElement.Focusable" Value="False" />
                                    <Setter Property="FrameworkElement.Width" Value="16" />
                                    <Setter Property="FrameworkElement.Height" Value="16" />
                                    <Setter Property="Control.Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                <Border Padding="5" Background="#00FFFFFF" Width="16" Height="16">
                                                    <Path Fill="#00FFFFFF" Stroke="#FF989898" Name="ExpandPath">
                                                        <Path.Data>
                                                            <PathGeometry Figures="M0,0L0,6L6,0z" />
                                                        </Path.Data>
                                                        <Path.RenderTransform>
                                                            <RotateTransform Angle="135" CenterX="3" CenterY="3" />
                                                        </Path.RenderTransform>
                                                    </Path>
                                                </Border>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="UIElement.IsMouseOver" Value="True">
                                                        <Setter Property="Shape.Stroke" TargetName="ExpandPath">
                                                            <Setter.Value>
                                                                <SolidColorBrush>
                                                                    #FF1BBBFA</SolidColorBrush>
                                                            </Setter.Value>
                                                        </Setter>
                                                        <Setter Property="Shape.Fill" TargetName="ExpandPath">
                                                            <Setter.Value>
                                                                <SolidColorBrush>#00FFFFFF</SolidColorBrush>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </Trigger>
                                                    <Trigger Property="ToggleButton.IsChecked" Value="True">
                                                        <Setter Property="UIElement.RenderTransform"
                                                                TargetName="ExpandPath">
                                                            <Setter.Value>
                                                                <RotateTransform Angle="180" CenterX="3" CenterY="3" />
                                                            </Setter.Value>
                                                        </Setter>
                                                        <Setter Property="Shape.Fill" TargetName="ExpandPath">
                                                            <Setter.Value>
                                                                <SolidColorBrush>#FF595959</SolidColorBrush>
                                                            </Setter.Value>
                                                        </Setter>
                                                        <Setter Property="Shape.Stroke" TargetName="ExpandPath">
                                                            <Setter.Value>
                                                                <SolidColorBrush>#FF262626</SolidColorBrush>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ToggleButton.Style>
                        </ToggleButton>
                        <ContentPresenter x:Name="content"
                            FocusManager.IsFocusScope="True" 
                            Content="{TemplateBinding Control.DataContext}"
                            ContentTemplate="{Binding DataTemplate, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                            ContentSource="Header" 
                            HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                            SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                    </DockPanel>
Jun 4, 2013 at 1:28 PM
If you do this, your Examples still look the same, so it should not break anything!
Coordinator
Jun 5, 2013 at 3:53 PM
Indeed, it seems to work quite well. I've checked it in with 72268.