Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# RaisePropertyChanged在双向绑定属性上引发StackOverflow异常_C#_Wpf_Data Binding - Fatal编程技术网

C# RaisePropertyChanged在双向绑定属性上引发StackOverflow异常

C# RaisePropertyChanged在双向绑定属性上引发StackOverflow异常,c#,wpf,data-binding,C#,Wpf,Data Binding,因此,我得到了下面的组合框,其中SelectedValue绑定到下面的属性。对于以下绑定,当我设置值时,binding/RaisePropertyChanged组合将引发StackOverflow异常 这是组合框 <ComboBox x:Name="WireType" ItemsSource="{x:Bind ViewModel.WireTypes}" SelectedValue="{x:Bind ViewModel.WireType, Mode=TwoWay}"/> 这是Rais

因此,我得到了下面的组合框,其中SelectedValue绑定到下面的属性。对于以下绑定,当我设置值时,binding/RaisePropertyChanged组合将引发StackOverflow异常

这是组合框

<ComboBox x:Name="WireType" ItemsSource="{x:Bind ViewModel.WireTypes}" SelectedValue="{x:Bind ViewModel.WireType, Mode=TwoWay}"/>
这是RaisePropertyChanged方法

private void RaisePropertyChanged([CallerMemberName] string caller = "")
{
    PropertyChangedEventHandler handler = PropertyChanged;
    if (handler != null)
    {
        handler(this, new PropertyChangedEventArgs(caller));
    }
}
我很肯定我以前做过。我错过了什么?

试试这个

public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged([CallerMemberName] string caller = "")
{
  if (this.PropertyChanged != null)
    this.PropertyChanged(this, new PropertyChangedEventArgs(caller));
}

我的灵能表明
PropertyChanged
事件正在尝试设置属性值

setter应该针对值未更改的情况进行保护。即-

set
{
    if (_wireType != value) // or the appropriate comparison for your specific case
    {
        _wireType = value;
        RaisePropertyChanged();
    }
}

当然,堆栈跟踪将确认实际发生的情况。

(部分)堆栈跟踪可能有用。这对我来说是一个无聊的时刻:)感谢您的快速回复。很有魅力,莫希特。抱歉,我错过了发布活动。我已经有代码了。
set
{
    if (_wireType != value) // or the appropriate comparison for your specific case
    {
        _wireType = value;
        RaisePropertyChanged();
    }
}