WINDOWS PHONE LISTBOX选用不同的模板.doc
上传人:sy****28 上传时间:2024-09-11 格式:DOC 页数:2 大小:16KB 金币:16 举报 版权申诉
预览加载中,请您耐心等待几秒...

WINDOWS PHONE LISTBOX选用不同的模板.doc

WINDOWSPHONELISTBOX选用不同的模板.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

16 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

本文由麦可网http://www.microoh.com/收集整理,转载请注明出处。WindowsPhoneListBox选用不同的模板第一步:创建两个DataTemplate待用。一个是选中状态的(SelectDataTemplate),一个未选中状态的(NormalDataTemplate)。将它放们放到资源里面。<phone:PhoneApplicationPage.Resources><DataTemplatex:Key="SelectDataTemplate"><BorderBorderThickness="2"BorderBrush="White"><StackPanelOrientation="Horizontal"><TextBlockHorizontalAlignment="Center"VerticalAlignment="Center"Text="{BindingConsumptionName}"FontSize="30"></TextBlock><TextBlockHorizontalAlignment="Center"VerticalAlignment="Center"Text="{BindingConsumptionAmount}"FontSize="30"Margin="10,0,0,0"></TextBlock><Button>Update</Button><Button>Del</Button></StackPanel></Border></DataTemplate><DataTemplatex:Key="NormalDataTemplate"><StackPanelOrientation="Horizontal"><TextBlockHorizontalAlignment="Center"VerticalAlignment="Center"Text="{BindingConsumptionName}"FontSize="30"></TextBlock><TextBlockHorizontalAlignment="Center"VerticalAlignment="Center"Text="{BindingConsumptionAmount}"FontSize="30"Margin="10,0,0,0"></TextBlock></StackPanel></DataTemplate></phone:PhoneApplicationPage.Resources>第二步:用Blend添加一个ListBox到页面里面。在ListBox上面右键->addListBoxItem。第三步:在刚才添加的ListBoxItem上面右键->EditTemplate->EditaCopy。命名为:MyListBoxItemStyle第四步:编辑我们刚才添加的MyListBoxItemStyle。在左下边的ObjectsandTimeline中选中ContentContainer。然后在右边的Properties里面点击ContentTemplate项的右边绿色小方块。在弹出窗口中选择LocalResource->NormalDataTemplate第五步:打开xaml。在刚才添加的MyListBoxItemStyle中找到视觉状态组SelectionStates。在它的下面有一个Selected状态。在这个状态下面有一段代码:<Storyboard><ObjectAnimationUsingKeyFramesStoryboard.TargetProperty="Foreground"Storyboard.TargetName="ContentContainer"><DiscreteObjectKeyFrameKeyTime="0"Value="{StaticResourcePhoneAccentBrush}"/></ObjectAnimationUsingKeyFrames></Storyboard>这是一段动画。代码的意思是将ListBox的选中项(ContentContainer)的前景色(Foreground)换成红色(Value="{StaticResourcePhoneAccentBrush}")。同样的原理,在这段动画再加一段动画,把选中项的模板换掉。<ObjectAnimationUsingKeyFramesStoryboard.TargetProperty="ContentTemplate"Storyboard.TargetName="ContentContainer"><DiscreteObjectKeyFrameKeyTime="0"Value="{StaticReso