【问题标题】:Applying default style for ListViewItem, while using custom behavior为 ListViewItem 应用默认样式,同时使用自定义行为
【发布时间】:2013-04-07 01:42:52
【问题描述】:

我正在使用自定义行为将列表视图项滚动到 ListView 的当前可见视图中:

mvvm how to make a list view auto scroll to a new Item in a list view

<UserControl.Resources>
    <Style x:Key="ListBoxItemContainerStyle" TargetType="{x:Type ListBoxItem}"
        BasedOn="{StaticResource {x:Type ListBoxItem}}">
        <Setter Property="localBehaviors:ListBoxItemBehavior.IsBroughtIntoViewWhenSelected" Value="true"/>
    </Style>
</UserControl.Resources>

<!-- using Caliburn.Micro's conventions to bind ItemsSource -->
<ListView x:Name="Items" ItemContainerStyle="{StaticResource ListBoxItemContainerStyle}"
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Column #1" DisplayMemberBinding="{Binding ValueOfColumnOne}" />
            <!-- the rest of columns are defined here using DisplayMemberBinding or GridViewColumn.CellTemplate -->
        </GridView
    </ListView.View>
</ListView>

问题是,正如这个问题中所描述的那样,列表视图项目失去了它们的显示定义(我猜是模板):

ListView losing GridView display when applying ItemContainerStyle

但是,我不想重新定义 ListViewItem 的模板;即我想使用 WPF 提供的默认值。

【问题讨论】:

    标签: c# wpf listview attachedbehaviors


    【解决方案1】:

    你不能只使用 ScrollIntoView 吗?然后集中注意力。

    listview.ScrollIntoView(listviewitem);
    listviewitem.Focus();
    

    【讨论】:

    • 是的,我最终为 ListView 创建了行为,而不是。不过还是谢谢你的回答。
    猜你喜欢
    • 2019-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多