That is my custom control code:
<TreeView Name="TreeView1"
Width="180"
HorizontalAlignment="Left"
HorizontalContentAlignment="Left"
BorderThickness="0"
ItemsSource="{Binding SectionList}">
<TreeView.ItemTemplate>
<DataTemplate>
<Expander Margin="-20,0,0,0"
Padding="0,0,0,0"
Header="{Binding Name}"
IsExpanded="True">
<ListBox Margin="22,0,0,0"
Padding="0,0,0,0"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Left"
BorderBrush="Transparent"
BorderThickness="0,0,0,0"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Sections}"
ScrollViewer.CanContentScroll="False"
SelectedValue="{Binding Path=DataContext.Label, RelativeSource={RelativeSource AncestorType={x:Type TreeView}}}"
SelectedValuePath="Text">
<ListBox.Template>
<ControlTemplate>
<ItemsPresenter />
</ControlTemplate>
</ListBox.Template>
</ListBox>
</Expander>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
When the name is too large, scrollbar makes visible and it's okay. But when you scroll horizontally the Expander
button is going to left and despair and it's a problem. So, I would like to make Expander
ignore scrolling.
First view:
After scroll: