空,我想在从ListView中派生,我们已经创建了一个控制禁用列reording。这种控制称为SortableListView
。我认为一个依赖项属性将是实现这一点的最佳方式,但((SortableListVIew)source).View
返回null
。下面是代码:ListView.View是依赖属性
public class SortableListView : ListView
{
// ...lots of other properties here
public static readonly DependencyProperty AllowsColumnReorderProperty =
DependencyProperty.Register(
"AllowsColumnReorder",
typeof(bool),
typeof(SortableListView),
new UIPropertyMetadata(true, AllowsColumnReorderPropertyChanged));
public bool AllowsColumnReorder
{
get
{
return (bool)this.GetValue(AllowsColumnReorderProperty);
}
set
{
this.SetValue(AllowsColumnReorderProperty, value);
}
}
private static void AllowsColumnReorderPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
ViewBase vb = ((SortableListView)source).View;
if (vb != null)
{
((GridView)vb).AllowsColumnReorder = (bool)e.NewValue;
}
}
而XAML:
<TableControls:SortableListView x:Name="QueueViewTable" Margin="0,0,0,0"
Style="{StaticResource ListViewStyle}"
ItemsSource="{Binding Path=QueueList}"
ItemContainerStyle="{StaticResource alternatingListViewItemStyle}"
AlternationCount="2"
SelectionMode="Single"
SortEnabled="False"
AllowsColumnReorder="false">
麻烦的是,VB总是空,因此方法无法设置AllowsColumnReoder。我敢肯定,中投是有效的,因为最初的代码看起来像这样在OnInitialized:
((GridView)this.View).AllowsColumnReorder = false;
...但我需要设置AllowsColumnReorder对视图的特定实例所以这个代码是没有好。
谁能告诉我我做错了什么?或者有更好的方法来设置这个属性?
我不太确定我的理解。如何覆盖View属性并添加更改侦听器?对于愚蠢的问题抱歉,但我对WPF相当陌生,正在学习工作。 – serlingpa
更新的答案包括更多信息 –
非常感谢您的信息约翰。我还有一个问题:如何为我的AlowsColumnReorderPropertyChanged方法获得正确的Paramanter? – serlingpa