public ChatPage() { //Join Room Button joinButton = new Button { Text = "Join Group" }; joinButton.SetBinding(Button.CommandProperty, "JoinRoomCommand"); joinButton.Clicked += joinButton_Clicked; //Init Name Entry nameEntry = new Entry { TextColor = Color.Black }; nameEntry.SetBinding(Entry.TextProperty, "ChatMessage.Name", BindingMode.TwoWay); nameEntry.TextChanged += nameEntry_TextChanged; //Init Message Entry messageEntry = new Entry { TextColor = Color.Black }; messageEntry.SetBinding(Entry.TextProperty, "ChatMessage.Message"); sendMessageButton = new Button { Text = "Send Message" }; sendMessageButton.SetBinding(Button.CommandProperty, "SendMessageCommand"); //Init List // messagesListView = new ListView (); // messagesListView.SetBinding (ListView.ItemsSourceProperty, "Messages"); var messageList = new ChatListView(); messageList.VerticalOptions = LayoutOptions.FillAndExpand; messageList.SetBinding(ChatListView.ItemsSourceProperty, new Binding("Messages")); messageList.ItemTemplate = new DataTemplate(CreateMessageCell); var stackLayout = new StackLayout() { Orientation = StackOrientation.Vertical, Padding = new Thickness(5, 20, 5, 10), Children = { nameEntry, joinButton, messageEntry, sendMessageButton } }; Content = new StackLayout { Children = { stackLayout, messageList } }; }
public ChatPage() { InitializeComponent(); BindingContext = _viewModel = new ChatViewModel(); //https://github.com/juucustodio/Chat-Xamarin.Forms //https://github.com/L3xer/SignalR-Chat //https://github.com/jamesmontemagno/app-monkeychat var itens = new List <ChatMessage>() { new ChatMessage() { Name = "Suporte", Text = "Olá Daniel! Por favor verifique seus alertas...", IsIncoming = false, MessageDateTime = DateTime.Now, ImageFile = GetImageMockAsync(1) }, new ChatMessage() { Name = "Fabiana Barbosa", Text = "Olá! Tudo bem?", IsIncoming = true, MessageDateTime = DateTime.Now, ImageFile = GetImageMockAsync(2) } }; _viewModel.Messages.AddRange(itens); //MessageList.ItemsSource = itens; //MessagesListView.ItemsSource = itens; //???? //https://github.com/jamesmontemagno/ImageCirclePlugin _viewModel.Messages.CollectionChanged += (sender, e) => { var target = _viewModel.Messages[_viewModel.Messages.Count - 1]; ChatListView.ScrollTo(target, ScrollToPosition.End, true); }; }
protected void Page_PreRender(object sender, EventArgs e) { ChatContext db = new ChatContext(); ChatListView.DataSource = db.Messages.ToList(); ChatListView.DataBind(); if (ViewState["username"] != null) { ((TextBox)Page.FindControl("tb_Username")).Text = (string)ViewState["username"]; } ((TextBox)Page.FindControl("tb_Message")).Text = ""; }
public ChatPage(ViewModelBase viewModel) : base(viewModel) { Title = "Chat"; Icon = "chat.png"; var headerLabel = new Label(); headerLabel.Font = Font.BoldSystemFontOfSize(24); headerLabel.TextColor = Device.OnPlatform(Color.Green, Color.Yellow, Color.Yellow); headerLabel.SetBinding(Label.TextProperty, new Binding("Subject", stringFormat: " {0}")); var sendButton = new Button(); sendButton.Text = " Send "; sendButton.VerticalOptions = LayoutOptions.EndAndExpand; sendButton.SetBinding(Button.CommandProperty, new Binding("SendMessageCommand")); if (Device.OS == TargetPlatform.WinPhone) { sendButton.BackgroundColor = Color.Green; sendButton.BorderColor = Color.Green; sendButton.TextColor = Color.White; } var inputBox = new Entry(); inputBox.HorizontalOptions = LayoutOptions.FillAndExpand; inputBox.Keyboard = Keyboard.Chat; inputBox.Placeholder = "Type a message..."; inputBox.HeightRequest = 30; inputBox.SetBinding(Entry.TextProperty, new Binding("InputText", BindingMode.TwoWay)); var messageList = new ChatListView(); messageList.VerticalOptions = LayoutOptions.FillAndExpand; messageList.SetBinding(ChatListView.ItemsSourceProperty, new Binding("Events")); messageList.ItemTemplate = new DataTemplate(CreateMessageCell); Content = new StackLayout { Padding = Device.OnPlatform(new Thickness(6, 6, 6, 6), new Thickness(0), new Thickness(0)), Children = { new StackLayout { Children = { inputBox, sendButton }, Orientation = StackOrientation.Horizontal, Padding = new Thickness(0, Device.OnPlatform(0, 20, 0), 0, 0), }, //headerLabel, messageList, } }; }
public ChatPage(ViewModelBase viewModel) : base(viewModel) { Title = "Chat"; Icon = "chat.png"; var headerLabel = new Label(); headerLabel.Font = Font.BoldSystemFontOfSize(24); headerLabel.TextColor = Device.OnPlatform(Color.Green, Color.Yellow, Color.Yellow); headerLabel.SetBinding(Label.TextProperty, new Binding("Subject", stringFormat:" {0}")); var sendButton = new Button(); sendButton.Text = " Send "; sendButton.VerticalOptions = LayoutOptions.EndAndExpand; sendButton.SetBinding(Button.CommandProperty, new Binding("SendMessageCommand")); if (Device.OS == TargetPlatform.WinPhone) { sendButton.BackgroundColor = Color.Green; sendButton.BorderColor = Color.Green; sendButton.TextColor = Color.White; } var inputBox = new Entry(); inputBox.HorizontalOptions = LayoutOptions.FillAndExpand; inputBox.Keyboard = Keyboard.Chat; inputBox.Placeholder = "Type a message..."; inputBox.HeightRequest = 30; inputBox.SetBinding(Entry.TextProperty, new Binding("InputText", BindingMode.TwoWay)); var messageList = new ChatListView(); messageList.VerticalOptions = LayoutOptions.FillAndExpand; messageList.SetBinding(ChatListView.ItemsSourceProperty, new Binding("Events")); messageList.ItemTemplate = new DataTemplate(CreateMessageCell); Content = new StackLayout { Padding = Device.OnPlatform(new Thickness(6,6,6,6), new Thickness(0), new Thickness(0)), Children = { new StackLayout { Children = {inputBox, sendButton}, Orientation = StackOrientation.Horizontal, Padding = new Thickness(0, Device.OnPlatform(0, 20, 0),0,0), }, //headerLabel, messageList, } }; }
public ChatPage(ViewModelBase viewModel) : base(viewModel) { Title = "Chat"; Icon = "chat.png"; var messageList = new ChatListView(); messageList.VerticalOptions = LayoutOptions.FillAndExpand; messageList.SetBinding(ChatListView.ItemsSourceProperty, new Binding("Events")); messageList.ItemTemplate = new DataTemplate(CreateMessageCell); var leftButton = new Button(); leftButton.Text = " Option One "; leftButton.VerticalOptions = LayoutOptions.EndAndExpand; leftButton.SetBinding(Button.CommandProperty, new Binding("SendMessageCommand")); leftButton.BackgroundColor = Color.Green; leftButton.BorderColor = Color.Green; leftButton.TextColor = Color.White; var rightButton = new Button(); rightButton.Text = " Option Two "; rightButton.VerticalOptions = LayoutOptions.EndAndExpand; rightButton.SetBinding(Button.CommandProperty, new Binding("SendMessageCommand")); rightButton.BackgroundColor = Color.Blue; rightButton.BorderColor = Color.Blue; rightButton.TextColor = Color.White; var optionButtons = new StackLayout { Orientation = StackOrientation.Horizontal, Padding = new Thickness(0, Device.OnPlatform(0, 20, 0), 0, 0), HorizontalOptions = LayoutOptions.Center }; optionButtons.Children.Add(leftButton); optionButtons.Children.Add(rightButton); Content = new StackLayout { Padding = Device.OnPlatform(new Thickness(6, 6, 6, 6), new Thickness(0), new Thickness(0)), Children = { messageList, optionButtons } }; }
// Channel column functions private async void ChannelListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { UserInfo.Visibility = Visibility.Collapsed; var item = (Channel)ChannelListView.SelectedItem; if (item.IsText == Visibility.Visible) { ChannelTitle.Text = item.ID.ToString(); RightColumnStack.Visibility = Visibility.Visible; chatViewModel.Messages.Clear(); memberViewModel.Members.Clear(); await Task.Run(() => { foreach (Message m in item.Messages) { chatViewModel.AddText(m); } foreach (Member m in item.Members) { memberViewModel.AddMember(m); } Application.Current.Dispatcher.Invoke(new Action(() => { ChatListView.ScrollIntoView(chatViewModel.Messages[chatViewModel.Messages.Count() - 1]); })); }); } else { try { ChannelListView.SelectedItem = e.RemovedItems[0]; } catch (Exception) { ChannelListView.SelectedItem = null; } } } catch (Exception) { //TextChannelGrid.Visibility = Visibility.Collapsed; } }
public ChatPage(ViewModelBase viewModel) : base(viewModel) { Title = "Mensagens"; Icon = "chat.png"; Label lblHeader = new Label(); lblHeader.Font = Font.BoldSystemFontOfSize(24); lblHeader.TextColor = Device.OnPlatform(Color.Green, Color.Yellow, Color.Yellow); lblHeader.SetBinding(Label.TextProperty, new Binding("Subject", stringFormat: " {0}")); Button btnEnviar = new Button(); btnEnviar.Text = "Enviar"; btnEnviar.VerticalOptions = LayoutOptions.EndAndExpand; btnEnviar.SetBinding(Button.CommandProperty, new Binding("SendMessageCommand")); ConfiguraBtnEnviarWinPhone(btnEnviar); Entry txtMensagem = new Entry(); txtMensagem.HorizontalOptions = LayoutOptions.FillAndExpand; txtMensagem.Keyboard = Keyboard.Chat; txtMensagem.Placeholder = "Escreva uma mensagem..."; txtMensagem.HeightRequest = 30; txtMensagem.SetBinding(Entry.TextProperty, new Binding("InputText", BindingMode.TwoWay)); ChatListView listaMsg = new ChatListView(); listaMsg.VerticalOptions = LayoutOptions.FillAndExpand; //listaMsg.SetBinding(ChatListView.ItemsSourceProperty, new Binding("Events")); listaMsg.SetBinding(ChatListView.ItemsSourceProperty, new Binding("Mensagens")); listaMsg.ItemTemplate = new DataTemplate(CreateMessageCell); Content = new StackLayout { Padding = Device.OnPlatform(new Thickness(6, 6, 6, 6), new Thickness(0), new Thickness(0)), Children = { new StackLayout { Children = {txtMensagem, btnEnviar}, Orientation = StackOrientation.Horizontal, Padding = new Thickness(0, Device.OnPlatform(0, 20, 0),0,0), }, lblHeader, listaMsg, } }; }
public ChatRoomView() { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); /*ChatView = new ChatListView (){ * BackgroundColor = Color.FromHex ("#EEEEEE"), * HorizontalOptions=LayoutOptions.FillAndExpand, * VerticalOptions=LayoutOptions.FillAndExpand * }; * ChatView.SetBinding (ChatListView.ItemsSourceProperty, "Messages");//SelectedMessage * ChatView.SetBinding (ChatListView.SelectedItemProperty, "SelectedMessage",BindingMode.TwoWay); */ ChatView = new ChatListView() { BackgroundColor = Color.FromHex("#EEEEEE"), HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, // IsGroupingEnabled = true, //GroupDisplayBinding = new Binding("MessageDate"), // GroupShortNameBinding = new Binding ("MessageDate"), // GroupDisplayBinding = new Binding("MessageDate"), }; ChatView.SetBinding(ChatListView.ItemsSourceProperty, "Messages");//SelectedMessage ChatView.SetBinding(ChatListView.SelectedItemProperty, "SelectedMessage", BindingMode.TwoWay); MyEntry messageEntry = new MyEntry { Placeholder = "Type your message here", FontSize = 14, HeightRequest = 25, HorizontalOptions = LayoutOptions.FillAndExpand }; messageEntry.SetBinding(Entry.TextProperty, "YourMessage"); Image sendImg = new Image { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, Source = ImageSource.FromFile("send.png"), Aspect = Aspect.AspectFit }; StackLayout sendBtn = new StackLayout() { HeightRequest = 25, WidthRequest = 25, HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.CenterAndExpand, Children = { sendImg } }; sendBtn.SetBinding(StackLayout.IsVisibleProperty, "CanEnableSendBtn"); sendBtn.GestureRecognizers.Add(new TapGestureRecognizer((v, o) => { ((ChatRoomViewModel)this.BindingContext).SendCmd.Execute(null); })); ChatMessage.Children.Add(ChatView); ChatRoom.Children.Add(new StackLayout { BackgroundColor = Color.White, HeightRequest = 40, Spacing = 0, VerticalOptions = LayoutOptions.End, Orientation = StackOrientation.Horizontal, Padding = new Thickness(10, 10, 10, 10), Children = { messageEntry, sendBtn } }); // ChatRoom }