WPF:如何修改标签?

WPF:如何修改标签?,wpf,wpf-controls,Wpf,Wpf Controls,在my Main Window.xaml中,我有: <Window x:Class="UnionPayExhangeRate3.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Union Pay Exchange Rate" Height

在my Main Window.xaml中,我有:

<Window x:Class="UnionPayExhangeRate3.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Union Pay Exchange Rate" Height="350" Width="525">

<Grid>
    <Label Content="" HorizontalAlignment="Left" Margin="10,64,0,0" VerticalAlignment="Top" Width="497"/>
</Grid>

</Window>

我看不到任何识别标签的方法,所以我必须为标签设置一个id并以某种方式调用它吗?

Name
属性添加到您的
标签中

<Label x:Name="myLabel" Content="" HorizontalAlignment="Left" Margin="10,64,0,0" VerticalAlignment="Top" Width="497"/>

设置标签的
name
属性。然后你可以在代码隐藏中访问它。谢谢,它可以工作!你是西方最快的枪。看一下WPF的101……这是最基本的……我试过寻找答案,但没用。此问题不存在这样的101:(不应该是:mainWindow.myLabel.Content=“Hello World”?)?
<Label x:Name="myLabel" Content="" HorizontalAlignment="Left" Margin="10,64,0,0" VerticalAlignment="Top" Width="497"/>
 protected override void OnStartup(StartupEventArgs e)
 {
        base.OnStartup(e);
        MainWindow mainWindow = new MainWindow();
        mainWindow.Show();  
        //Change the label in MainWindow              
        mainWindow.myLabel.Content = "Hello World";
 }