<Window x:Class="wpfdemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"> <Grid Name="grid1" > <TextBlock Name="txt1" Text="{Binding}" Width="150" Height="30" /> </Grid> public partial class MainWindow : Window { private string name; public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { name = "Button"; grid1.DataContext = name; } } </Window>
可以
110,536
社区成员
642,578
社区内容
加载中
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧