Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 11.25 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Scroll bar is not coming in the right it is falling in the center in listbox
  2. <!--listBoxWithAutoScroll_Vertical-->
  3.     <SolidColorBrush x:Key="NormalBrush" Color="#FFCCCCCC"/>
  4.     <SolidColorBrush x:Key="PressedBrush" Color="#FFEEEEEE"/>
  5.     <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
  6.     <LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
  7.         <GradientBrush.GradientStops>
  8.             <GradientStopCollection>
  9.                 <GradientStop Color="#CCC" Offset="0.0"/>
  10.                 <GradientStop Color="#444" Offset="1.0"/>
  11.             </GradientStopCollection>
  12.         </GradientBrush.GradientStops>
  13.     </LinearGradientBrush>
  14.     <Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
  15.         <Setter Property="SnapsToDevicePixels" Value="True"/>
  16.         <Setter Property="OverridesDefaultStyle" Value="true"/>
  17.         <Setter Property="IsTabStop" Value="false"/>
  18.         <Setter Property="Focusable" Value="false"/>
  19.         <Setter Property="Width" Value="6"/>
  20.         <Setter Property="FlowDirection" Value="LeftToRight"/>
  21.         <Setter Property="Template">
  22.             <Setter.Value>
  23.                 <ControlTemplate TargetType="{x:Type RepeatButton}">
  24.                     <Border BorderBrush="#989590" BorderThickness="1" Background="Transparent" />
  25.                 </ControlTemplate>
  26.             </Setter.Value>
  27.         </Setter>
  28.     </Style>
  29.     <Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
  30.         <Setter Property="SnapsToDevicePixels" Value="True"/>
  31.         <Setter Property="OverridesDefaultStyle" Value="true"/>
  32.         <Setter Property="IsTabStop" Value="false"/>
  33.         <Setter Property="Focusable" Value="false"/>
  34.         <Setter Property="Template">
  35.             <Setter.Value>
  36.                 <ControlTemplate TargetType="{x:Type Thumb}">
  37.                     <Border FlowDirection="LeftToRight" Width="6" Background="Gray"
  38.                             BorderBrush="#989590" BorderThickness="1" />
  39.                 </ControlTemplate>
  40.             </Setter.Value>
  41.         </Setter>
  42.     </Style>
  43.     <Style x:Key="ScrollBarLineButton" TargetType="{x:Type RepeatButton}">
  44.         <Setter Property="SnapsToDevicePixels" Value="True"/>
  45.         <Setter Property="OverridesDefaultStyle" Value="true"/>
  46.         <Setter Property="Focusable" Value="false"/>
  47.          <Setter Property="FlowDirection" Value="LeftToRight"/>
  48.         <Setter Property="Template">
  49.             <Setter.Value>
  50.                 <ControlTemplate TargetType="{x:Type RepeatButton}">
  51.                     <Border Name="Border" CornerRadius="2" Background="{StaticResource NormalBrush}"
  52.                           BorderBrush="{StaticResource NormalBorderBrush}" >
  53.                         <Path HorizontalAlignment="Left" VerticalAlignment="Center" Fill="Gray"
  54.                             Data="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}"
  55.                             Opacity="{Binding Path=Opacity, RelativeSource={RelativeSource TemplatedParent}}"  />
  56.                     </Border>
  57.                     <ControlTemplate.Triggers>
  58.                         <Trigger Property="IsPressed" Value="true">
  59.                             <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
  60.                         </Trigger>
  61.                         <Trigger Property="IsEnabled" Value="false">
  62.                             <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
  63.                         </Trigger>
  64.                     </ControlTemplate.Triggers>
  65.                 </ControlTemplate>
  66.             </Setter.Value>
  67.         </Setter>
  68.     </Style>
  69.     <Style x:Key="ListBoxWithAutoScroll_Vertical" TargetType="{x:Type ListBox}" >
  70.         <Setter Property="SnapsToDevicePixels" Value="true"/>
  71.         <Setter Property="OverridesDefaultStyle" Value="true"/>
  72.         <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
  73.         <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
  74.         <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
  75.         <Setter Property="Background" Value="Transparent"/>
  76.         <Setter Property="Template">
  77.             <Setter.Value >
  78.                 <ControlTemplate>
  79.                     <Grid>
  80.                         <ScrollViewer x:Name="scrollviewer">
  81.                             <ScrollViewer.Template>
  82.                                 <ControlTemplate TargetType="{x:Type ScrollViewer}">
  83.                                     <Grid>
  84.                                         <ScrollBar x:Name="PART_VerticalScrollBar" Orientation="Vertical"
  85.                                                            Value="{TemplateBinding VerticalOffset}"
  86.                                                            Maximum="{TemplateBinding ScrollableHeight}"
  87.                                                            ViewportSize="{TemplateBinding ViewportHeight}"
  88.                                                            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}">
  89.                                             <ScrollBar.Template>
  90.  
  91.                                                 <ControlTemplate>
  92.                                                     <Track x:Name="PART_Track" IsDirectionReversed="True">
  93.                                                         <Track.DecreaseRepeatButton>
  94.                                                             <RepeatButton Command="ScrollBar.PageUpCommand"
  95.                                                                         Style="{StaticResource ScrollBarPageButton}"/>
  96.                                                         </Track.DecreaseRepeatButton>
  97.                                                         <Track.IncreaseRepeatButton>
  98.                                                             <RepeatButton Command="ScrollBar.PageDownCommand"
  99.                                                                         Style="{StaticResource ScrollBarPageButton}"/>
  100.                                                         </Track.IncreaseRepeatButton>
  101.                                                         <Track.Thumb>
  102.                                                             <Thumb Style="{StaticResource ScrollBarThumb}"
  103.                                                                      Background="Gray" Opacity="0.8"/>
  104.                                                         </Track.Thumb>
  105.                                                     </Track>
  106.                                                 </ControlTemplate>
  107.                                             </ScrollBar.Template>
  108.                                         </ScrollBar>
  109.                                         <ScrollContentPresenter Width="Auto" HorizontalAlignment="Left"/>
  110.                                     </Grid>
  111.                                 </ControlTemplate>
  112.                             </ScrollViewer.Template>
  113.                             <ItemsPresenter/>
  114.                         </ScrollViewer>
  115.                         <Grid x:Name="Panel">
  116.                             <Grid.RowDefinitions>
  117.                                 <RowDefinition Height="Auto"/>
  118.                                 <RowDefinition Height="*"/>
  119.                                 <RowDefinition Height="Auto"/>
  120.                             </Grid.RowDefinitions>
  121.                             <RepeatButton x:Name="LineUpButton" Grid.Row="0" Height="20" Opacity="0" Visibility="Collapsed"
  122.                                   Style="{StaticResource ScrollBarLineButton}"
  123.                                   Content="M 0 8 L 32 8 L 16 0 Z"      
  124.                                   Command="{x:Static ScrollBar.LineUpCommand}"      
  125.                                   CommandTarget="{Binding ElementName=scrollviewer}"
  126.                                   ClickMode="Hover" />
  127.                             <RepeatButton x:Name="LineDownButton" Grid.Row="2" Height="20" Opacity="0" Visibility="Collapsed"
  128.                                   Style="{StaticResource ScrollBarLineButton}"
  129.                                   Content="M 0 0 L 16 8 L 32 0 Z"
  130.                                   Command="{x:Static ScrollBar.LineDownCommand}"      
  131.                                   CommandTarget="{Binding ElementName=scrollviewer}"
  132.                                   ClickMode="Hover"/>
  133.                         </Grid>
  134.                     </Grid>
  135.                     <ControlTemplate.Triggers>
  136.                         <MultiTrigger>
  137.                             <MultiTrigger.Conditions>
  138.                                 <Condition Property="IsMouseOver" Value="True"/>
  139.                                 <Condition Property="ComputedVerticalScrollBarVisibility" SourceName="scrollviewer" Value="Visible"/>
  140.                             </MultiTrigger.Conditions>
  141.                             <MultiTrigger.Setters>
  142.                                 <Setter TargetName="LineUpButton" Property="Visibility" Value="Visible" />
  143.                                 <Setter TargetName="LineDownButton" Property="Visibility" Value="Visible" />
  144.                             </MultiTrigger.Setters>
  145.                             <MultiTrigger.EnterActions>
  146.                                 <BeginStoryboard>
  147.                                     <Storyboard>
  148.                                         <DoubleAnimation Storyboard.TargetName="LineUpButton"
  149.                                                          Storyboard.TargetProperty="Opacity" To="0.8" Duration="0:0:0.25"/>
  150.                                         <DoubleAnimation Storyboard.TargetName="LineDownButton"
  151.                                                          Storyboard.TargetProperty="Opacity" To="0.8" Duration="0:0:0.25"/>
  152.                                     </Storyboard>
  153.                                 </BeginStoryboard>
  154.                             </MultiTrigger.EnterActions>
  155.                             <MultiTrigger.ExitActions>
  156.                                 <BeginStoryboard>
  157.                                     <Storyboard>
  158.                                         <DoubleAnimation Storyboard.TargetName="LineUpButton"
  159.                                                          Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.25"/>
  160.                                         <DoubleAnimation Storyboard.TargetName="LineDownButton"
  161.                                                          Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.25"/>
  162.                                     </Storyboard>
  163.                                 </BeginStoryboard>
  164.                             </MultiTrigger.ExitActions>
  165.                         </MultiTrigger>
  166.                     </ControlTemplate.Triggers>
  167.                 </ControlTemplate>
  168.             </Setter.Value>
  169.         </Setter>
  170.         <Setter Property="ItemsPanel">
  171.             <Setter.Value >
  172.                 <ItemsPanelTemplate>
  173.                     <VirtualizingStackPanel Orientation="Vertical"/>
  174.                 </ItemsPanelTemplate>
  175.             </Setter.Value>
  176.         </Setter>
  177.     </Style>
  178.        
  179. <Grid>
  180.     <Grid.ColumnDefinitions>
  181.         <ColumnDefinition />
  182.         <ColumnDefinition Width="Auto" />
  183.     </Grid.ColumnDefinitions>
  184.     <ScrollBar Grid.Column="1">
  185.         <!-- ScrollBar contents and other properties omitted for brevity -->
  186.     </ScrollBar>
  187.     <ScrollContentPresenter Grid.Column="0" Width="Auto" HorizontalAlignment="Left"/>
  188. </Grid>