【问题标题】:Update TextBlock in real time while typing in TextBox using Unity Prism in WPF在 WPF 中使用 Unity Prism 在 TextBox 中输入时实时更新 TextBlock
【发布时间】:2018-09-25 09:34:35
【问题描述】:

我正在尝试在 WPF 中使用 Prism Unity 输入 TextBox 时更新 TextBlock,但它只会在我关闭主窗口时触发,而不是在输入时触发。

视图模型

private string _textName = "text";

public string TextName
{
    get { return _textName; }
    set
    {
        _textName = value;
        RaisePropertyChanged(nameof(TextName));
    }
}

查看

<StackPanel>
     <TextBlock Text="{Binding TextName}" FontSize="30"></TextBlock>
     <TextBox Text="{Binding TextName}"></TextBox>
</StackPanel>

如何在不实现 event_handler 的情况下在 TextBox 中输入时实时获取 TextBlock 更新?

【问题讨论】:

    标签: c# wpf mvvm prism


    【解决方案1】:

    默认情况下,属性更改仅在焦点更改时触发。

    要在键入时触发,请更改:

     <TextBox Text="{Binding TextName}">
     </TextBox>
    

    ...到:

     <TextBox Text="{Binding TextName, 
                     UpdateSourceTrigger=PropertyChanged}">
     </TextBox>
    

    【讨论】:

      猜你喜欢
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-12
      • 1970-01-01
      相关资源
      最近更新 更多