Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - jumping ListBox

 
 
Old 01-10-2006   #1 (permalink)
michael.talics@gmail.com


 
 

jumping ListBox

Hi!

I have a little problem creating a custom ListBox in Dec-CTP. To see
the problem, just paste the code below into XamlPad.

Problem: Everytime you select an item at the bottom of the ListBox, the
ScrollViewer jumps almost to the top
Setting CanContentScroll="true" in the Template solves the Problem, but
creates other problems in my application, so this solution doesn't help
me at all

Any tips from you guys how to solve this problem?

Michael

<Grid Name="root"
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005">
<Grid.Resources>
<Style x:Key="{x:Type ListBox}" TargetType="{x:Type ListBox}">
<Setter Property="DefaultStyleKey" Value="{x:Null}" />
<Setter Property="Background" Value="White" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="#aa000000" />
<Setter Property="Padding" Value="2" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility"
Value="Auto" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border
CornerRadius="4"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
>

<ScrollViewer
CanContentScroll="false"
Margin="1"
HorizontalScrollBarVisibility="{TemplateBinding
ScrollViewer.HorizontalScrollBarVisibility}"
VerticalScrollBarVisibility="{TemplateBinding
ScrollViewer.VerticalScrollBarVisibility}"
Padding="{TemplateBinding Padding}"
>

<ItemsPresenter/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" Value="#EEEEEE" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="{x:Type ListBoxItem}" TargetType="{x:Type
ListBoxItem}">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border CornerRadius="3"
Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding
BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<ContentPresenter Content="{TemplateBinding
Content}" ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
HorizontalAlignment="Stretch" Name="ContentSite"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#eeF5F5FF" />
<Setter Property="BorderBrush" Value="Silver" />
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<ListBox HorizontalAlignment="Center" Height="150">
<ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test2</ListBoxItem>
<ListBoxItem>Test3</ListBoxItem>
<ListBoxItem>Test4</ListBoxItem>
<ListBoxItem>Test5</ListBoxItem>
<ListBoxItem>Test6</ListBoxItem>
<ListBoxItem>Test7</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test2</ListBoxItem>
<ListBoxItem>Test3</ListBoxItem>
<ListBoxItem>Test4</ListBoxItem>
<ListBoxItem>Test5</ListBoxItem>
<ListBoxItem>Test6</ListBoxItem>
<ListBoxItem>Test7</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test2</ListBoxItem>
<ListBoxItem>Test3</ListBoxItem>
<ListBoxItem>Test4</ListBoxItem>
<ListBoxItem>Test5</ListBoxItem>
<ListBoxItem>Test6</ListBoxItem>
<ListBoxItem>Test7</ListBoxItem>
<ListBoxItem>Test1</ListBoxItem>
<ListBoxItem>Test2</ListBoxItem>
<ListBoxItem>Test3</ListBoxItem>
<ListBoxItem>Test4</ListBoxItem>
<ListBoxItem>Test5</ListBoxItem>
<ListBoxItem>Test6</ListBoxItem>
<ListBoxItem>Test7</ListBoxItem>
</ListBox>
</Grid>


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Set Listbox Value .NET General
Easy to get handle from listbox. How to get listbox from handle? .NET General
Listbox PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46