gpt4 book ai didi

wpf - 防止在 Xceed DataGrid 上重新排序

转载 作者:行者123 更新时间:2023-12-04 13:53:38 36 4
gpt4 key购买 nike

我正在尝试取消 xceed datagrid(社区版)网格(http://wpftoolkit.codeplex.com/wikipage?title=DataGrid)中某些列的重新排序/拖放功能

到目前为止我所做的是监听 PreviewMouseLeftButtonUp/Down 事件。然后我可以在 Down 上设置 handled = true 并且用户不能对列执行任何操作(没有排序或任何东西)或在 Up 上,检查 IsBeingDragged 是否为真。但是如果我设置 e.Handled 然后,该列将保持拖动模式。我想要做的是取消整个拖动并将列放回原来的位置,或者(如果可能的话)尽可能靠近拖放的列。

谁能指导我?

private void ColumnManagerCell_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
// Check that the Original Source is a ColumnManagerCell
if (sender.GetType() == typeof(Xceed.Wpf.DataGrid.ColumnManagerCell))
{
ColumnManagerCell col = sender as ColumnManagerCell;
if (col.IsBeingDragged)
{
// user attempted to move the column to a new location, or to the GroupByControl area
e.Handled = true;
}
}
}

最佳答案

来自 Xceed DataGrid 的文档:

http://doc.xceedsoft.com/products/XceedWpfDataGrid/#Grouping_Data.html

<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
xmlns:d="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase">
<Grid.Resources>
<xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
Source="{Binding Source={x:Static Application.Current},
Path=Orders}">
<xcdg:DataGridCollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="ShipCountry" Direction="Ascending"/>
<scm:SortDescription PropertyName="ShipCity" Direction="Ascending"/>
</xcdg:DataGridCollectionViewSource.SortDescriptions>
<xcdg:DataGridCollectionViewSource.GroupDescriptions>
<xcdg:DataGridGroupDescription PropertyName="ShipCountry"/>
<xcdg:DataGridGroupDescription PropertyName="ShipCity"/>
</xcdg:DataGridCollectionViewSource.GroupDescriptions>
</xcdg:DataGridCollectionViewSource>
</Grid.Resources>
<xcdg:DataGridControl x:Name="OrdersGrid"
ItemsSource="{Binding Source={StaticResource cvs_orders}}">
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="ShipCountry" VisiblePosition="0"/>
<xcdg:Column FieldName="ShipCity" VisiblePosition="1"/>
</xcdg:DataGridControl.Columns>
<xcdg:DataGridControl.View>
<xcdg:TableView FixedColumnCount="2" UseDefaultHeadersFooters="False">
<xcdg:TableView.FixedHeaders>
<DataTemplate>
<xcdg:GroupByControl AllowSort="False" AllowGroupingModification="False"/>
</DataTemplate>
<DataTemplate>
<xcdg:ColumnManagerRow AllowSort="False" AllowColumnReorder="False"/>
</DataTemplate>
</xcdg:TableView.FixedHeaders>
</xcdg:TableView>
</xcdg:DataGridControl.View>
</xcdg:DataGridControl>
</Grid>

关于wpf - 防止在 Xceed DataGrid 上重新排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24155816/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com