访问UniformGrid ItemTemplate中编程 [英] Access UniformGrid ItemTemplate programmatically

查看:353
本文介绍了访问UniformGrid ItemTemplate中编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用WPF更多地了解WPF打造宾果游戏模拟器,和我有麻烦搞清楚如何改变< ItemsControl的> 模板编程。



我只使用从2010年VS默认的WPF应用程序,所以我有一个MainWindow.xaml,App.xaml中和MainWindow.xaml.cs。



我要访问的<的原因; ItemTemplate中> ,是改变绑定的模板,如果是宾果数字来作为最高选择。



我试过这种可能的解决方案在隐藏文件我的代码,但我不认为在这种情况下工作。



下面是我有我的主窗口和XAML应用程序文件中设置了



MainWindow.xaml



 < ItemsControl的名称= icBColumn的ItemsSource ={结合CardBNumbers}
Grid.Column =0Grid.Row =2
的ItemTemplate ={StaticResource的BingoSquare}
ItemsPanel ={StaticResource的BingoColumn}>



的App.xaml



 <的DataTemplate X:键=BingoSquare> 
<边框背景={DynamicResource UnmarkedSquare}>
<标签内容={结合}/>
< /边框>
< / DataTemplate中>
<放射X:键=UnmarkedSquare渐变=0.5,0.5
中心=0.5,0.5半径=0.5半径=0.5>
< RadialGradientBrush.GradientStops>
<渐变停止颜色=暗绿偏移量=1/>
< /RadialGradientBrush.GradientStops>
< /&画笔GT;
< ItemsPanelTemplate X:键=BingoColumn>
< UniformGrid NAME =NumbersGrid列=1行=10/>
< / ItemsPanelTemplate>


解决方案

勾选此的链接那里你会找到的代码是足够接近你所需要的,但需要一些工作。



我会提出一些修复重建。



例如,你绑定你的ItemsControl的的ItemsSource到CardBNumbers。它是一个int列表或CustomClass例如列表BingoNumClass。如果它是一个自定义类添加您将通过defualt变成假的布尔IsBingo布尔属性。每当选择了宾果数字将转向从你的代码真的,你会更新CardBNumbers列表中的项目。



然后,你可以与IsBingo物业Datatriggers延长你的ItemTemplate尽快被选中Chnage其appearrence - 转向真正从CardBNumbers列表


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>

解决方案

Check this link there you will find code that is close enough to what you need but needs some work.

I would propose some recontruction.

For example you bind your ItemsControl's ItemsSource to CardBNumbers. Is it a list of int or a list of CustomClass e.g. BingoNumClass. If it is a custom class the add a boolean IsBingo boolean property which you will by defualt turn to false. It will turn to true from your code whenever a bingo number is selected and you will update the items of CardBNumbers list.

Then you could extend your ItemTemplate with Datatriggers on IsBingo Property to Chnage its appearrence as soon as it is selected - turned to true from your CardBNumbers list.

这篇关于访问UniformGrid ItemTemplate中编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆