public LoggListPage(Jakt jakt) { Title = "Loggføringer"; PositionActivityIndicator = new ActivityIndicator(); BindingContext = VM = new JaktVM(jakt); ToolbarItems.Add(new ToolbarItem("Ny logg", null, () => { var logg = VM.CreateLogg(); Navigation.PushAsync(new LoggPage(logg), true); }, ToolbarItemOrder.Primary)); if (VM.IsNew) { TryGetPosition(); } }
public void Init() { VM.BindData(); var editJaktBtn = new Image() { Source = "more.png", HeightRequest = 40, WidthRequest = 40, HorizontalOptions = LayoutOptions.EndAndExpand }; var dateLabel = new Label() { FontSize = 12 }; var titleLabel = new Label() { FontSize = 16 }; var circleImage = new CircleImage() { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Start, BorderThickness = 2, BorderColor = Color.White, HeightRequest = 70, WidthRequest = 70, Aspect = Aspect.AspectFill }; var headerTextLayout = new StackLayout() { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.StartAndExpand, Children = { dateLabel, titleLabel } }; dateLabel.SetBinding(Label.TextProperty, new Binding("CurrentJakt.DatoFraTil")); titleLabel.SetBinding(Label.TextProperty, new Binding("CurrentJakt.Title")); circleImage.SetBinding(CircleImage.SourceProperty, new Binding("CurrentJakt.Image")); headerTextLayout.SetBinding(StackLayout.IsVisibleProperty, new Binding("IsLoadingPosition", converter: new InverseBooleanConverter())); PositionActivityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, new Binding("IsLoadingPosition")); var jaktSummary = new StackLayout() { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Fill, Padding = 5, GestureRecognizers = { new TapGestureRecognizer { Command = new Command(() => Navigation.PushAsync(new JaktPage(VM.CurrentJakt))), }, }, Children = { circleImage, headerTextLayout, PositionActivityIndicator, editJaktBtn } }; ListView lv = new ListView(); lv.HorizontalOptions = LayoutOptions.FillAndExpand; lv.VerticalOptions = LayoutOptions.FillAndExpand; lv.SetBinding(ListView.ItemsSourceProperty, new Binding("ItemCollection")); lv.ItemSelected += (sender, e) => { if (e.SelectedItem != null) { Navigation.PushAsync(new LoggPage((Logg)e.SelectedItem), true); ((ListView)sender).SelectedItem = null; } }; //Remember to remove this event handler on dispoing of the page; DataTemplate dt = new DataTemplate(typeof(CircleImageCell)); dt.SetBinding(CircleImageCell.TextProperty, new Binding("Title")); dt.SetBinding(CircleImageCell.DetailProperty, new Binding("Details")); dt.SetBinding(CircleImageCell.ImageSourceProperty, new Binding("Image")); lv.ItemTemplate = dt; if (VM.ItemCollection.Any()) { Content = new StackLayout() { Padding = 5, Children = { jaktSummary, lv } }; } else { var btn = new Button() { Text = "Opprett første loggføring", BackgroundColor = Color.FromHex("#74B058") }; btn.Clicked += delegate(object sender, EventArgs args) { var logg = VM.CreateLogg(); Navigation.PushAsync(new LoggPage(logg), true); }; Content = new StackLayout() { Children = { jaktSummary, btn } }; } }