Beispiel #1
0
        public MessagePage()
        {
            MessageViewModel = new MessagePageViewModel();

            this.InitializeComponent();
            this.Loaded += MessagePage_Loaded;

            // Always use the cached page
            // this.NavigationCacheMode = NavigationCacheMode.Required;
        }
Beispiel #2
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     if (model == null)
     {
         model           = new MessagePageViewModel();
         model.MessageId = Convert.ToInt32(NavigationContext.QueryString["id"]);
         DataContext     = model;
         LoadMessage();
     }
 }
        /// <summary>
        ///     Populates the page with content passed during navigation.  Any saved state is also
        ///     provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        ///     The source of the event; typically <see cref="NavigationHelper" />
        /// </param>
        /// <param name="e">
        ///     Event data that provides both the navigation parameter passed to
        ///     <see cref="Frame.Navigate(Type, Object)" /> when this page was initially requested and
        ///     a dictionary of state preserved by this page during an earlier
        ///     session.  The state will be null the first time a page is visited.
        /// </param>
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            _vm = (MessagePageViewModel)DataContext;

            if (e.PageState != null && e.PageState.ContainsKey("userEntity") && App.UserAccountEntity == null)
            {
                string savedStateJson = e.PageState["userAccountEntity"].ToString();
                App.UserAccountEntity = JsonConvert.DeserializeObject <UserAccountEntity>(savedStateJson);
                savedStateJson        = e.PageState["userEntity"].ToString();
                _user = JsonConvert.DeserializeObject <UserAccountEntity.User>(savedStateJson);
                App.UserAccountEntity.SetUserEntity(_user);
            }
            var jsonObjectString = (string)e.NavigationParameter;

            _messageGroup = JsonConvert.DeserializeObject <MessageGroupEntity.MessageGroup>(jsonObjectString);
            _vm.SetMessages(_messageGroup.MessageGroupId, App.UserAccountEntity);
        }
Beispiel #4
0
 public MessagePage(MessagePageViewModel ViewModel)
 {
     InitializeComponent();
     this.BindingContext = ViewModel;
 }
Beispiel #5
0
        public MessagePage()
        {
            Title = "Monkey Chat";
            var _messagePageViewModel = new MessagePageViewModel();
            var MessagesListView      = new ListView()
            {
                BackgroundColor     = Color.White,
                VerticalOptions     = LayoutOptions.FillAndExpand,
                HorizontalOptions   = LayoutOptions.FillAndExpand,
                ItemTemplate        = new MyDataTemplateSelector(),
                ItemsSource         = _messagePageViewModel.Messages,
                HasUnevenRows       = true,
                SeparatorVisibility = SeparatorVisibility.None,
                //SelectedItem = ""
            };

            var MessageEntry = new Entry()
            {
                Keyboard          = Keyboard.Chat,
                HeightRequest     = 25,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
            };

            MessageEntry.SetBinding(Entry.TextProperty, "OutGoingText");

            var SentButton = new Button()
            {
                Text = "发送",
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Command           = _messagePageViewModel.SendCommand
            };

            var MessageControls = new Grid()
            {
                Padding           = 5,
                BackgroundColor   = Color.FromHex("efeff4"),
                VerticalOptions   = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                RowDefinitions    =
                {
                    new RowDefinition {
                        Height = new GridLength(30, GridUnitType.Absolute)
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    },
                    new ColumnDefinition {
                        Width = new GridLength(100, GridUnitType.Absolute)
                    },
                }
            };

            MessageControls.Children.Add(MessageEntry, 0, 0);
            MessageControls.Children.Add(SentButton, 0, 1);

            var ChatLayout = new StackLayout
            {
                Spacing         = 0,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children        =
                {
                    MessagesListView,
                    MessageControls
                }
            };

            Content = ChatLayout;
        }
Beispiel #6
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     ViewModel = e.Parameter as MessagePageViewModel;
 }