我有以下配置:
主窗口.xaml
<Window x:Class="MYNS.MainWindow"
mc:Ignorable="d"
x:Name="mainWindow"
...
主窗口.xaml.cs
public partial class MainWindow : Window
{
public Options Options { get; private set; }
public MainWindow()
{
Options = new Options();
}
}
选项.xaml
class Options
{
public bool QuietMode { get; set; }
public Options()
{
QuietMode = true;
}
}
现在我想将此布尔值绑定到CheckBox另一个窗口的控件,所以我有
选项Windows.xaml
<CheckBox
Content="Quiet Mode"
DataContext="{Binding ElementName=mainWindow, Path=Options}"
IsChecked="{Binding Path=QuietMode}"
/>
我虽然打算这样做,但它不起作用(我尝试了多种类似的方法,但到目前为止都没有奏效)。由于我对 WPF 很陌生,我想我显然在这里遗漏了一些东西。