【问题标题】:WPF ListBox of RadioButtons inside ScrollViewer - scrolls before selection changedScrollViewer 内 RadioButtons 的 WPF ListBox - 在选择更改之前滚动
【发布时间】:2012-09-25 14:48:47
【问题描述】:

我有一个很烦人的问题。我在 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 上有足够的项目来显示滚动条时,我无法选择底部项目。每次我尝试这样做时 - ListBox 都会滚动到顶部和 SelectedItem.Value 内部,列表中没有最后一项,而是靠近顶部的一项(例如从底部算起的第三个或某事)。

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

谢谢

【问题讨论】:

    标签: wpf triggers listbox radio-button scrollviewer


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 1970-01-01
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多