【发布时间】:2021-12-18 16:04:06
【问题描述】:
您好,我想通过后面的代码设置文本框的 Text 属性。目前我使用 XAML:
<TextBox x:Name="txtFilter" Text="{Binding FiltroFunzioni, Mode=OneWayToSource}" Grid.Row="0" />
作为测试,我这样做了:
Binding b = new Binding();
b.Mode = BindingMode.OneWayToSource;
b.Path = new PropertyPath("Text"); //??
b.Source = PageViewModel.FiltroFunzioni;
BindingOperations.SetBinding(txtFilter, TextBlock.TextProperty, b);
变量“FiltroFunzioni”是一个定义为属性的字符串:
private string _filtroFunzioni = "";
public string FiltroFunzioni
{
get { return _filtroFunzioni; }
set
{
_filtroFunzioni = value;
RaisePropertyChanged("FiltroFunzioni");
_functionsView.Refresh();
}
}
基本上我不知道我应该将什么样的值设置为 PropertyPath。有什么想法吗?
【问题讨论】: