Search code examples
wpfxamllistboxscrollinteraction

Mysterious AutoScrolling WPF Listbox


Have a very werid issue. My machine is Windows7 64bit. My listbox scrolls properly on all our 64bit computers at work. However, on the 32bit systems the listbox does not scroll properly. When a user clicks the down arrow to navigte down the listbox list, it goes down but then jumps right back up to the top. It does not matter if it was done by arrows, mousewheel, or clicking in the scrollbar area. Has anyone come across this werid issue before, and figured out a way to resolve it? I have tried releasing with cpu x86 and All cpu and still same issue either way.

Another note: Another issue I encountered betweeen 64it and 32bit OS was binding a datagrid to a datatable. On my system if the datatable had zero rows in it, it still bound with no issues, but on the 32bit systems we get a binding error trying to bind to a datatable with a row count of zero. Only mention this in case some sees some werid correlation between the two.

Listbox XAML

<!-- System Listbox -->
    <Grid Grid.Row="2" Grid.Column="0" VerticalAlignment="Stretch">
        <DockPanel Margin="10,0,0,10" VerticalAlignment="Stretch">
            <ListBox x:Name="lbSystems" VerticalAlignment="Stretch" DockPanel.Dock="Left" Width="Auto" IsTextSearchEnabled="True" TextSearch.TextPath="{Binding Name}"
                     Background="Transparent" Foreground="{DynamicResource DynamicFrmFG}" FontFamily="Consolas" 
                     ItemsSource="{Binding Path=SystemsList}" ItemTemplate="{StaticResource mySystemTemplate}" SelectedItem="{Binding Path=SelectedSystem}" 
                     SelectionChanged="lbSystems_SelectionChanged" ContextMenuOpening="lbSystems_ContextMenuOpening">
                <ListBox.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{DynamicResource DynamicCtrlHighlight}"/>
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{DynamicResource DynamicCtrlHighlight}"/>
                </ListBox.Resources>
            </ListBox>
        </DockPanel>
    </Grid>

The Listbox item template

    <Window.Resources>
    <DataTemplate x:Key="mySystemTemplate">
        <StackPanel VerticalAlignment="Stretch">
            <TextBlock Text="{Binding Mode=OneWay}" Foreground="{DynamicResource DynamicFrmFG}" FontSize="14" FontFamily="Consolas" 
                       TextWrapping="Wrap" Margin="0,2,0,2"/>
        </StackPanel>  
    </DataTemplate>
</Window.Resources>

EDIT: Using .Net Version 4. Its the standard version pushed to all machines.


Solution

  • Well it seems it had to deal with my grid ColumnDefinition. DO not really understand it but below is the XAML I had previously.

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="125" />
            <RowDefinition Height="*" />
            <RowDefinition Height="20" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" MinWidth="300" />
            <ColumnDefinition Width="475*" />
        </Grid.ColumnDefinitions>
    

    Soon as I changed the first column to read, as written below, it started scrolling properly on all machines.

    <ColumnDefinition Width="300*" MinWidth="300" />