<Window x:Class="ControllingExpanderStyle_WPF.MainWindow"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
		Title="MainWindow" Height="400" Width="525">
	
	<Window.Resources>
<Style TargetType="telerik:RadTreeViewItem">
	<Style.Setters>
		<Setter Property="ExpanderStyle" Value="{Binding MyCustomExpanderStyle, Mode=TwoWay}"/>
	</Style.Setters>
</Style>

		<Style x:Key="ExpanderStyle_1" TargetType="ToggleButton">
			<Setter Property="Visibility" Value="Visible" />
			<Setter Property="IsEnabled" Value="True" />
			<Setter Property="IsTabStop" Value="False" />
			<Setter Property="Cursor" Value="Hand" />
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="ToggleButton">
						<Grid>
							<Grid x:Name="Button" Margin="0,7,4,0" HorizontalAlignment="Right"
									VerticalAlignment="Top" Width="11" Height="11" Background="Transparent">
								<Rectangle Stroke="#FF989898" HorizontalAlignment="Left"
										VerticalAlignment="Top" Width="11" Height="11" />
								<Rectangle x:Name="CollapsedVisual" Fill="#FF989898"
										HorizontalAlignment="Left" VerticalAlignment="Top" Width="1"
										Height="5" Margin="5,3,0,0" />
								<Rectangle Fill="#FF989898" VerticalAlignment="Top"
										HorizontalAlignment="Left" Height="1" Width="5"
										Margin="3,5,0,0" />
							</Grid>
						</Grid>
						<ControlTemplate.Triggers>
							<Trigger Property="IsChecked" Value="True">
								<Setter TargetName="CollapsedVisual" Property="Opacity" Value="0" />
							</Trigger>
							<Trigger Property="IsMouseOver" Value="True" />
							<Trigger Property="IsEnabled" Value="false" />
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>

		<Style x:Key="ExpanderStyle_2" TargetType="ToggleButton">
			<Setter Property="Visibility" Value="Visible" />
			<Setter Property="IsEnabled" Value="True" />
			<Setter Property="IsTabStop" Value="False" />
			<Setter Property="Cursor" Value="Hand" />
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="ToggleButton">
						<Grid>
							<Grid x:Name="Button" Background="Transparent" Width="11" >

								<Path x:Name="arrow" Opacity="1" HorizontalAlignment="Right"
						Grid.Column="5" VerticalAlignment="Center" Stretch="None"
						Stroke="#FF989898" StrokeThickness="2"
						RenderTransformOrigin="0.5 0.5"
						Data="M 1,1.5 L 4.5,5 L 8,1.5" >
									<Path.RenderTransform>
										<RotateTransform x:Name="directionRotation" Angle="-90" />
									</Path.RenderTransform>
								</Path>

							</Grid>
						</Grid>
						<ControlTemplate.Triggers>
							<Trigger Property="IsChecked" Value="True">
								<Setter TargetName="arrow" Property="RenderTransform">
									<Setter.Value>
										<TransformGroup>
											<RotateTransform Angle="0"/>
										</TransformGroup>
									</Setter.Value>
								</Setter>
							</Trigger>
							<Trigger Property="IsMouseOver" Value="True" />
							<Trigger Property="IsEnabled" Value="false" />
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>

		<Style x:Key="ExpanderStyle_3" TargetType="ToggleButton">
			<Setter Property="Visibility" Value="Visible" />
			<Setter Property="IsEnabled" Value="True" />
			<Setter Property="IsTabStop" Value="False" />
			<Setter Property="Cursor" Value="Hand" />
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="ToggleButton">
						<Grid>
							<Grid x:Name="Button"  Background="Transparent" Width="16" Height="12" >
								<Image Source="Images/close_folder.png" Stretch="None" x:Name="closebutton" Opacity="1" />
								<Image Source="Images/open_folder.png" Stretch="None" x:Name="openbutton" Opacity="0" />
							</Grid>
						</Grid>

						<ControlTemplate.Triggers>
							<Trigger Property="IsChecked" Value="True">
								<Setter TargetName="closebutton" Property="Opacity" Value="0" />
								<Setter TargetName="openbutton" Property="Opacity" Value="1" />
							</Trigger>
							<Trigger Property="IsMouseOver" Value="True" />
							<Trigger Property="IsEnabled" Value="false" />
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>

		<HierarchicalDataTemplate x:Key="ItemsTemplate" ItemsSource="{Binding Items}">
			<TextBlock Text="{Binding Name}"/>
		</HierarchicalDataTemplate>
	</Window.Resources>

	<StackPanel Orientation="Horizontal" Margin="20">

		<telerik:RadTreeView x:Name="myTreeView" Width="250" BorderThickness="1" BorderBrush="#FF989898"
							 ItemTemplate="{StaticResource ItemsTemplate}"
							 IsVirtualizing="True"
							 />

		<StackPanel Margin="20 0">
			<TextBlock Text="Choose ExpanderStyle:" Margin="0 2"/>
			<telerik:RadButton Content="Tree Style1" x:Name="TreeStyle1" Click="TreeStyle1_Click" Margin="0 2"/>
			<telerik:RadButton Content="Tree Style2" x:Name="TreeStyle2" Click="TreeStyle2_Click" Margin="0 2"/>
			<telerik:RadButton Content="Tree Style3" x:Name="TreeStyle3" Click="TreeStyle3_Click" Margin="0 2"/>
			<TextBlock Text="Choose ItemStyle:" Margin="0 10 0 2"/>
			<telerik:RadButton Content="Item Style1" x:Name="ItemStyle1" Click="ItemStyle1_Click" Margin="0 2"/>
			<telerik:RadButton Content="Item Style2" x:Name="ItemStyle2" Click="ItemStyle2_Click" Margin="0 2"/>
			<telerik:RadButton Content="Item Style3" x:Name="ItemStyle3" Click="ItemStyle3_Click" Margin="0 2"/>
			<TextBlock Text="Clear Style:" Margin="0 10 0 2"/>
			<telerik:RadButton Content="Clear Local Tree Style" x:Name="ClearLocalTreeStyle" Click="ClearLocalTreeStyle_Click" Margin="0 2"/>
			<telerik:RadButton Content="Clear Local Item Style" x:Name="ClearLocalItemStyle" Click="ClearLocalItemStyle_Click" Margin="0 2"/>
		</StackPanel>

	</StackPanel>
	
</Window>
