【发布时间】:2018-09-17 02:10:13
【问题描述】:
我想在所有前面的页面都有效时启用给定的向导页面。这是我的视图模型:
[Aggregatable]
[NotifyPropertyChanged]
[ContentProperty("Pages")]
public class Wizard
{
[Child, AggregateAllChanges]
public AdvisableCollection<Page> Pages { get; } = new AdvisableCollection<Page>();
}
这是Page 本身:
[Aggregatable]
[NotifyPropertyChanged]
public class Page : INotifyPropertyChanged
{
[Parent] Wizard Wizard { get; set; }
public string Name { get; set; }
public bool Valid { get; set; }
[SafeForDependencyAnalysis]
public bool Enabled
{
get
{
if(Depends.Guard)
Depends.On(Wizard.Pages);
return Wizard.Pages
.TakeWhile(p => p != this)
.All(p => p.Valid);
}
}
public event PropertyChangedEventHandler PropertyChanged = delegate { };
void OnPropertyChanged(string propertyName)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
if (Wizard != null)
NotifyPropertyChangedServices.SignalPropertyChanged(Wizard, nameof(Wizard.Pages));
}
}
我期待 PostSharp 在 Wizard.Pages 更改时通知 Enabled 属性更改。不幸的是,它不起作用 - Enabled 属性没有更新。这段代码有什么问题?
要测试的 XAML:
<Window.DataContext>
<local:Wizard>
<local:Page Name="First"/>
<local:Page Name="Second"/>
<local:Page Name="Third"/>
<local:Page Name="Forth"/>
</local:Wizard>
</Window.DataContext>
<ListBox ItemsSource="{Binding Pages}">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type local:Page}">
<CheckBox Content="{Binding Name}" IsChecked="{Binding Valid}" IsEnabled="{Binding Enabled}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
【问题讨论】:
-
NotifyPropertyChanged和Aggregatable方面之间的兼容性错误已在 PostSharp 版本 6.0.29 中修复。请将您的 NuGet 包更新到最新版本。
标签: c# wpf xaml postsharp .net-4.7.2