【问题标题】:update source trigger of one control should effect the other control一个控件的更新源触发器应该影响另一个控件
【发布时间】:2018-06-05 10:40:44
【问题描述】:

我正在为数据网格使用第三方控件。我已经在模型类中实现了属性更改事件,并且在我使用时它正在工作

 Text="{Binding itemQty, UpdateSourceTrigger=propertychanged}"

它甚至在我的数据源中更新,但我有另一个文本框,尽管项目源已更新为新值,但数据并未从项目源中检索。 我想显示带有第一个文本框的属性更改事件的数据,并且行是动态的,所以我不能直接调用它们。 如果我刷新它正在显示的数据源,但我不能使用该过程,因为当项目很多时,这是一个耗时的过程。

【问题讨论】:

  • 如果答案已经解决了您的问题,请mark 方便以后访问此主题的人接受,感谢您的理解。

标签: c# uwp uwp-xaml updatesourcetrigger


【解决方案1】:

我想显示具有第一个文本框的属性更改事件的数据,并且行是动态的

问题是您没有为您的Text 属性设置Mode=TwoWay。而UpdateSourceTrigger 定义了一些常量,这些常量指示绑定源何时被双向绑定中的绑定目标更新。

<TextBox Text="{Binding Info,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
<TextBox Text="{Binding Info}"/>

背后的代码

private string info { get; set; }
public string Info
{
    get { return info; }
    set
    {
        info = value;
        OnPropertyChanged();
    }
}

public event PropertyChangedEventHandler PropertyChanged;

private void OnPropertyChanged([CallerMemberName] string properName = null)
{
    if(PropertyChanged != null)
    this.PropertyChanged(this,new PropertyChangedEventArgs(properName));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    相关资源
    最近更新 更多