WPF 前台显示后台定义的变量的值3
发布网友
发布时间:2024-01-21 22:00
我来回答
共1个回答
热心网友
时间:2024-02-13 01:24
给你个例子可以参考下:
前台:
<TextBlock Height="23" Width="100" HorizontalAlignment="Left" Margin="90,92,0,0" Name="textBlock1" Text="{Binding}" VerticalAlignment="Top" />
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="90,139,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
后台:
public partial class Window2 : Window
{
int A = 0;
public Window2()
{
InitializeComponent();
textBlock1.DataContext = A;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
A = 100;
textBlock1.DataContext = A;
}
}