I have scroll viewer enabled in treeview and listbox and have even customized the scroll bars refering this site and i have acheived what i need .My scroll bar is now looking like below
but i need my scrollbar to be look like this
I need that space in right bottom corner to be filled with horizontal or vertical scroll bar .Is it possible in wpf ??
Below is the customized style for the scrollbar
<local:ThicknessConverter x:Key="ThicknessConverter" />
<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Style.Triggers>
<Trigger Property="Orientation" Value="Horizontal">
<Setter Property="Width" Value="Auto"/>
<Setter Property="Height" Value="18" />
<Setter Property="Template"
Value="{StaticResource HorizontalScrollBar}" />
</Trigger>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="Width" Value="18"/>
<Setter Property="Height" Value="Auto" />
<Setter Property="Template"
Value="{StaticResource VerticalScrollBar}" />
</Trigger>
<Trigger Property="Name" Value="PART_VerticalScrollBar">
<Setter Property="Margin" Value="{Binding RelativeSource={RelativeSource AncestorType=ScrollViewer},Converter={StaticResource ThicknessConverter}}">
</Setter>
</Trigger>
</Style.Triggers>
</Style>
and here is there treeview code
<telerik:RadTreeView x:Name="radTreeView" Background="#4E4E4E" Margin="0,0,456,0" Grid.Row="2"
ItemsSource="{x:Static local:MainWindow.AnimalCategories}" ItemPrepared="treeView_ItemPrepared"
ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" Grid.RowSpan="2" Grid.ColumnSpan="2">
<telerik:RadTreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Animals}">
<TextBlock Text="{Binding Category}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</telerik:RadTreeView.ItemTemplate>
</telerik:RadTreeView>
Below is a way to do it:
XAML:
<ScrollViewer Height="400" Width="400" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" >
<ScrollViewer.Resources>
<local:ThicknessConverter x:Key="ThicknessConverter" />
<Style TargetType="ScrollBar">
<Style.Triggers>
<Trigger Property="Orientation" Value="Horizontal">
<Setter Property="Margin" Value="{Binding RelativeSource={RelativeSource AncestorType=ScrollViewer},Converter={StaticResource ThicknessConverter}}">
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ScrollViewer.Resources>
</ScrollViewer>
Converter:
public class ThicknessConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var scrollBars = FindVisualChildren<ScrollBar>(value as DependencyObject);
foreach (var scrollBar in scrollBars)
{
if (scrollBar.Orientation == Orientation.Horizontal)
{
return new Thickness(0, 0, 0, 0 - scrollBar.ActualHeight);
}
}
return new Thickness(0, 0, 0, 0);
}
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
yield return (T)child;
}
foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
OUTPUT:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With