标签:
最近在学习win10开发UWP应用的时候遇到了一些问提,记录以作备用。
1. listview可以通过ItemTemplateSelector来给listview显示不同的DataTemplate
一个继承DataTemplateSelector的类,通过重写SelectTemplateCore的方法来指定不同的DataTemplate
2.在DataTemplate里面使用x:bind的时候,必须在DataTemplate那里指定x:DataType,不然编译会报错
3.listview的FooterTemplate和DataTemplate的内容所属的集合不一致,
在赋值的时候,是这样赋值的
//初始化数据,TemplateType=2的那一项是占位项,用来显示画线的那一项 //SpView的那一项是listview的footitem的那一项 public SpliteViewViewModel() { spHelper = new List<SpliteViewHelper>() { new SpliteViewHelper() {SpliteviewName="标题1",groupType=1,SpIcon=new BitmapImage(new Uri("ms-appx:///Assets/LockScreenLogo.scale-200.png")) ,TemplateType=1}, new SpliteViewHelper() {SpliteviewName="标题2",groupType=1,SpIcon=new BitmapImage(new Uri("ms-appx:///Assets/LockScreenLogo.scale-200.png")),TemplateType=1}, new SpliteViewHelper() {SpliteviewName="标题3",groupType=1,SpIcon=new BitmapImage(new Uri("ms-appx:///Assets/LockScreenLogo.scale-200.png")),TemplateType=1}, new SpliteViewHelper() {SpliteviewName="标题1",groupType=1,SpIcon=new BitmapImage(new Uri("ms-appx:///Assets/LockScreenLogo.scale-200.png")),TemplateType=2}, new SpliteViewHelper() {SpliteviewName="标题4",groupType=1,SpIcon=new BitmapImage(new Uri("ms-appx:///Assets/LockScreenLogo.scale-200.png")),TemplateType=1}, new SpliteViewHelper() {SpliteviewName="标题5",groupType=1,SpIcon=new BitmapImage(new Uri("ms-appx:///Assets/LockScreenLogo.scale-200.png")),TemplateType=1}, }; SpView = new SpliteViewHelper() { SpliteviewName = "底部标题", groupType = 1, SpIcon = new BitmapImage(new Uri("ms-appx:///Assets/LockScreenLogo.scale-200.png")), TemplateType = 1 }; }
在前台绑定也是不同的
<ListView x:Name="SplitViewListView" SelectedItem="{Binding spviewmodel.selectitem}" ItemsSource="{Binding spviewmodel.spHelper}" Background="#372127" > <Interactivity:Interaction.Behaviors> <core:EventTriggerBehavior EventName="SelectionChanged"> <core:InvokeCommandAction Command="{Binding spviewmodel.SelectedCommand}" CommandParameter="{Binding ElementName=SplitViewListView,Path=SelectedItem}"/> </core:EventTriggerBehavior> </Interactivity:Interaction.Behaviors> <ListView.ItemTemplateSelector> <com:TemplateSelector LineTemplate="{StaticResource LineTemplate}" NomalTemplate="{StaticResource NomalTemplate}"/> </ListView.ItemTemplateSelector> <ListView.FooterTemplate> <DataTemplate > <StackPanel Orientation="Horizontal" Height="40" x:Name="footItem"> <Interactivity:Interaction.Behaviors> <core:EventTriggerBehavior EventName="Tapped"> <core:InvokeCommandAction Command="{Binding spviewmodel.SelectedCommand}" CommandParameter="{Binding ElementName=footItem}"/> </core:EventTriggerBehavior> </Interactivity:Interaction.Behaviors> <Image Source="{Binding spviewmodel.SpView.SpIcon}" Width="40" Height="40" VerticalAlignment="Center"/> <TextBlock Text="{Binding spviewmodel.SpView.SpliteviewName}" Foreground="White"></TextBlock> </StackPanel> </DataTemplate> </ListView.FooterTemplate> </ListView>
但是为什么绑定Command的时候是找得到同一个Command呢?
还有一个问题listview的FooterTemplate怎么去选中呢
4.UserControl通过 x:FieldModifier来控制访问权限
5.splitview的DisplayMode决定了它的不同显示
最近遇到了很多问题,写的很差,新手勿喷
标签:
原文地址:http://www.cnblogs.com/lj940306/p/4977788.html