TreeView And TreeViewItem

image_pdfimage_print


   
   

<Window x:Class="SimpleStyles.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="SimpleStyles"
  Background="#F8F8F8">
  <ScrollViewer>
    <WrapPanel>
       <HeaderedItemsControl Header="TreeView">
        <StackPanel>
          <TreeView Width="150" Height="150" Margin="8">
            <TreeViewItem Header="Top One">
              <TreeViewItem Header="Sub One" />
              <TreeViewItem Header="Sub Two (Longer than Normal)" />
              <TreeViewItem Header="Sub Three" />
              <TreeViewItem Header="Sub Four">
                <TreeViewItem Header="Sub One" />
                <TreeViewItem Header="Sub Two" />
                <TreeViewItem Header="Sub Three" />
              </TreeViewItem>
              <TreeViewItem Header="Sub Five" />
            </TreeViewItem>
            <TreeViewItem Header="Top Two">
              <TreeViewItem Header="Sub One" />
              <TreeViewItem Header="Checkable" />
              <TreeViewItem Header="Sub Three" />
              <TreeViewItem Header="Sub Four">
                <TreeViewItem Header="Sub One" />
                <TreeViewItem Header="Sub Two" />
                <TreeViewItem Header="Sub Three" />
              </TreeViewItem>
              <TreeViewItem Header="Sub Five" />
            </TreeViewItem>
            <TreeViewItem Header="Top Three" >
              <TreeViewItem Header="Sub One" />
              <TreeViewItem Header="Sub Two" />
              <TreeViewItem Header="Sub Three" />
              <TreeViewItem Header="Sub Five" />
            </TreeViewItem>
          </TreeView>
        </StackPanel>
      </HeaderedItemsControl>
   
    </WrapPanel>
  </ScrollViewer>
</Window>

   
    
    
     


Set drop shadow for a ToolTip

image_pdfimage_print


   
     

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="160" Width="300">
    <Window.Resources>
        <Style TargetType="{x:Type ToolTip}">
            <Setter Property="Width" Value="100"/>
            <Setter Property="Height" Value="100"/>
            <Setter Property="HasDropShadow" Value="True"/>
            <Setter Property="OverridesDefaultStyle" Value="True"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate 
                        TargetType="{x:Type ToolTip}">
                        <Border Name="Border"
                            BorderBrush="DarkGray"
                            BorderThickness="1"
                            Width="{TemplateBinding Width}"
                            Height="{TemplateBinding Height}"
                            CornerRadius="4">
                            <Border.Background>
                                <LinearGradientBrush 
                                    StartPoint="0,0"
                                    EndPoint="0,1">
                                    <GradientStop 
                                        Color="Snow" 
                                        Offset="0.0"/>
                                    <GradientStop 
                                        Color="Gainsboro" 
                                        Offset="1.0"/>
                                </LinearGradientBrush>
                            </Border.Background>

                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </Window.Resources>

    <Grid>
            <TextBlock Foreground="DarkGray" 
                       VerticalAlignment="Center" 
                       HorizontalAlignment="Center"
                       ToolTip="This is a custom tooltip"
                       Text="Mouse Over for tooltip"/>
    </Grid>
    
</Window>

   
    
    
    
    
     


Add Image to ToolTip

image_pdfimage_print


   
     



<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="160" Width="300">
    <Window.Resources>
        <Style TargetType="{x:Type ToolTip}">
            <Setter Property="Width" Value="100"/>
            <Setter Property="Height" Value="100"/>
            <Setter Property="OverridesDefaultStyle" Value="True"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate 
                        TargetType="{x:Type ToolTip}">
                        <Border Name="Border"
                            BorderBrush="DarkGray"
                            BorderThickness="1"
                            Width="{TemplateBinding Width}"
                            Height="{TemplateBinding Height}"
                            CornerRadius="4">
                            <StackPanel Orientation="Horizontal">
                                <Image Margin="4,4,0,4" Source="c:image.gif"/>
                                <ContentPresenter
                                  Margin="4" 
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Top" />
                                </StackPanel>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </Window.Resources>

    <Grid>
            <TextBlock Foreground="DarkGray" 
                       VerticalAlignment="Center" 
                       HorizontalAlignment="Center"
                       ToolTip="This is a custom tooltip"
                       Text="Mouse Over for tooltip"/>
    </Grid>
    
</Window>

   
    
    
    
    
     


Set border for ToolTip by using ControlTemplate

image_pdfimage_print


   
     

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="160" Width="300">
    <Window.Resources>
        <Style TargetType="{x:Type ToolTip}">
            <Setter Property="Width" Value="100"/>
            <Setter Property="Height" Value="100"/>
            <Setter Property="HasDropShadow" Value="True"/>
            <Setter Property="OverridesDefaultStyle" Value="True"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate 
                        TargetType="{x:Type ToolTip}">
                        <Border Name="Border"
                            BorderBrush="DarkGray"
                            BorderThickness="1"
                            Width="{TemplateBinding Width}"
                            Height="{TemplateBinding Height}"
                            CornerRadius="4">
                            <Border.Background>
                                <LinearGradientBrush 
                                    StartPoint="0,0"
                                    EndPoint="0,1">
                                    <GradientStop 
                                        Color="Snow" 
                                        Offset="0.0"/>
                                    <GradientStop 
                                        Color="Gainsboro" 
                                        Offset="1.0"/>
                                </LinearGradientBrush>
                            </Border.Background>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </Window.Resources>

    <Grid>
            <TextBlock Foreground="DarkGray" 
                       VerticalAlignment="Center" 
                       HorizontalAlignment="Center"
                       ToolTip="This is a custom tooltip"
                       Text="Mouse Over for tooltip"/>
    </Grid>
    
</Window>

   
    
    
    
    
     


Complex ToolTip

image_pdfimage_print


   
      
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  Title="About WPF" 
  Background="OrangeRed">
        <Canvas>
        <CheckBox>
          CheckBox
          <CheckBox.ToolTip>
            <StackPanel>
              <Label FontWeight="Bold" Background="Blue" Foreground="White">
                The CheckBox
              </Label>
              <TextBlock Padding="10" TextWrapping="WrapWithOverflow" Width="200">
                this is a test
              </TextBlock>
              <Line Stroke="Black" StrokeThickness="1" X2="200"/>
              <StackPanel Orientation="Horizontal">
                <Image Margin="2" Source="help.png"/>
                <Label FontWeight="Bold">Press F1 for more help.</Label>
              </StackPanel>
            </StackPanel>
          </CheckBox.ToolTip>
        </CheckBox>
        </Canvas>

</Window>

   
    
    
    
    
    
     


Control the Display Duration and Position of a Tool Tip

image_pdfimage_print


   
     

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="200" Width="300">
    <StackPanel>
        <Button Height="40" Margin="5" ToolTipService.Placement="Mouse" 
                ToolTipService.ShowDuration="1000">
            <Button.ToolTip>
                <ToolTip>
                    ToolTip displayed for 1 second...
                </ToolTip>
            </Button.ToolTip>
            Button with ToolTip under Mouse
        </Button>
    </StackPanel>
</Window>

   
    
    
    
    
     


Set ToolTip Placement, ShowDuration, VerticalOffset

image_pdfimage_print


   
     

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="200" Width="300">
    <StackPanel>
        <Button Height="40" Margin="5" ToolTipService.HorizontalOffset="5cm" 
                ToolTipService.Placement="Relative" 
                ToolTipService.ShowDuration="10000" 
                ToolTipService.VerticalOffset="50px">
            <Button.ToolTip>
                <ToolTip >
                    ToolTip displayed for 10 seconds...
                </ToolTip>
            </Button.ToolTip>
            Button with offset ToolTip
        </Button>
    </StackPanel>
</Window>