private void UpdateColor(object sender, PropertyChangedEventArgs args) { Dispatcher.Invoke( () => { if (_circle != null) { _circle.Fill = ChannelColors.GetChannelColor((IChannel)sender); _circleInnerText.Text = ChannelColors.GetChannelStatusText((IChannel)sender); } }); }
private void RefreshUi() { lock (_rects) { _rects.Clear(); var grid = new Grid(); grid.CreateRows("50*", "50*"); grid.Cell().Row(1) .AddUi( new Label() { Content = _uiCard.CenterFrequency, FontWeight = FontWeights.Black, HorizontalAlignment = HorizontalAlignment.Center, Foreground = Application.Current.Resources["SpectrumCardTextBrush"] as Brush }) .AddUi( new Label() { Content = _uiCard.Name, HorizontalAlignment = HorizontalAlignment.Left, Foreground = Application.Current.Resources["SpectrumCardNameBrush"] as Brush }) .AddUi( new Label() { //This is a shortcut to display the stream direction without picture using a webding character FontFamily = new FontFamily("Webdings"), FontSize = 16, Content = (_uiCard.StreamDirection == StreamDirectionEnum.Down) ? "6" : "5", HorizontalAlignment = HorizontalAlignment.Right, Foreground = Application.Current.Resources["SpectrumCardNameBrush"] as Brush } ); grid.Cell().Row(0).AddUi( new CustomCanvas( canvas => { int i = 0; Trace.WriteLine(StringExt.Format("Create: {0} - {1}", _uiCard.Name, _uiCard.Channels.Count)); foreach (var channel in _uiCard.Channels) { var rect = new Rectangle() { Fill = ChannelColors.GetChannelColor(channel), Margin = new Thickness(0, 3, 0, 3), Stroke = Application.Current.Resources["SpectrumCardChannelStateBorderBrush"] as Brush }; _rects.Add(rect); canvas.Children.Add(rect); i += 1; } return(true); }, (c) => { int i = 0; foreach (var channel in _uiCard.Channels) { Trace.WriteLine( StringExt.Format("Positioning : {0} - {1}", _uiCard.Name, _uiCard.Channels.Count)); var px = c.ActualWidth / 200 * (channel.CenterFreq - (_uiCard.CenterFrequency - 100) - (channel.Bandwidth / 2)); var size = c.ActualWidth / 200 * channel.Bandwidth; (c.Children[i] as Rectangle).Width = size; (c.Children[i] as Rectangle).Height = c.ActualHeight; Canvas.SetLeft(c.Children[i], px); Canvas.SetTop(c.Children[i], 0); i += 1; Trace.WriteLine(StringExt.Format("Positioning : {0} - {1}", _uiCard.Name, px)); } })); Trace.WriteLine(StringExt.Format("{0} - {1}", _uiCard.Name, _uiCard.Channels.Count)); Child = grid; if (ActualHeight < 50) { grid.RowDefinitions[0].Height = new GridLength(0); } InvalidateVisual(); } }