In MainWindow.xaml 我
...
<TextBlock x:Name="tbCpu" Text="{Binding Path=activeTower.cpuTotal}" />
...
以及Main Window.xaml.cs 我
public partial class MainWindow : Window
{
Tower activeTower
public MainWindow()
{
activeTower = Tower();
activeTower.cpuTotal = 500;
tbCpu.DataContext = this;
}
}
The code compiles and runs fine, without any errors. However, tbCpu stays empty. Tower is a custom class that has a property cpuTotal that returns a double, but I have tried other properties in the same class that return a string and it still doesn t work. What am I doing wrong here?