summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Pages/ListDataPage.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Pages/ListDataPage.cs')
-rw-r--r--Xamarin.Forms.Pages/ListDataPage.cs55
1 files changed, 55 insertions, 0 deletions
diff --git a/Xamarin.Forms.Pages/ListDataPage.cs b/Xamarin.Forms.Pages/ListDataPage.cs
new file mode 100644
index 00000000..2a2585ec
--- /dev/null
+++ b/Xamarin.Forms.Pages/ListDataPage.cs
@@ -0,0 +1,55 @@
+namespace Xamarin.Forms.Pages
+{
+ public class ListDataPageControl : ListView
+ {
+ public ListDataPageControl()
+ {
+ SetBinding(ItemTemplateProperty, new TemplateBinding(DataPage.DefaultItemTemplateProperty.PropertyName));
+ SetBinding(SelectedItemProperty, new TemplateBinding(ListDataPage.SelectedItemProperty.PropertyName, BindingMode.TwoWay));
+ SetBinding(ItemsSourceProperty, new TemplateBinding(DataPage.DataProperty.PropertyName));
+ }
+ }
+
+ public class ListDataPage : DataPage
+ {
+ public static readonly BindableProperty DetailTemplateProperty = BindableProperty.Create(nameof(DetailTemplate), typeof(DataTemplate), typeof(ListDataPage), null);
+
+ public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create(nameof(SelectedItem), typeof(object), typeof(ListDataPage), null, BindingMode.TwoWay,
+ propertyChanged: OnSelectedItemChanged);
+
+ public DataTemplate DetailTemplate
+ {
+ get { return (DataTemplate)GetValue(DetailTemplateProperty); }
+ set { SetValue(DetailTemplateProperty, value); }
+ }
+
+ public object SelectedItem
+ {
+ get { return GetValue(SelectedItemProperty); }
+ set { SetValue(SelectedItemProperty, value); }
+ }
+
+ static async void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue)
+ {
+ var self = (ListDataPage)bindable;
+ DataTemplate template = self.DetailTemplate;
+ if (newValue == null)
+ return;
+
+ Page detailPage;
+ if (template == null)
+ {
+ detailPage = new DataPage();
+ }
+ else
+ {
+ detailPage = (Page)template.CreateContent(newValue, self);
+ }
+
+ detailPage.BindingContext = newValue;
+ await self.Navigation.PushAsync(detailPage);
+
+ self.SelectedItem = null;
+ }
+ }
+} \ No newline at end of file