我具有以下类我使用的单选按钮结合C# - 动态属性和RaisePropertyChanged
public class RadioButtonSwitch : ViewModelBase
{
IDictionary<string, bool> _options;
public RadioButtonSwitch(IDictionary<string, bool> options)
{
this._options = options;
}
public bool this[string a]
{
get
{
return _options[a];
}
set
{
if (value)
{
var other = _options.Where(p => p.Key != a).Select(p => p.Key).ToArray();
foreach (string key in other)
_options[key] = false;
_options[a] = true;
RaisePropertyChanged("XXXX");
else
_options[a] = false;
}
}
}
XAML
<RadioButton Content="Day" IsChecked="{Binding RadioSwitch[radio1], Mode=TwoWay}" GroupName="Monthly" HorizontalAlignment="Left" VerticalAlignment="Center" />
视图模型
RadioSwitch = new RadioButtonSwitch(
new Dictionary<string, bool> {{"radio1", true},{"radio2", false}}
);
我有问题RaisePropertyChanged()在我的类。我不确定为了改变这个变化我应该投入什么样的价值。
我试图把:
- 项目[]
- 一个
- [A]
我不断收到以下错误:
这是如此,如果有任何改变,我可以在我看来相应地处理它。请不要给我的解决方案为单选按钮等列表
定义了“ViewModelBase”的位置? – 2011-05-21 02:40:59
'ViewModelBase'扩展了'GalaSoft.MvvMLight'' ViewModelBase'。它实现了'INotifyPropertyChanged'。 'RaisePropertyChanged'几乎只是调用'if(PropertyChanged!= null)PropertyChanged(this,new PropertyChangedEventArgs(property));' – Luke 2011-05-21 02:44:56
嗯,那么错误*来自哪里?你可以发布完整的堆栈跟踪吗? – 2011-05-21 02:46:50