I have a problem with layout.
At initial window everything is as expected.

When one of the parent or child items is clicked, everything is aligned to the right. I don’t want that such situation. Here is screenshots:


Could anybody help me?
XAML layout template:
‘textBlock’ style
<Style x:Key="textBlock" TargetType="{x:Type TextBlock}">
<Setter Property="FontFamily" Value="Verdana"></Setter>
<Setter Property="FontSize" Value="12"></Setter>
</Style>
Items layout:
<HierarchicalDataTemplate
DataType="{x:Type models:EntityViewModel}" ItemsSource="{Binding Children}" >
<Grid Margin="0,0,3,0">
<TextBlock Style="{StaticResource textBlock}" TextWrapping="Wrap" Width="{Binding ActualWidth, ElementName=EntityTree}">
<Hyperlink NavigateUri="{Binding Url}" RequestNavigate="Hyperlink_RequestNavigate">
<TextBlock Text="{Binding ID}"></TextBlock>
</Hyperlink>
<TextBlock Text="{Binding TypeName}"></TextBlock>
<TextBlock Text="{Binding Explanation}"></TextBlock>
</TextBlock>
</Grid>
</HierarchicalDataTemplate>
Parent layout:
<HierarchicalDataTemplate
DataType="{x:Type models:ParentViewModel}" ItemsSource="{Binding Children}">
<Grid Margin="0,0,3,0">
<TextBlock Style="{StaticResource textBlock}" TextWrapping="Wrap" Width="{Binding ActualWidth, ElementName=EntityTree}" >
<TextBlock Text="{Binding ParentName}"/>
<Run Text=" kategorisinde toplam "></Run>
<TextBlock Text="{Binding ItemsCount}"></TextBlock>
<Run Text=" adet kayıt"></Run>
</TextBlock>
</Grid>
</HierarchicalDataTemplate>
Probably this is due too the Binding for the Width of the TextBlock in your EntityViewModel DataTemplate. I assume, that EntityTree is the name of the entire TreeView. You force the TextBlock’s width to be larger than your entire TreeView, since it is indented on the second level, this causes the TreeView to try to make the whole Textblock Visible and enforce the scrolling to the right. Try to set a fixed width in a first approach, which is less or equal to the width available