I'm trying to build a bingo game simulator using WPF to learn more about WPF, and I'm having trouble figuring out how to change an <ItemsControl>
template programmatically.
I'm only using the default WPF Application from VS 2010, so I have a MainWindow.xaml, App.xaml and MainWindow.xaml.cs.
The reason I want to access the <ItemTemplate>
, is to change the bound template if that bingo number comes up as chosen.
I've tried this possible solution in my code behind file, but I don't think that works in this situation.
Here is how I have my MainWindow and App xaml files set up
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>