在 XAML 文件中:
首先,您应该命名您的 TextBlock,例如我给出tbWithNoName
的。
<TextBlock x:Name="tbWithNoName" HorizontalAlignment="Left" TextWrapping="Wrap" Padding="6" VerticalAlignment="Center" Margin="45,0,0,0" Height="30" Width="386" Text="My Program ver. Version"/>
然后在 Window 对象上添加 Loaded 调用。
<Window x:Class="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">
将 Window_Loaded 函数插入到您的 vb 文件中。
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
tbWithNoName.Text = tbWithNoName.Text + " " + Version
End Sub
这将在加载窗口时更改 TextBlock 的文本