无法显示变量wpf xaml c#

jv4diomz  于 2022-12-07  发布在  C#
关注(0)|答案(1)|浏览(195)

我试图显示一个可能随时间变化的变量,我尝试了这个:
第一个
The variable result is supposed to be displayed here but instead there is a blank
我尝试了所有能找到的显示变量的方法

ddrv8njm

ddrv8njm1#

尝试将UpdateSourceTrigger设置为PropertyChanged:

<TextBlock Text= "{Binding myText, ElementName=windowElement, UpdateSourceTrigger=PropertyChanged}" />
   <TextBox Text="{Binding Buffer, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>

并实现INotifyPropertyChanged:

public string myText 
 {
     get; 
     set
     {
        RaisePropertyChanged(myText);
     }
 }
 public void test()
 {
      myText = " testttttttttttttttttttt";
 }

public new event PropertyChangedEventHandler? PropertyChanged;

protected virtual void RaisePropertyChanged([CallerMemberName] string? propertyName = null)
{
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

编辑:
我们遇到了问题。在WPF中,您需要有一个页面(Diag_Prog.xaml)和一个自动连接的代码隐藏文件(Diag_Prog.xaml.cs)。只需向您的项目中添加一个页面:

在Visual Studio中,它应该如下所示:

相关问题