【发布时间】:2012-12-26 06:54:12
【问题描述】:
我正在尝试使用 WPF 构建一个宾果游戏模拟器以了解有关 WPF 的更多信息,但我无法弄清楚如何以编程方式更改 <ItemsControl> 模板。
我只使用 VS 2010 的默认 WPF 应用程序,所以我有 MainWindow.xaml、App.xaml 和 MainWindow.xaml.cs。
我想访问<ItemTemplate> 的原因是,如果选择的宾果号码出现,则更改绑定模板。
我已经在我的代码隐藏文件中尝试了this possible solution,但我认为这不适用于这种情况。
这是我设置 MainWindow 和 App xaml 文件的方式
MainWindow.xaml
<ItemsControl Name="icBColumn" ItemsSource="{Binding CardBNumbers}"
Grid.Column="0" Grid.Row="2"
ItemTemplate="{StaticResource BingoSquare}"
ItemsPanel="{StaticResource BingoColumn}">
App.xaml
<DataTemplate x:Key="BingoSquare">
<Border Background="{DynamicResource UnmarkedSquare}">
<Label Content="{Binding}" />
</Border>
</DataTemplate>
<RadialGradientBrush x:Key="UnmarkedSquare" GradientOrigin="0.5,0.5"
Center="0.5,0.5" RadiusX="0.5" RadiusY="0.5">
<RadialGradientBrush.GradientStops>
<GradientStop Color="LimeGreen" Offset="1" />
</RadialGradientBrush.GradientStops>
</RadialGradientBrush>
<ItemsPanelTemplate x:Key="BingoColumn">
<UniformGrid Name="NumbersGrid" Columns="1" Rows="5"/>
</ItemsPanelTemplate>
【问题讨论】:
标签: c# wpf datatemplate itemscontrol