我尝试在 WPF 中使用 Prism Unity 在 TextBox 中键入时更新 TextBlock,但它仅在我关闭主窗口时触发,而不是在键入时触发。
View 模型
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 更新?
最佳答案
默认情况下,属性更改仅在焦点更改时触发。
要在您键入时触发,请更改:
<TextBox Text="{Binding TextName}">
</TextBox>
...到:
<TextBox Text="{Binding TextName,
UpdateSourceTrigger=PropertyChanged}">
</TextBox>
关于c# - 在 WPF 中使用 Unity Prism 在 TextBox 中键入时实时更新 TextBlock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52494946/