private void addMessageProcesser(string channel, ref BindingControlSet set) { #region svMessageRecord set.svMessageRecord = new ScrollViewer(); this.gMessageRecord.Children.Add(set.svMessageRecord); set.svMessageRecord.Visibility = Visibility.Hidden; #region tbRecord set.tbMessageRecord = new TextBlock(); set.svMessageRecord.Content = set.tbMessageRecord; set.tbMessageRecord.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Auto); set.tbMessageRecord.Margin = new Thickness(15, 0, 15, 0); set.tbMessageRecord.TextWrapping = TextWrapping.Wrap; #endregion #endregion #region svMessage set.svMessage = new ScrollViewer(); this.gMessage.Children.Add(set.svMessage); set.svMessage.SetValue(Grid.RowProperty, 1); set.svMessage.Visibility = Visibility.Hidden; #region tbMessage set.txtMessage = new TextBox(); set.svMessage.Content = set.txtMessage; set.txtMessage.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Auto); set.txtMessage.AcceptsTab = true; set.txtMessage.Padding = new Thickness(15, 0, 15, 0); set.txtMessage.TextWrapping = TextWrapping.Wrap; #endregion #endregion }
private void addChannelControls(string channel) { BindingControlSet set = new BindingControlSet(); this.addChannelItem(channel, ref set); this.addMessageProcesser(channel, ref set); this.controlSetDic.Add(channel, set); }
private void removeChannelControls(string channel) { BindingControlSet set = this.controlSetDic[channel]; this.spChannelList.Children.Remove(set.gChannel); this.gMessageRecord.Children.Remove(set.svMessageRecord); this.gMessage.Children.Remove(set.svMessage); set.Dispose(); this.controlSetDic.Remove(channel); }
private void addChannelItem(string channel, ref BindingControlSet set) { #region gChannel set.gChannel = new Grid(); this.spChannelList.Children.Add(set.gChannel); set.gChannel.Background = new SolidColorBrush(Color.FromArgb(16, 0, 0, 0)); set.gChannel.ColumnDefinitions.Add(new ColumnDefinition()); set.gChannel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(0, GridUnitType.Auto) }); #region grid1 Grid grid1 = new Grid(); set.gChannel.Children.Add(grid1); grid1.SetValue(Grid.ColumnProperty, 0); grid1.Margin = new Thickness(15); grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(0, GridUnitType.Auto) }); grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(10) }); grid1.ColumnDefinitions.Add(new ColumnDefinition()); grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(0, GridUnitType.Auto) }); grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(0, GridUnitType.Auto) }); #region imgChannelIcon set.imgChannelIcon = new Image(); grid1.Children.Add(set.imgChannelIcon); set.imgChannelIcon.Height = 35; set.imgChannelIcon.Width = 35; set.imgChannelIcon.Source = new BitmapImage(new Uri(@"/images/channel_default_icon.png", UriKind.Relative)); set.imgChannelIcon.Stretch = Stretch.Fill; #endregion #region grid2 Grid grid2 = new Grid(); grid1.Children.Add(grid2); grid2.SetValue(Grid.ColumnProperty, 2); grid2.VerticalAlignment = VerticalAlignment.Center; grid2.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0, GridUnitType.Auto) }); grid2.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2) }); grid2.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0, GridUnitType.Auto) }); #region tbChannelName set.tbChannelName = new TextBlock(); grid2.Children.Add(set.tbChannelName); set.tbChannelName.SetValue(Grid.RowProperty, 0); set.tbChannelName.Text = channel; #endregion #region tbLatestMessageContent set.tbLatestMessageContent = new TextBlock(); grid2.Children.Add(set.tbLatestMessageContent); set.tbLatestMessageContent.SetValue(Grid.RowProperty, 2); set.tbLatestMessageContent.Foreground = new SolidColorBrush(Colors.Gray); #endregion #endregion #region grid3 Grid grid3 = new Grid(); grid1.Children.Add(grid3); grid3.SetValue(Grid.ColumnProperty, 3); grid3.RowDefinitions.Add(new RowDefinition()); grid3.RowDefinitions.Add(new RowDefinition()); #region lblLatestMessageTime set.lblLatestMessageTime = new Label(); grid3.Children.Add(set.lblLatestMessageTime); set.lblLatestMessageTime.SetValue(Grid.RowProperty, 0); set.lblLatestMessageTime.Foreground = new SolidColorBrush(Colors.Gray); set.lblLatestMessageTime.HorizontalAlignment = HorizontalAlignment.Center; set.lblLatestMessageTime.VerticalAlignment = VerticalAlignment.Center; set.lblLatestMessageTime.HorizontalContentAlignment = HorizontalAlignment.Center; set.lblLatestMessageTime.VerticalAlignment = VerticalAlignment.Center; //set.lblLatestMessageTime.Content = "20:45"; #endregion #region brdrNewMessageBubble set.brdrNewMessageBubble = new Border(); grid3.Children.Add(set.brdrNewMessageBubble); set.brdrNewMessageBubble.SetValue(Grid.RowProperty, 1); set.brdrNewMessageBubble.Background = new SolidColorBrush(Colors.Red); set.brdrNewMessageBubble.Margin = new Thickness(11, 0, 11, 0); set.brdrNewMessageBubble.Padding = new Thickness(1); set.brdrNewMessageBubble.BorderBrush = new SolidColorBrush(Colors.Red); set.brdrNewMessageBubble.BorderThickness = new Thickness(1); set.brdrNewMessageBubble.CornerRadius = new CornerRadius(10); set.brdrNewMessageBubble.Visibility = Visibility.Collapsed; #region tbNewMessageCount set.tbNewMessageCount = new TextBlock(); set.brdrNewMessageBubble.Child = set.tbNewMessageCount; set.tbNewMessageCount.Foreground = new SolidColorBrush(Colors.White); set.tbNewMessageCount.HorizontalAlignment = HorizontalAlignment.Center; set.tbNewMessageCount.VerticalAlignment = VerticalAlignment.Center; set.tbNewMessageCount.Text = "0"; #endregion #endregion #endregion #endregion #region lblRemoveChannel Label lblRemoveChannel = new Label(); set.gChannel.Children.Add(lblRemoveChannel); lblRemoveChannel.SetValue(Grid.ColumnProperty, 1); lblRemoveChannel.Width = 5; lblRemoveChannel.Content = "删除"; lblRemoveChannel.Foreground = new SolidColorBrush(Colors.Transparent); lblRemoveChannel.Background = new SolidColorBrush(Colors.Transparent); lblRemoveChannel.HorizontalAlignment = HorizontalAlignment.Stretch; lblRemoveChannel.HorizontalContentAlignment = HorizontalAlignment.Center; lblRemoveChannel.VerticalAlignment = VerticalAlignment.Stretch; lblRemoveChannel.VerticalContentAlignment = VerticalAlignment.Center; lblRemoveChannel.MouseLeftButtonUp += (sender, e) => { this.disconnect(channel); }; #region trgMouseEnter EventTrigger trgMouseEnter = new EventTrigger(Label.MouseEnterEvent); lblRemoveChannel.Triggers.Add(trgMouseEnter); BeginStoryboard actBeginStoryboard_MouseEnter = new BeginStoryboard(); trgMouseEnter.Actions.Add(actBeginStoryboard_MouseEnter); Storyboard storyboard_MouseEnter = new Storyboard(); actBeginStoryboard_MouseEnter.Storyboard = storyboard_MouseEnter; Duration duration_MouseEnter = new TimeSpan(0, 0, 0, 0, 250); DoubleAnimation widthDoubleAnimation_MouseEnter = new DoubleAnimation(); storyboard_MouseEnter.Children.Add(widthDoubleAnimation_MouseEnter); Storyboard.SetTarget(widthDoubleAnimation_MouseEnter, lblRemoveChannel); Storyboard.SetTargetProperty(widthDoubleAnimation_MouseEnter, new PropertyPath(Label.WidthProperty)); widthDoubleAnimation_MouseEnter.From = 5; widthDoubleAnimation_MouseEnter.To = 50; widthDoubleAnimation_MouseEnter.Duration = duration_MouseEnter; DoubleAnimation opacityDoubleAnimation_MouseEnter = new DoubleAnimation(); storyboard_MouseEnter.Children.Add(opacityDoubleAnimation_MouseEnter); Storyboard.SetTarget(opacityDoubleAnimation_MouseEnter, lblRemoveChannel); Storyboard.SetTargetProperty(opacityDoubleAnimation_MouseEnter, new PropertyPath(Label.OpacityProperty)); opacityDoubleAnimation_MouseEnter.From = 0; opacityDoubleAnimation_MouseEnter.To = 1; opacityDoubleAnimation_MouseEnter.Duration = duration_MouseEnter; ColorAnimation foregroundColorAnimation_MouseEnter = new ColorAnimation(); storyboard_MouseEnter.Children.Add(foregroundColorAnimation_MouseEnter); Storyboard.SetTarget(foregroundColorAnimation_MouseEnter, lblRemoveChannel); Storyboard.SetTargetProperty(foregroundColorAnimation_MouseEnter, new PropertyPath("(0).(1)", Label.ForegroundProperty, SolidColorBrush.ColorProperty)); foregroundColorAnimation_MouseEnter.From = Colors.Transparent; foregroundColorAnimation_MouseEnter.To = Colors.White; foregroundColorAnimation_MouseEnter.Duration = duration_MouseEnter; ColorAnimation backgroundColorAnimation_MouseEnter = new ColorAnimation(); storyboard_MouseEnter.Children.Add(backgroundColorAnimation_MouseEnter); Storyboard.SetTarget(backgroundColorAnimation_MouseEnter, lblRemoveChannel); Storyboard.SetTargetProperty(backgroundColorAnimation_MouseEnter, new PropertyPath("(0).(1)", Label.BackgroundProperty, SolidColorBrush.ColorProperty)); backgroundColorAnimation_MouseEnter.From = Colors.Transparent; backgroundColorAnimation_MouseEnter.To = Colors.Red; backgroundColorAnimation_MouseEnter.Duration = duration_MouseEnter; #endregion #region trgMouseLeave EventTrigger trgMouseLeave = new EventTrigger(Label.MouseLeaveEvent); lblRemoveChannel.Triggers.Add(trgMouseLeave); BeginStoryboard actBeginStoryboard_MouseLeave = new BeginStoryboard(); trgMouseLeave.Actions.Add(actBeginStoryboard_MouseLeave); Storyboard storyboard_MouseLeave = new Storyboard(); actBeginStoryboard_MouseLeave.Storyboard = storyboard_MouseLeave; Duration duration_MouseLeave = new TimeSpan(0, 0, 0, 0, 250); DoubleAnimation widthDoubleAnimation_MouseLeave = new DoubleAnimation(); storyboard_MouseLeave.Children.Add(widthDoubleAnimation_MouseLeave); Storyboard.SetTarget(widthDoubleAnimation_MouseLeave, lblRemoveChannel); Storyboard.SetTargetProperty(widthDoubleAnimation_MouseLeave, new PropertyPath(Label.WidthProperty)); widthDoubleAnimation_MouseLeave.From = 50; widthDoubleAnimation_MouseLeave.To = 5; widthDoubleAnimation_MouseLeave.Duration = duration_MouseLeave; DoubleAnimation opacityDoubleAnimation_MouseLeave = new DoubleAnimation(); storyboard_MouseLeave.Children.Add(opacityDoubleAnimation_MouseLeave); Storyboard.SetTarget(opacityDoubleAnimation_MouseLeave, lblRemoveChannel); Storyboard.SetTargetProperty(opacityDoubleAnimation_MouseLeave, new PropertyPath(Label.OpacityProperty)); opacityDoubleAnimation_MouseLeave.From = 1; opacityDoubleAnimation_MouseLeave.To = 0; opacityDoubleAnimation_MouseLeave.Duration = duration_MouseLeave; ColorAnimation foregroundColorAnimation_MouseLeave = new ColorAnimation(); storyboard_MouseLeave.Children.Add(foregroundColorAnimation_MouseLeave); Storyboard.SetTarget(foregroundColorAnimation_MouseLeave, lblRemoveChannel); Storyboard.SetTargetProperty(foregroundColorAnimation_MouseLeave, new PropertyPath("(0).(1)", Label.ForegroundProperty, SolidColorBrush.ColorProperty)); foregroundColorAnimation_MouseLeave.From = Colors.White; foregroundColorAnimation_MouseLeave.To = Colors.Transparent; foregroundColorAnimation_MouseLeave.Duration = duration_MouseLeave; ColorAnimation backgroundColorAnimation_MouseLeave = new ColorAnimation(); storyboard_MouseLeave.Children.Add(backgroundColorAnimation_MouseLeave); Storyboard.SetTarget(backgroundColorAnimation_MouseLeave, lblRemoveChannel); Storyboard.SetTargetProperty(backgroundColorAnimation_MouseLeave, new PropertyPath("(0).(1)", Label.BackgroundProperty, SolidColorBrush.ColorProperty)); backgroundColorAnimation_MouseLeave.From = Colors.Red; backgroundColorAnimation_MouseLeave.To = Colors.Transparent; backgroundColorAnimation_MouseLeave.Duration = duration_MouseLeave; #endregion #endregion Label lblHotArea = new Label(); set.gChannel.Children.Add(lblHotArea); lblHotArea.SetValue(Grid.ColumnProperty, 0); lblHotArea.MouseLeftButtonUp += (sender, e) => { // 引发CurrentChannelChange事件。 this.setCurrentChannel(channel); }; #endregion }