【发布时间】:2016-03-26 20:49:23
【问题描述】:
我正在尝试使用 9x9 网格制作数独,但是为了获得干净的代码,我正在尝试使用字典。编写下面给出的代码后,预览实现了 9x9 网格。但是,每当我启动应用程序时,我都没有得到相同的结果,我只会得到最后加载的网格。
这是具有以下网格元素的字典:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Key="GridTemplate" ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" ></Label>
<Label Grid.Column="0" Grid.Row="1" ></Label>
<Label Grid.Column="0" Grid.Row="2" ></Label>
<Label Grid.Column="1" Grid.Row="0" ></Label>
<Label Grid.Column="1" Grid.Row="1" ></Label>
<Label Grid.Column="1" Grid.Row="2" ></Label>
<Label Grid.Column="2" Grid.Row="0" ></Label>
<Label Grid.Column="2" Grid.Row="1" ></Label>
<Label Grid.Column="2" Grid.Row="2" ></Label>
</Grid>
现在我正在尝试使用这个 9 次到另一个网格到这个窗口中
<Window x:Class="SudokuWPF.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">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="GridDictonary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ContentControl Content="{StaticResource GridTemplate}" Grid.Column="0" Grid.Row="0" />
<ContentControl Content="{StaticResource GridTemplate}" Grid.Column="0" Grid.Row="1" />
<ContentControl Content="{StaticResource GridTemplate}" Grid.Column="0" Grid.Row="2" />
<ContentControl Content="{StaticResource GridTemplate}" Grid.Column="1" Grid.Row="0" />
<ContentControl Content="{StaticResource GridTemplate}" Grid.Column="1" Grid.Row="1" />
<ContentControl Content="{StaticResource GridTemplate}" Grid.Column="1" Grid.Row="2" />
<ContentControl Content="{StaticResource GridTemplate}" Grid.Column="2" Grid.Row="0" />
<ContentControl Content="{StaticResource GridTemplate}" Grid.Column="2" Grid.Row="1" />
<ContentControl Content="{StaticResource GridTemplate}" Grid.Column="2" Grid.Row="2" />
</Grid>
我希望能解决这个问题,因为我没有选择:(
【问题讨论】:
标签: c# .net wpf xaml dictionary