首页 > 技术文章 > xamarin开发UWP元素的初始化设置顺序

zuimengaitianya 2016-11-29 09:43 原文

     在开发xamarin的UWP平台不可避免的遇到一下坑,现记录下来,希望对后面踩坑有帮助。

     一、listview的分组问题:当我们使用listview的IsGroupingEnabled=true时,如果你采用如下代码写分组的头代码的话,那这个DataTemplate将不起作用。

list = new ListView(ListViewCachingStrategy.RecycleElement)
            {
                IsGroupingEnabled = true,
                GroupDisplayBinding = new Binding("Key", BindingMode.OneWay, new HanderTextConverter()),
                //注意这里设置的模板将不起作用,
                GroupHeaderTemplate = new DataTemplate(typeof(BorwseHanderCell))
                //GroupShortNameBinding = new Binding("Key"),
                SeparatorColor = Color.White,
                BackgroundColor = Color.White,
                VerticalOptions = LayoutOptions.FillAndExpand,
                //HasUnevenRows = true,
            };

需要在初始化后在设置GroupHeaderTemplate的模板

 1 list = new ListView(ListViewCachingStrategy.RecycleElement)
 2             {
 3                 IsGroupingEnabled = true,
 4                 GroupDisplayBinding = new Binding("Key", BindingMode.OneWay, new HanderTextConverter()),
 5                 //GroupShortNameBinding = new Binding("Key"),
 6                 SeparatorColor = Color.White,
 7                 BackgroundColor = Color.White,
 8                 VerticalOptions = LayoutOptions.FillAndExpand,
 9                 //HasUnevenRows = true,
10             };
11 
12 list.GroupHeaderTemplate = new DataTemplate(typeof(BorwseHanderCell));

同时那个GroupDisplayBinding也是没有效果的。

 

    二、MasterDetailPage的Detail页的Title问题。

    如果你使用了this.Detail.BindingContext = lst[0]这样的方式绑定Mastpage和Detailpage的内容交互的话,如果你想更改Detail页的Title那需要如下设置,注意代码的顺序,搞错顺序将无效:

1 listView.ItemsSource = mailFolederList;
2                             mailFolederList[0].IsSelected = true;
3                             this.Detail.BindingContext = lst[0];
4                             this.Detail.Title = lst[0].FolderName;
5                             this.Title = “我是更改的Title”;
6                             this.IsPresented = false;

 

推荐阅读