首页 > 代码库 > wpf中如何在xaml中绑定cs中类的属性

wpf中如何在xaml中绑定cs中类的属性

cs代码:
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ContentGrid.DataContext = this;
this.Path = "数据绑定";
}

public string Path { get; set; }
}
XAML代码:
<Grid x:Name="ContentGrid">
<TextBlock Text="{Binding Path}"></TextBlock>
</Grid>