- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以我得到了以下组合框,其中 SelectedValue 绑定(bind)到下面的属性。对于以下绑定(bind),当我设置值时,绑定(bind)/RaisePropertyChanged 组合会抛出 StackOverflow 异常。
这是组合框
<ComboBox x:Name="WireType" ItemsSource="{x:Bind ViewModel.WireTypes}" SelectedValue="{x:Bind ViewModel.WireType, Mode=TwoWay}"/>
这是属性
public string WireType
{
get
{
return _wireType;
}
set
{
_wireType = value;
RaisePropertyChanged();
}
}
这里是 RaisePropertyChanged 方法。
private void RaisePropertyChanged([CallerMemberName] string caller = "")
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(caller));
}
}
我很确定我以前做过这个。我错过了什么?
最佳答案
我的灵能表明 PropertyChanged
事件正在尝试设置属性值。
setter 应该防止值未更改的情况。即-
set
{
if (_wireType != value) // or the appropriate comparison for your specific case
{
_wireType = value;
RaisePropertyChanged();
}
}
当然,堆栈跟踪可以确认实际发生了什么。
关于c# - RaisePropertyChanged 在双向绑定(bind)属性上抛出 StackOverflow 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32469667/
我不确定为什么要使用 RaisePropertyChanging , 当通知 View fx: private LoggingLvl _myLoggingLvl; public Loggin
在这里,我向我的 View 模型添加了一个模型: public dal.UserAccount User { get { return _user; } set {
我已经将 MVVM 与我的 WPF 应用程序一起使用了一段时间,但是我试图让一个按钮保持禁用状态,直到它可以启用为止。没问题,我将在 ViewModel 中创建一个 bool 并将其绑定(bind)到
我有一个按钮,其内容与 ViewModel 的名为 Test 的属性绑定(bind)。 单击按钮时,我正在更改其内容 private void button1_Click(object sender
我有一个模型用户: public class User { public string Name { get; set; } public int Level { get; set;
为了在通用应用程序中获取 MvvmCross PropertyChanged 事件,我必须设置 ShouldAlwaysRaiseInpcOnUserInterfaceThread(false)。你能
我在模型类的 IDataErrorInfo 的实现部分中编写了此代码,以便在清除错误后清除错误。 我不明白这里用空字符串引发了哪个属性刷新? if (raiseNotification)
我有以下用于单选按钮绑定(bind)的类 public class RadioButtonSwitch : ViewModelBase { IDictionary _optio
我无法在 View Model 的 SET 属性中定位断点,因此默认值未更改。 (Get - 没问题,它用有效的默认值初始化我的文本框。) 我有一个model.cs定义公共(public)字符串字
如果我想通过 RaisePropertyChanged 更新我的 UI,我会遇到一个奇怪的行为。我使用 this post 的第二个解决方案(由 Johnathan1 提供) :我实现了 RadioB
我正在使用 mvvm-light,我注意到有关 RaisePropertyChanged 的这种奇怪行为。 xaml: 可观察类: public class A : ObservableObj
根据 MSDN doc on PropertyChanged ,如果将空字符串传递给该方法,则会刷新所有属性。使用MvvmLight RaisePropertyChanged 时有这样的事情吗?传递
我目前正在学习 MVVM,我不明白 RaisePropertyChanged 有多重要 例如这个函数: public City SelectedCity { get {
我在 Windows Phone Silverlight 应用程序中使用 MVVM Light。 我真的不明白 RaisePropertyChanged 应该如何工作;让我解释一下,用这样的代码 pr
我正在寻找一种解决方案,以在其中一个内部属性发生变化时触发整个属性的 PropertyChanged。所以这是模型: public class MainStatus : ObservableObjec
由于某种原因,我无法让 UI 响应 RaisePropertyChanged。卡住了。 CurrentClient 是不向 UI 触发的部分。真的很奇怪。 希望有人可以帮助我。谢谢斯科特 public
我有 public override bool RelatedProperty { get { return this.SomeProperty > 0; }
NotificationObject 中此方法有一个重载:- protected void RaisePropertyChanged(Expression> propertyExpression);
当我的 ViewModel 更改时,我无法让我的 UI 更新两个列表框以正确更新。 首先,页面背后的基本逻辑: Movie 是一个带有标题的对象,以及各种MovieDetails。一些 MovieDe
我有一个类似于此的属性: private ISomething currentSomething; public ISomething CurrentSomething {
我是一名优秀的程序员,十分优秀!