Inheritance: INotifyPropertyChanged
Ejemplo n.º 1
0
        /// <summary>
        /// Method that creates the page content
        /// </summary>
        public void SetContent()
        {
            var header = new Label
            {
                Text = "Vælg Takst",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
            };
            
            var backButton = new BackButton(SendBackMessage);
            // filler to make header is centered
            var filler = new Filler();
            // they need to be the same size.
            backButton.WidthRequest = backButton.WidthRequest - 40;
            filler.WidthRequest = backButton.WidthRequest;

            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    backButton,
                    header,
                    filler
                }
            };

            var list = new ListView
            {
                ItemTemplate = new DataTemplate(typeof(GenericCell)),
                SeparatorColor = Color.FromHex("#EE2D2D"),
                SeparatorVisibility = SeparatorVisibility.Default,
            };
            list.SetBinding(ListView.ItemsSourceProperty, TaxViewModel.TaxListProperty, BindingMode.TwoWay);

            list.ItemSelected += (sender, args) =>
            {
                var item = (GenericCellModel) args.SelectedItem;

                if (item == null) return;
                item.Selected = true;
                Selected = item;
                SendSelectedMessage();
            };

            var layout = new StackLayout
            {
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
            };


            layout.Children.Add(headerstack);
            layout.Children.Add(list);

            this.Content = layout;
        }
        /// <summary>
        /// Method that creates the page layout and sets the page content, to that layout
        /// </summary>
        public void SetContent()
        {
            var header = new Label
            {
                Text = "Vælg Formål",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
            };
            
            var addButton = new AddButton(SendAddMessage);
            var backButton = new BackButton(SendBackMessage);

            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    backButton,
                    header,
                    addButton
                }
            };

            var list = new ListView
            {
                ItemTemplate = new DataTemplate(typeof(GenericCell)),
                SeparatorColor = Color.FromHex("#EE2D2D"),
                SeparatorVisibility = SeparatorVisibility.Default,
            };
            list.SetBinding(ListView.ItemsSourceProperty, PurposeViewModel.PurposeListProperty, BindingMode.TwoWay);
            list.GestureRecognizers.Add(new TapGestureRecognizer
            {
                NumberOfTapsRequired = 2,
                Command = new Command((o) =>
                {
                    if (list.SelectedItem != null)
                    {
                        SendDeleteMessage();
                    }
                })
            });

            list.ItemSelected += (sender, args) =>
            {
                var item = (GenericCellModel) args.SelectedItem;

                if (item == null) return;
                item.Selected = true;
                Selected = item;
                SendSelectedMessage();
            };

            var layout = new StackLayout
            {
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
            };

            var entry = new Entry
            {
                Placeholder = _placeholder,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
            };
            entry.SetBinding(Entry.TextProperty, PurposeViewModel.PurposeStringProperty);

            var addPurpose = new Button
            {
                Text = "Tilføj",
                BorderColor = Color.FromHex(Definitions.PrimaryColor),
                TextColor = Color.FromHex(Definitions.TextColor),
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions = LayoutOptions.Center,
                AnchorY = (double)TextAlignment.Center,
                FontSize = 20,
                
            };
            addPurpose.SetBinding(Button.CommandProperty, PurposeViewModel.AddPurposeCommand);

            var addStack = new StackLayout
            {
                Padding = new Thickness(Definitions.Padding, 0, Definitions.Padding, 0),
                Spacing = Definitions.Padding,
                Orientation = StackOrientation.Horizontal,
                Children =
                {
                    entry,
                    addPurpose
                }
            };
            addStack.SetBinding(StackLayout.IsVisibleProperty, PurposeViewModel.HideFieldProperty);

            var textlabel = new Label
            { 
                Text = "Dobbelt tryk for at slette formål",
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                Opacity = 0.6,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.End,
            };

            layout.Children.Add(headerstack);
            layout.Children.Add(addStack);
            layout.Children.Add(list);
            layout.Children.Add((textlabel));

            this.Content = layout;

        }
 /// <summary>
 /// Method that handles the Delete message
 /// </summary>
 private void HandleDeleteMessage(GenericCellModel str)
 {
     _purposes.Remove(str);
     PurposeList = _purposes;
     Definitions.Purpose = null;
     FileHandler.WriteFileContent(Definitions.PurposeFileName, Definitions.PurposeFolderName,
         JsonConvert.SerializeObject(_purposes)).ContinueWith(
             result =>
             {
                 InitializeCollection();
             }, TaskScheduler.FromCurrentSynchronizationContext());
 }
        /// <summary>
        /// Method that creates a layout for the page and sets it as the page content
        /// </summary>
        public void SetContent()
        {
            var header = new Label
            {
                // View title
                Text = "Vælg Organisatorisk Placering",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize - 13,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
            };
            
            // Backbutton
            var backButton = new BackButton(SendBackMessage);
            var filler = new Filler();

            backButton.WidthRequest = backButton.WidthRequest - 40;
            filler.WidthRequest = backButton.WidthRequest;

            // Navigation Bar
            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    backButton,
                    header,
                    filler
                }
            };

            // Item List
            var list = new ListView
            {
                ItemTemplate = new DataTemplate(typeof(GenericCell)),
                SeparatorColor = Color.FromHex("#000000"),
                SeparatorVisibility = SeparatorVisibility.Default,
            };
            list.SetBinding(ListView.ItemsSourceProperty, OrganizationViewModel.OrganizationListProperty, BindingMode.TwoWay);

            list.ItemSelected += (sender, args) =>
            {
                var item = (GenericCellModel) args.SelectedItem;

                if (item == null) return;
                item.Selected = true;
                Selected = item;
                SendSelectedMessage();
            };

            var layout = new StackLayout
            {
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
            };


            layout.Children.Add(headerstack);
            layout.Children.Add(list);
            
            this.Content = layout;

        }