我正在尝试将MainWindow.xaml中的int变量传递给UserControl.当我重新调试myGridSize总是等于零.我将不胜感激任何帮助.
x:Name="myWindow">
<Grid>
<my:SudokuGrid x:Name="mySudokuGrid" myGridSize="{Binding SudokuSize, ElementName=myWindow}">
</my:SudokuGrid>
</Grid>
Run Code Online (Sandbox Code Playgroud)
public static readonly DependencyProperty SudokuSizeProperty =
DependencyProperty.Register("SudokuSize", typeof(int), typeof(MainWindow), new FrameworkPropertyMetadata(null));
private int SudokuSize
{
get { return (int)GetValue(SudokuSizeProperty); }
set { SetValue(SudokuSizeProperty, value); }
}
public MainWindow()
{
SudokuSize = 9;
InitializeComponent();
}
Run Code Online (Sandbox Code Playgroud)
x:Name="gridCustom">
<UniformGrid Name="SudokuUniGrid" Style="{StaticResource CustomGridStyle}">
</UniformGrid>
Run Code Online (Sandbox Code Playgroud)
public static readonly DependencyProperty myGridSizeProperty =
DependencyProperty.Register("myGridSize", typeof(int), typeof(SudokuGrid), new FrameworkPropertyMetadata(null));
public int myGridSize
{
get { return (int)GetValue(myGridSizeProperty); }
set { SetValue(myGridSizeProperty, value); }
} …Run Code Online (Sandbox Code Playgroud)