我正在尝试在 WPF 中使用 Prism Unity 在 TextBox 中输入时更新 TextBlock,但它仅在我关闭主窗口时触发,而不是在输入时触发。
private string _textName = "text";
public string TextName
{
get { return _textName; }
set
{
_textName = value;
RaisePropertyChanged(nameof(TextName));
}
}
Run Code Online (Sandbox Code Playgroud)
<StackPanel>
<TextBlock Text="{Binding TextName}" FontSize="30"></TextBlock>
<TextBox Text="{Binding TextName}"></TextBox>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
如何在不实现 event_handler 的情况下在 TextBox 中键入时实时获取 TextBlock 更新?
默认情况下,属性更改仅在焦点更改时触发。
要在键入时触发,请更改:
<TextBox Text="{Binding TextName}">
</TextBox>
Run Code Online (Sandbox Code Playgroud)
...到:
<TextBox Text="{Binding TextName,
UpdateSourceTrigger=PropertyChanged}">
</TextBox>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
406 次 |
| 最近记录: |