链接文本框到属性



我不能在c#中链接我的文本框到我的属性。当我编写并按下按钮时,我必须发送请求,但问题是,当我的文本框为空时,我不能给它用户输入的值。

In my view-model

class ViewModel : INotifyPropertyChanged
{
private string textePartieA;
public string TextePartieA
{
get { return textePartieA; }
set
{
textePartieA = value;
OnPropertyChanged("TextePartieA"); 
if (!(textePartieA is null))
TextToSpeech(apikeyTextToSpeech, urlTextToSpeech);
}
}

在我看来:

<TextBox x:Name="TextePartieA" Margin="5" MinHeight="85" Grid.ColumnSpan="3" 
Text="{Binding TextePartieA, Mode=TwoWay}"></TextBox>

你也应该将viewModel绑定到你的DataContext:

public class MyWindow : Window {
public MyWindow() {
var viewModel = new ViewModel();

DataContext = viewModel;
InitializeComponents();

}

}

最新更新