【发布时间】:2012-12-29 18:32:56
【问题描述】:
我在 WPF 应用程序中有一个带有 4 个单选按钮(2 个组)的向导内的页面。我正在使用 .Net4 和 Caliburn Micro。
单击并设置值时,它会正确绑定到相应的属性。 当我离开页面并返回时,我需要在代码中设置属性并期望它们通过 NotifyPropertyChanged 在页面上更新。 但是即使设置了相应的属性,也不会检查任何 RadioButtons...
有谁知道 caliburn.micro 应该如何工作?!
这是 xaml:
<RadioButton Name="NewInstallChecked" GroupName="InstallType" Content="New Installation (default)" Margin="75,10,0,0" />
<RadioButton Name="UpdateInstallChecked" GroupName="InstallType" Content="Update of existing Installation" Margin="75,10,0,0" />
<Label Content="Please select which version of Siseco you want to install:" Height="28" HorizontalAlignment="Left" Margin="20,20,0,0" Name="label2" VerticalAlignment="Top" />
<RadioButton Name="ServerChecked" GroupName="Version" Content="Server version (default)" Margin="75,10,0,0" />
<RadioButton Name="ClientChecked" GroupName="Version" Content="Client version" Margin="75,10,0,0" />
这里是我的视图模型中的代码:
public bool ClientChecked
{
get { return _clientChecked; }
set { _clientChecked = value; NotifyOfPropertyChange(() => ClientChecked); }
}
public bool ServerChecked
{
get { return _serverChecked; }
set { _serverChecked = value; NotifyOfPropertyChange(() => ServerChecked); }
}
public bool NewInstallChecked
{
get { return _newInstallChecked; }
set { _newInstallChecked = value; NotifyOfPropertyChange(() => NewInstallChecked); }
}
public bool UpdateInstallChecked
{
get { return _updateInstallChecked; }
set { _updateInstallChecked = value; NotifyOfPropertyChange(() => UpdateInstallChecked);}
}
...
protected override void OnActivate()
{
NewInstallChecked = _options.NewInstall;
UpdateInstallChecked = _options.UpdateInstall;
ServerChecked = _options.ServerInstall;
ClientChecked = _options.ClientInstall;
base.OnActivate();
}
【问题讨论】:
-
只是出于好奇-您是否尝试过不使用组中的单选按钮?我只是想知道“组”机制是否会以某种方式干扰绑定-从技术上讲,您应该让绑定解析初始值-您不应该在初始化时触发 propertychanged 事件(它是属性
changed事件,而不是属性初始化事件)。还可以尝试在 VM 的构造函数中设置checkedbool 值,看看是否有所不同 -
在 OnViewLoaded 中设置还是不行吗?
-
好点 - INPC 可能在附加视图之前触发,这意味着绑定没有任何更新,这意味着我的建议可能没用! :)
-
尝试在 OnViewLoaded 中设置该选项。没有帮助。
-
我也尝试了不设置属性因此不触发属性更改事件的解决方案,尽管我不认为这是一个“真正的”初始化,因为它不是页面的新实例,它只是被重新激活......但无论如何它也没有那样工作......
标签: c# wpf .net-4.0 radio-button caliburn.micro