ScrollViewer中的RadioButtons的WPF ListBox - 在选择更改之前滚动

时间:2012-09-20 12:29:50

标签: wpf triggers listbox radio-button scrollviewer

我有很烦人的问题。我在ScrollViewer中有ListBox。 ListBox充满了RadioButton控件。以下代码显示:

<Grid>
<Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" CanContentScroll="False">
        <ListBox Name="lbActiveProjects" Background="Transparent" 
                         Style="{StaticResource RadioButtonList}" SelectedValuePath="Value.IsMainProject"
                         ItemTemplate="{StaticResource ResourceKey=radioButtonActiveProjectsListItem}"
                         ItemsSource="{Binding Path=Model.Worker.ProjectManager.Projects}"
                         SelectedValue="true" FontSize="{Binding Source={x:Static props:Settings.Default}, 
                                                                                                         Path=SmallerFontSize}"
                         Grid.Row="0" 
                        ><!--ScrollViewer.VerticalScrollBarVisibility="Auto"-->
                <i:Interaction.Triggers>
                        <i:EventTrigger EventName="PreviewMouseUp">
                                <cmd:EventToCommand Command="{Binding SelectionChangedCommand}"
                                                                        CommandParameter="{Binding ElementName=lbActiveProjects, Path=SelectedItem.Value}"/>
                        </i:EventTrigger>
                </i:Interaction.Triggers>
        </ListBox>
</ScrollViewer>
.
.
.
</Grid>

现在,当我在ListBox上有足够的项目来显示滚动条时,我无法选择底部项目。每次我尝试这样做 - 列表框滚动到顶部,在SelectedItem.Value内部,列表中没有最后一项,但是其中一个更接近顶部(如底部的第三个或者是......)。

有没有办法阻止它滚动到顶部(我不需要)或者至少强迫他在滚动之前选择合适的项目?

由于

1 个答案:

答案 0 :(得分:0)

最简单的解决方案是最好的解决方案。我想除了删除ScrollViewer并让ListBox单独滚动其内容之外别无他法。

相关问题