BerndKraemer

BerndKraemer
- Name: [not set]
- Favorite Languages: [not set]
- Website: [not set]
- Location: [not set]
- About Me: [not set]
-
WPF Tutorial - Using An ItemsPanel
02/25/2009 - 12:12
I have used the same technique (supplying a WrapPanel or a UniformGrid for displaying a number of images in a ListBox), with the possibility to set the number of visible rows and columns in the ScrollViewer inside the ListBox.
My question is: how can I scroll in discrete steps, i.e. per whole item instead of the smooth scrolling that I get by default? (I also changed the setting of the scroll wheel in the Windows configuration to scroll 1 line at a time. For the normal VirtualStackPanel this works fine, but I need multiple columns of images).Some code snippets from my experiment. I edited the generic.xaml for my own special ListBox.
<Setter Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="{x:Type MyListBox}">
<Border x:Name="Bd">
<ScrollViewer
CanContentScroll="True"
VerticalContentAlignment="Top"
HorizontalContentAlignment="Left"
HorizontalScrollBarVisibility ="Disabled">
<ItemsPresenter
VerticalAlignment="Top"
HorizontalAlignment="Stretch"
Width="Auto"/>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>And in C# I created the UniformGrid to fit an exact number of visible rows and columns of images inside the scrollviewer of the listbox:
// Create a matrix layout for the total number of images
FrameworkElementFactory uGrid =
new FrameworkElementFactory(typeof(UniformGrid));
uGrid.SetValue(UniformGrid.ColumnsProperty, totalCols);
uGrid.SetValue(UniformGrid.RowsProperty, totalRows);
// show only a submatrix of images in the listbox
double width = this.ActualWidth * totalCols / visibleCols;
double height = this.ActualHeight * totalRows / visibleRows;
uGrid.SetValue(UniformGrid.WidthProperty, width);
uGrid.SetValue(UniformGrid.HeightProperty, height);
this.ItemsPanel = new ItemsPanelTemplate(uGrid);How can I scroll the images row by row and column by column? Or maybe there are more convenient ways to do this... Thanks in advance for your answer! - Bernd -
Recent Comments