在 ListView 中拖动列时,列选项卡顺序不会改变
是否可以将控件的 TabIndex 绑定到 GridView 中的列顺序?假设我们有一个 GridView,AllowsColumnReorder 设置为 true,当我们将第二列拖到最后时,选项卡导航顺序将保持按列排序:1 -> 3-> 2,而不是 1-> 2-> 3 和平常一样。我想要做的是根据第二张图片上的真实列布局进行选项卡导航。
我的 kxaml 代码:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<ListView ItemsSource="2"
Grid.Row="1">
<ListView.View>
<GridView AllowsColumnReorder="True">
<GridViewColumn Header="One">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="100" Text="1"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Two">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="100" Text="2"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Three">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="100" Text="3"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Page>
Is it possible to bind a control's TabIndex to the column's order in a GridView? Say, we have a GridView with AllowsColumnReorder set to true, and when we dragging a second column to be last, the tab navigation order would remain column-ordered: 1 -> 3 -> 2, and not the 1-> 2 -> 3 as usually. What i want to do is the tab navigation according to real column layout as on second image.
My code for kxaml:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<ListView ItemsSource="2"
Grid.Row="1">
<ListView.View>
<GridView AllowsColumnReorder="True">
<GridViewColumn Header="One">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="100" Text="1"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Two">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="100" Text="2"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Three">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="100" Text="3"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Page>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个使用 datagrid 的示例,而不是
EDIT
这是一个使用 listview 的解决方案,但我认为它不是最好的......
希望这有帮助
here is an example with datagrid instead
EDIT
here is a solution with listview that works, but i think its not the best...
hope this helps
如果您改用 DataGrid:这些列具有 DisplayIndex 属性,它保存当前索引,即使它们被重新排序。
If you use a DataGrid instead: The columns have a DisplayIndex property, which holds the current index, even when they are reordered.
这是一个伟大的开始。剩下要做的唯一一件事就是遍历 GridView 的 ListView 的项目并为行中的每个元素设置选项卡索引(
//!迭代 ListView 行
)。由于代码仓促,一些逻辑可能会混乱。XAMLC
#
Here's a big start. The only thing left to do would be to walk the GridView's ListView's Items and set tab index foreach element in the row (
//! iterate ListView rows
). Some of the logic may be messed up, as code was rushed..XAML
C#