public static void PutToBottom(Grid parent, Grid me, Grid source)
        {
            parent.ColumnDefinitions.Clear();
            parent.RowDefinitions.Clear();

            PhantasmagoriaSplitter splitter = new PhantasmagoriaSplitter()
            {
                VerticalAlignment = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Height = 8,
                Width = double.NaN
            };

            parent.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
            parent.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(parent.ActualHeight * 0.5), MinHeight = MIN_HEIGHT });

            me.SetValue(Grid.RowProperty, 0);
            me.SetValue(Grid.RowSpanProperty, 1);
            me.Margin = new Thickness(0, 0, 0, 3);
            splitter.SetValue(Grid.RowProperty, 0);
            splitter.SetValue(Grid.RowSpanProperty, 1);
            splitter.Margin = new Thickness(0, 0, 0, -4);
            source.SetValue(Grid.RowProperty, 1);
            source.SetValue(Grid.RowSpanProperty, 1);
            source.Margin = new Thickness(0, 3, 0, 0);

            parent.Children.Add(me);
            parent.Children.Add(source);
            parent.Children.Add(splitter);
        }
        private void BottomLeftMove(Grid grid, MouseEventArgs e)
        {
            var _point = getScreenRange(e.GetPosition(LayoutAreaCanvas));

            if (_point.Y > Height - 48)
                _point.Y = Height - 48;
            if (_point.Y < grid.Height - 16)
                _point.Y = grid.Height - 16;
            if (_point.X > Width - grid.Width)
                _point.X = Width - grid.Width;

            grid.SetValue(Canvas.TopProperty, (double)_point.Y - grid.Height + 32);
            grid.SetValue(Canvas.LeftProperty, (double)_point.X);

            // 横
            Line1.X1 = 32;
            Line1.Y1 = _point.Y;
            Line1.X2 = _point.X + 32;
            Line1.Y2 = _point.Y;

            Line2.X1 = _point.X + 32;
            Line2.Y1 = Height - 48;
            Line2.X2 = _point.X + 32;
            Line2.Y2 = _point.Y;
        }
        public Grid CreerTerrain()
        {
            var grid = new Grid();

            for (int x = 0; x < 17; x++)
                grid.ColumnDefinitions.Add(new ColumnDefinition());
            for (int y = 0; y < 20; y++)
                grid.RowDefinitions.Add(new RowDefinition());

            for (int x = 0; x < 20; x++)
                for (int y = 0; y < 17; y++)
                {
                    var childrenGrid = new Grid();
                    var border = new Border();

                    if (_plateauDeJeu.ZoneList.Exists(a => a.PositionX == x && a.PositionY == y))
                    {
                        var zone = _plateauDeJeu.ZoneList.First(a => a.PositionX == x && a.PositionY == y);

                        childrenGrid.DataContext = zone;

                        foreach (var objet in zone.ObjetList)
                        {
                            var binding = new Binding("Image");
                            border.SetBinding(Border.BackgroundProperty, binding);

                            if (objet is PacGomme)
                                zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\point.png", UriKind.Relative)));
                            if (objet is SuperPacGomme)
                                zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\pomme.png", UriKind.Relative)));
                            if (objet is Porte)
                                zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\porte.png", UriKind.Relative)));
                        }
                        childrenGrid.Children.Add(border);
                    }
                    else
                    {
                        border.Background = new SolidColorBrush(Colors.Red);
                        childrenGrid.Children.Add(border);
                    }

                    if (_plateauDeJeu.PersonnageList.Any(a => a.ZoneAbstraite.PositionX == x && a.ZoneAbstraite.PositionY == y))
                    {
                        var zone = _plateauDeJeu.ZoneList.First(a => a.PositionX == x && a.PositionY == y);
                        var personnage = _plateauDeJeu.PersonnageList.FirstOrDefault(a => a.ZoneAbstraite.PositionX == x && a.ZoneAbstraite.PositionY == y);
                        {
                            if (personnage is PacMan)
                                zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman.png", UriKind.Relative)));
                            if (personnage is Fantome)
                            {
                                var random = new Random();
                                var res = random.Next(1, 3);
                                switch (res)
                                {
                                    case 1:
                                        zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman-bleu.png", UriKind.Relative)));
                                        break;
                                    case 2:
                                        zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman-rose.png", UriKind.Relative)));
                                        break;
                                    case 3:
                                        zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman-rouge.png", UriKind.Relative)));
                                        break;
                                }
                            }
                        }
                    }

                    childrenGrid.SetValue(Grid.RowProperty, x);
                    childrenGrid.SetValue(Grid.ColumnProperty, y);
                    grid.Children.Add(childrenGrid);
                }
            return grid;
        }
 public static void SetSizeRowsToExpanderState(Grid grid, bool value)
 {
     grid.SetValue(SizeRowsToExpanderStateProperty, value);
 }
示例#5
0
        private void CreateUserInterface()
        {
            #region Область размещения.
            grid_region.Children.Clear();
            grid_region.ColumnDefinitions.Clear();

            for (int i = 0; i < R.Dim; i++)
            {
                grid_region.ColumnDefinitions.Add(new ColumnDefinition() { SharedSizeGroup = "dimension" });

                TextBox text_box = new TextBox();
                text_box.Text = region.Size(i).ToString();                
                text_box.SetValue(Grid.ColumnProperty, i);
                if (region.Freez(i))
                    text_box.Background = Brushes.Red;
                else
                    text_box.Background = Brushes.White;
                text_box.Tag = i;
                text_box.KeyDown += new System.Windows.Input.KeyEventHandler(TextBoxRegion_KeyDown);
                grid_region.Children.Add(text_box);
            }
            #endregion

            #region Объекты размещения.
            for (int i = 0; i < rects.Length; i++)
            {
                grid_rects.RowDefinitions.Add(new RowDefinition());

                Grid grid = new Grid();
                grid_rects.Children.Add(grid);
                grid.SetValue(Grid.RowProperty, i);
                grid.Tag = i;
                grid.MouseEnter += new System.Windows.Input.MouseEventHandler(GridRect_MouseEnter);
                for (int j = 0; j < R.Dim; j++)
                {
                    grid.ColumnDefinitions.Add(new ColumnDefinition() { SharedSizeGroup = "dimension" });

                    Grid grid_ = new Grid();
                    grid.Children.Add(grid_);
                    grid_.SetValue(Grid.ColumnProperty, j);
                    grid_.ColumnDefinitions.Add(new ColumnDefinition() { SharedSizeGroup = "value" });
                    grid_.ColumnDefinitions.Add(new ColumnDefinition() { SharedSizeGroup = "value" });
                    grid_.ColumnDefinitions.Add(new ColumnDefinition() { SharedSizeGroup = "value" });

                    TextBox text_box;

                    text_box = new TextBox();
                    text_box.Text = rects[i].Min(j).ToString();
                    text_box.IsReadOnly = true;
                    text_box.SetValue(Grid.ColumnProperty, 0);
                    grid_.Children.Add(text_box);

                    text_box = new TextBox();
                    text_box.Text = rects[i].Size(j).ToString();
                    //text_box.IsReadOnly = true;
                    text_box.SetValue(Grid.ColumnProperty, 1);
                    text_box.Tag = j;
                    text_box.KeyDown += new System.Windows.Input.KeyEventHandler(TextBoxRect_KeyDown);
                    grid_.Children.Add(text_box);

                    text_box = new TextBox();
                    text_box.Text = rects[i].Max(j).ToString();
                    text_box.IsReadOnly = true;
                    text_box.SetValue(Grid.ColumnProperty, 2);
                    grid_.Children.Add(text_box);
                }
            }
            #endregion
        }
示例#6
0
        private Grid createGridLayout(double width, double height, out Grid grid, out TextBlock page)
        {
            grid=new Grid();
            Grid layout=new Grid();
            layout.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            layout.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            layout.Width = width;
            layout.Height = width;
            layout.Children.Add(grid);
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions[0].Height = new GridLength(50, GridUnitType.Pixel);
            grid.RowDefinitions[2].Height = new GridLength(15, GridUnitType.Pixel);
            grid.RowDefinitions[1].Height = new GridLength(height - 65, GridUnitType.Pixel);

            StackPanel headerPanel=new StackPanel();
            headerPanel.Height = 50;
            headerPanel.Background = new SolidColorBrush(Colors.LightGray);
            TextBlock header=new TextBlock();
            //header.Text = String.Format("{0} на {1}", GlobalStatus.Current.HomeHeader,DateTime.Now.ToString("dd.MM.yy HH:mm"));
            header.Text = "";
            header.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            header.FontSize = 13;
            headerPanel.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
            grid.Children.Add(headerPanel);
            headerPanel.Children.Add(header);
            headerPanel.SetValue(Grid.RowProperty, 0);

            //host.Measure(new Size(width, double.PositiveInfinity));

            Grid footerGrid=new Grid();
            footerGrid.Height = 15;
            footerGrid.Background = new SolidColorBrush(Colors.LightGray);
            footerGrid.ColumnDefinitions.Add(new ColumnDefinition());
            footerGrid.ColumnDefinitions.Add(new ColumnDefinition());
            footerGrid.ColumnDefinitions.Add(new ColumnDefinition());
            footerGrid.ColumnDefinitions[0].Width = GridLength.Auto;
            footerGrid.ColumnDefinitions[1].Width = new GridLength(1, GridUnitType.Star);
            footerGrid.ColumnDefinitions[2].Width = GridLength.Auto;
            footerGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

            TextBlock footer=new TextBlock();
            footer.Text = String.Format("{0} на {1} ", GlobalStatus.Current.HomeHeader, DateTime.Now.ToString("HH:mm")); ;
            footer.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            footer.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            footer.FontSize = 12;
            footerGrid.Children.Add(footer);
            footer.SetValue(Grid.ColumnProperty, 1);

            page=new TextBlock();
            page.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            page.TextAlignment = TextAlignment.Left;
            page.FontSize = 12;
            footerGrid.Children.Add(page);
            page.SetValue(Grid.ColumnProperty, 0);

            TextBlock podp=new TextBlock();
            podp.Text = String.Format("{0}",  DateTime.Now.ToString("dd.MM.yy"));
            podp.TextAlignment = TextAlignment.Right;
            podp.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            podp.FontSize = 12;
            footerGrid.Children.Add(podp);
            podp.SetValue(Grid.ColumnProperty, 2);

            grid.Children.Add(footerGrid);
            footerGrid.SetValue(Grid.RowProperty, 2);

            return layout;
        }
        public virtual void AddConfigUI(Grid grid)
        {
            TextBlock label;
            #region Header
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Grid g = new Grid();
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.RowDefinitions.Add(new RowDefinition());
            label = new TextBlock()
            {
                Text = DisplayName ?? Name,
                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                Margin = new Thickness(2,10,2,2),
                FontWeight = FontWeights.Bold, 
                TextTrimming = TextTrimming.WordEllipsis
            };
            g.Children.Add(label);

            if (Required)
            {
                label = new TextBlock()
                    {
                        Text = Resources.Strings.Required,
                        VerticalAlignment = System.Windows.VerticalAlignment.Center,
                        HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
                        Margin = new Thickness(2),
                        FontWeight = FontWeights.Light,
                        FontStyle = FontStyles.Italic
                    };
                label.SetValue(Grid.ColumnProperty, 1);
                g.Children.Add(label);
            }
            g.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            g.SetValue(Grid.ColumnSpanProperty, 2);
            grid.Children.Add(g);
            #endregion

            #region Type
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            label = new TextBlock()
            {
				Text = Resources.Strings.LabelType,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);
            label = new TextBlock()
            {
                Text = Type.ToString(),
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            label.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(label);
            #endregion

            #region Label
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            label = new TextBlock()
            {
				Text = Resources.Strings.LabelLabel,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);
            TextBox labelTextBox = new TextBox()
            {
                Text = Label == null ? string.Empty : Label,
                Margin = new Thickness(2),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
            };
            labelTextBox.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            labelTextBox.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(labelTextBox);
            labelTextBox.TextChanged += (s, e) =>
            {
                Label = labelTextBox.Text;
            };
            #endregion

            if (Input)
            {
                #region Tooltip
                grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                label = new TextBlock()
                {
					Text = Resources.Strings.LabelTooltip,
                    Margin = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                TextBox tbToolTip = new TextBox()
                {
                    Margin = new Thickness(2),
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                };
                if (!string.IsNullOrEmpty(ToolTip))
                    tbToolTip.Text = ToolTip;
                tbToolTip.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                tbToolTip.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(tbToolTip);
                tbToolTip.TextChanged += (s, e) =>
                {
                    ToolTip = tbToolTip.Text;
                };
                #endregion

                #region ShownAtRuntime
                grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                label = new TextBlock()
                {
					Text = Resources.Strings.LabelShowParameter,
                    Margin = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                CheckBox chb = new CheckBox() { IsChecked = ShownAtRunTime, Margin = new Thickness(2) };
                chb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                chb.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(chb);
                chb.Checked += (s, e) => { ShownAtRunTime = true; };
                chb.Unchecked += (s, e) => { ShownAtRunTime = false; };
                #endregion

                #region Default Value
                if (Type != GPParameterType.FeatureLayer && Type != GPParameterType.MultiValueString)
                {
                    grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                    label = new TextBlock()
                    {
						Text = Resources.Strings.LabelDefaultValue,
                        Margin = new Thickness(2),
                        VerticalAlignment = System.Windows.VerticalAlignment.Center
                    };
                    label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                    grid.Children.Add(label);
                    ParameterBase paramUI = ParameterFactory.Create(this, null);
                    paramUI.AddUI(grid);
                    paramUI.CanExecuteChanged += (a, b) =>
                    {
                        this.DefaultValue = paramUI.Value;
                    };
                }
                #endregion
            }
        }
        private void ResizeGrid(IEnumerable<OnScreenKey> keys)
        {
            if (keys == null) throw new ArgumentNullException("keys");

            // Make sure there's enough rows
            var rowCount = keys.Max(x => x.GridRow) + 1;
            for (var extraRowIndex = RowDefinitions.Count; extraRowIndex < rowCount; extraRowIndex++)
            {
                // Button Row
                RowDefinitions.Add(new RowDefinition());

                // Add a grid for the buttons
                var g = new Grid();
                _buttonRows.Add(g);
                Children.Add(g);
                g.SetValue(RowProperty, extraRowIndex);
                g.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
            }

            // Make sure each row has enough columns
            for (var buttonRowIndex = 0; buttonRowIndex < rowCount; buttonRowIndex++)
            {
                var grid = _buttonRows[buttonRowIndex];
                var colCount = keys.Where(x => x.GridRow == buttonRowIndex).Max(x => x.GridColumn) + 1;
                for (var colsToAdd = colCount - grid.ColumnDefinitions.Count; colsToAdd > 0; colsToAdd--)
                {
                    // Add the extra Column
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                }
                for (var colsToRemove = grid.ColumnDefinitions.Count - colCount; colsToRemove > 0; colsToRemove--)
                {
                    // Remove the extra Column
                    grid.ColumnDefinitions.RemoveAt(0);
                }

                // Set the width of each column according to the key's GridWidth definition
                keys.Where(x => x.GridRow == buttonRowIndex && x.GridWidth.Value != 1).ToList()
                    .ForEach(x => grid.ColumnDefinitions[x.GridColumn].Width = x.GridWidth);

            }
        }
示例#9
0
        /// <summary>
        /// OnBusyStateChanged
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void OnBusyStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            bool isBusy = (bool)e.NewValue;
            bool wasBusy = (bool)e.OldValue;

            if (isBusy == wasBusy)
            {
                return;
            }

            var hostGridObject = (GetTargetVisual(d) ?? d);
            Debug.Assert(hostGridObject != null);

            var hostGrid = hostGridObject as Grid;
            if (hostGrid == null)
            {
                throw new InvalidCastException(
                    string.Format(
                        "The object being attached to must be of type {0}. Try embedding your visual inside a {0} control, and attaching the behavior to the {0} instead.",
                        typeof(Grid).Name));
            }

            if (isBusy)
            {
                Debug.Assert(LogicalTreeHelper.FindLogicalNode(hostGrid, "BusyIndicator") == null);

                bool dimBackground = GetDimBackground(d);
                var grid = new Grid
                {
                    Name = "BusyIndicator",
                    Opacity = 0.0
                };
                if (dimBackground)
                {
                    grid.Cursor = Cursors.Wait;
                    grid.ForceCursor = true;

                    InputManager.Current.PreProcessInput += OnPreProcessInput;
                }
                grid.SetBinding(FrameworkElement.WidthProperty, new Binding("ActualWidth")
                {
                    Source = hostGrid
                });
                grid.SetBinding(FrameworkElement.HeightProperty, new Binding("ActualHeight")
                {
                    Source = hostGrid
                });
                for (int i = 1; i <= 3; ++i)
                {
                    grid.ColumnDefinitions.Add(new ColumnDefinition
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    });
                    grid.RowDefinitions.Add(new RowDefinition
                    {
                        Height = new GridLength(1, GridUnitType.Star)
                    });
                }
                ProgressIndicator = new BusyIndicator() { Width = 150, Height = 120 };

                var viewbox = new Viewbox
                {
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Stretch = Stretch.Uniform,
                    StretchDirection = StretchDirection.Both,
                    Child = ProgressIndicator
                };
                grid.SetValue(Panel.ZIndexProperty, 1000);
                grid.SetValue(Grid.RowSpanProperty, Math.Max(1, hostGrid.RowDefinitions.Count));
                grid.SetValue(Grid.ColumnSpanProperty, Math.Max(1, hostGrid.ColumnDefinitions.Count));
                if (GetAddMargins(d))
                {
                    viewbox.SetValue(Grid.RowProperty, 1);
                    viewbox.SetValue(Grid.ColumnProperty, 1);
                }
                else
                {
                    viewbox.SetValue(Grid.RowSpanProperty, 3);
                    viewbox.SetValue(Grid.ColumnSpanProperty, 3);
                }
                viewbox.SetValue(Panel.ZIndexProperty, 1);

                var dimmer = new Rectangle
                {
                    Name = "Dimmer",
                    Opacity = GetDimmerOpacity(d),
                    Fill = GetDimmerBrush(d),
                    Visibility = (dimBackground ? Visibility.Visible : Visibility.Collapsed)
                };
                dimmer.SetValue(Grid.RowSpanProperty, 3);
                dimmer.SetValue(Grid.ColumnSpanProperty, 3);
                dimmer.SetValue(Panel.ZIndexProperty, 0);
                grid.Children.Add(dimmer);

                grid.Children.Add(viewbox);

                grid.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(1.0, GetDimTransitionDuration(d)));

                hostGrid.Children.Add(grid);
            }
            else
            {
                var grid = (Grid)LogicalTreeHelper.FindLogicalNode(hostGrid, "BusyIndicator");

                Debug.Assert(grid != null);

                if (grid != null)
                {
                    grid.Name = string.Empty;

                    var fadeOutAnimation = new DoubleAnimation(0.0, GetDimTransitionDuration(d));
                    fadeOutAnimation.Completed += (sender, args) => OnFadeOutAnimationCompleted(d, hostGrid, grid);
                    grid.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation);
                }
            }
        }
        private void TopRightMove(Grid grid, MouseEventArgs e)
        {
            var _point = getScreenRange(e.GetPosition(LayoutAreaCanvas));

            if (_point.Y > Height - grid.Height - 16)
                _point.Y = Height - grid.Height - 16;
            if (_point.X > Width - 32)
                _point.X = Width - 32;
            if (_point.X < grid.Width - 32)
                _point.X = grid.Width - 32;

            grid.SetValue(Canvas.TopProperty, (double)_point.Y);
            grid.SetValue(Canvas.LeftProperty, (double)_point.X - grid.Width + 32 );

            // 横
            Line1.X1 = Width - 32;
            Line1.Y1 = _point.Y + 32;
            Line1.X2 = _point.X;
            Line1.Y2 = _point.Y + 32;

            // 縦
            Line2.X1 = _point.X;
            Line2.Y1 = 48;
            Line2.X2 = _point.X;
            Line2.Y2 = _point.Y + 32;
        }
示例#11
0
        private void GenerateControls() {
            var settings = _viewModel.Settings;
            var properties = settings.GetType().GetProperties();
            var groups = new Dictionary<string, Dictionary<TextBlock, Control>>();
            Control firstControl = null;
            foreach (var property in properties) {
                var type = property.PropertyType;
                var propertyPath = property.Name;
                var genericType = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
                
                Control control = null;
                DependencyProperty bindProperty = null;
                if (genericType == typeof(SettingSingleSelection<>)) {
                    if (typeof(INovaromaService).IsAssignableFrom(type.GetGenericArguments().First()))
                        control = new SingleSelectionUserControl();
                    else
                        control = new SingleSelectComboBox();
                    bindProperty = DataContextProperty;
                    _lateBindables.Add((ILateBindable)property.GetValue(settings));
                }
                else if (genericType == typeof(SettingMultiSelection<>)) {
                    control = new MultiSelectionUserControl();
                    bindProperty = DataContextProperty;
                    _lateBindables.Add((ILateBindable)property.GetValue(settings));
                }
                else if (type == typeof (DirectorySelection)) {
                    control = new DirectorySelectUserControl();
                    bindProperty = DirectorySelectUserControl.TextProperty;
                    propertyPath += ".Path";
                }
                else if (!property.CanWrite) continue;
                else if (type == typeof(string)) {
                    control = new TextBox();
                    bindProperty = TextBox.TextProperty;
                }
                else if (type.IsNumericType()) {
                    control = new NumericUpDown();
                    bindProperty = NumericUpDown.ValueProperty;
                }
                else if (type == typeof (bool) 
                        || (genericType != null && genericType == typeof(Nullable<>) && genericType.GenericTypeArguments[0] == typeof(bool))) {
                    control = new ToggleSwitch {Language = Language};
                    bindProperty = ToggleSwitch.IsCheckedProperty;
                }

                if (control != null && bindProperty != null) {
                    if (firstControl == null) firstControl = control;

                    var displayAttr = property.GetAttribute<DisplayAttribute>();
                    string displayValue;
                    string description;
                    string groupName;
                    if (displayAttr != null) {
                        displayValue = displayAttr.GetName() ?? property.Name;
                        description = displayAttr.GetDescription() ?? string.Empty;
                        groupName = displayAttr.GetGroupName() ?? string.Empty;
                    }
                    else {
                        displayValue = property.Name;
                        description = string.Empty;
                        groupName = string.Empty;
                    }

                    var textBlock = new TextBlock();
                    textBlock.VerticalAlignment = VerticalAlignment.Center;
                    textBlock.Margin = new Thickness(10);
                    textBlock.Text = displayValue;
                    if (!string.IsNullOrEmpty(description))
                        textBlock.ToolTip = description;
                    textBlock.SetCurrentValue(Grid.ColumnProperty, 0);

                    control.Margin = new Thickness(10);
                    control.SetCurrentValue(Grid.ColumnProperty, 1);

                    var binding = new Binding();
                    binding.Source = settings;
                    binding.Path = new PropertyPath(propertyPath);
                    binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
                    var bindingExpression = BindingOperations.SetBinding(control, bindProperty, binding);
                    _bindings.Add(bindingExpression);

                    if (groups.ContainsKey(groupName))
                        groups[groupName].Add(textBlock, control);
                    else
                        groups.Add(groupName, new Dictionary<TextBlock, Control> {{textBlock, control}});
                }
            }

            foreach (var group in groups) {
                var tabItem = new TabItem();
                if (groups.Count > 1)
                    tabItem.Header = string.IsNullOrEmpty(group.Key) ? Novaroma.Properties.Resources.Main : group.Key;
                ControlsTabControl.Items.Add(tabItem);

                var scrollViewer = new ScrollViewer();
                tabItem.Content = scrollViewer;

                var grid = new Grid();
                grid.HorizontalAlignment = HorizontalAlignment.Stretch;
                grid.VerticalAlignment = VerticalAlignment.Stretch;
                grid.Margin = new Thickness(20);
                grid.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Auto);
                grid.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Auto);
                grid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(0, GridUnitType.Auto)});
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                scrollViewer.Content = grid;

                var i = 0;
                foreach (var controls in group.Value) {
                    var rowDefinition = new RowDefinition();
                    rowDefinition.Height = new GridLength(0, GridUnitType.Auto);
                    grid.RowDefinitions.Add(rowDefinition);

                    var textBlock = controls.Key;
                    textBlock.SetCurrentValue(Grid.RowProperty, i);

                    var control = controls.Value;
                    control.SetCurrentValue(Grid.RowProperty, i);

                    grid.Children.Add(controls.Key);
                    grid.Children.Add(controls.Value);

                    i++;
                }
            }

            if (firstControl != null)
                firstControl.Focus();
        }
示例#12
0
        // Organises the table for a given user on a particular day
        public void SetTimetable(User CurrentUser, DateTime Day)
        {
            // Get the current database state
            DataSnapshot Frame = DataRepository.TakeSnapshot();

            // Generate the correct number of rows
            Container.RowDefinitions.Clear();
            // Top header row
            Container.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
            // Actual rows of the table
            for (int y = 0; y < Frame.Rooms.Count; y++)
                Container.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(TileHeight) });

            // Generate the columns
            Container.ColumnDefinitions.Clear();
            // Left-hand side-heading column
            Container.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(LeftWidth) });
            // Actual columns in the table
            for (int x = 0; x < Frame.Periods.Count; x++)
                Container.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(TileWidth) });

            // Add the left-hand bar, contains room names and a tooltip
            Container.Children.Clear();
            for (int y = 0; y < Frame.Rooms.Count; y++)
            {
                // Create a textblock displaying the room name
                TextBlock Child = new TextBlock();
                Child.Text = Frame.Rooms[y].RoomName;
                // Set standard font, margin, wrapping style etc
                Child.FontSize = 16;
                Child.Margin = new Thickness(0, 0, 5, 0);
                Child.TextWrapping = TextWrapping.Wrap;
                Child.VerticalAlignment = VerticalAlignment.Center;
                Child.HorizontalAlignment = HorizontalAlignment.Right;

                // Create the alignment control for nice layout
                Border LeftTile = new Border();
                // Set tooltip to useful information
                LeftTile.ToolTip = "Standard Seats: " + Frame.Rooms[y].StandardSeats + (Frame.Rooms[y].SpecialSeats == 0 ? "" : "\n" + Frame.Rooms[y].SpecialSeatType + ": " + Frame.Rooms[y].SpecialSeats);
                // Set the UI child of this control to be the texblock above
                LeftTile.Child = Child;
                // Background colour
                LeftTile.Background = MarginBrush;

                // Positioning on the layout grid
                LeftTile.SetValue(Grid.RowProperty, y + 1);
                LeftTile.SetValue(Grid.ColumnProperty, 0);

                // Add the controls to the grid
                Container.Children.Add(LeftTile);
            }

            // Add the top heading, contains timeslot name and time interval
            for (int x = -1; x < Frame.Periods.Count; x++)
            {
                // Use a grid for ease of layout
                Grid TopTile = new Grid();
                TopTile.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
                TopTile.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });

                // Set background and child alignments
                TopTile.Background = MarginBrush;
                TopTile.VerticalAlignment = VerticalAlignment.Bottom;
                TopTile.HorizontalAlignment = HorizontalAlignment.Left;

                // If we're not filling out the top-left corner cell, store the timeslot name
                string Text = "";
                if (x >= 0 && !string.IsNullOrWhiteSpace(Frame.Periods[x].Name))
                    Text = Frame.Periods[x].Name;

                // First textblock - timeslot name
                TopTile.Children.Add(new TextBlock() { Text = Text, FontSize = 16, Margin = new Thickness(2, 2, 2, 0), TextWrapping = TextWrapping.Wrap, Width = TileWidth });
                // Second textblock - timeslot duration
                TopTile.Children.Add(new TextBlock() { Text = x >= 0 ? Frame.Periods[x].TimeRange : "", FontSize = 16, Margin = new Thickness(2, 0, 2, 10), TextWrapping = TextWrapping.Wrap, Width = TileWidth });

                // Set the position of each textblock within the local grid
                for (int y = 0; y < TopTile.Children.Count; y++)
                    TopTile.Children[y].SetValue(Grid.RowProperty, y);

                // Algin the local grid within the table's grid
                TopTile.SetValue(Grid.RowProperty, 0);
                TopTile.SetValue(Grid.ColumnProperty, x + 1);
                Container.Children.Add(TopTile);
            }

            // Add the main content
            // Find bookings on this day
            List<Booking> RelevantBookings = Frame.Bookings.Where(b => b.MatchesDay(Day)).ToList();
            // Initialise the internal array of tiles
            Tiles = new TimetableTile[Frame.Rooms.Count, Frame.Periods.Count];
            for (int y = 0; y < Frame.Rooms.Count; y++)
            {
                for (int x = 0; x < Frame.Periods.Count; x++)
                {
                    // Get the booking (or null) for this combination of room and timeslot
                    Booking Current = RelevantBookings.Where(b => b.TimeSlot == Frame.Periods[x] && b.Rooms.Contains(Frame.Rooms[y])).SingleOrDefault();

                    // Create the timetable tile
                    Tiles[y, x] = new TimetableTile(Current, Frame.Periods[x], Frame.Rooms[y], CurrentUser);

                    // Layout
                    Container.Children.Add(Tiles[y, x]);
                    Tiles[y, x].SetValue(Grid.RowProperty, y + 1);
                    Tiles[y, x].SetValue(Grid.ColumnProperty, x + 1);

                    // Hook up the tile clicked handler
                    Tiles[y, x].MouseLeftButtonDown += (o, e) => TileClicked((TimetableTile)o);
                }
            }
        }
 public static void SetDecrementKeyGesture(Grid grid, KeyGesture gesture)
 {
     Guard.ArgumentNotNull(grid, "grid");
     grid.SetValue(DecrementKeyGestureProperty, gesture);
 }
 public static void SetTargetColumn(Grid grid, int columnIndex)
 {
     Guard.ArgumentNotNull(grid, "grid");
     grid.SetValue(TargetColumnProperty, columnIndex);
 }
示例#15
0
        private void InitPopup()
        {
            popup = new Popup();
            popup.Opened += popup_Opened;

            Binding backgroundBinding = new Binding("Background");
            backgroundBinding.Source = this;

            Binding foregroundBinding = new Binding("Foreground");
            foregroundBinding.Source = this;

            Grid border = new Grid();
            border.Background = new SolidColorBrush(Color.FromArgb(200, 0, 0, 0));
            border.Width = Application.Current.Host.Content.ActualWidth;
            border.Height = Application.Current.Host.Content.ActualHeight;

            Grid container = new Grid();
            CompositeTransform transform = new CompositeTransform()
            {
                TranslateY = -Application.Current.Host.Content.ActualHeight
            };
            container.RenderTransform = transform;
            container.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            container.SetBinding(Grid.BackgroundProperty, backgroundBinding);

            #region init grid rows

            RowDefinition row1 = new RowDefinition()
            {
                Height = GridLength.Auto
            };
            container.RowDefinitions.Add(row1);

            RowDefinition row2 = new RowDefinition()
            {
                Height = GridLength.Auto
            };
            container.RowDefinitions.Add(row2);

            RowDefinition row3 = new RowDefinition()
            {
                Height = GridLength.Auto
            };
            container.RowDefinitions.Add(row3);

            #endregion

            TextBlock title = new TextBlock()
            {
                Margin = new Thickness(12),
                FontSize = 30,
                FontWeight = FontWeights.Black
            };
            Binding titleBinding = new Binding("Title");
            titleBinding.Source = this;
            title.SetBinding(TextBlock.TextProperty, titleBinding);

            title.SetBinding(TextBlock.ForegroundProperty, foregroundBinding);
            container.Children.Add(title);

            TextBlock content = new TextBlock()
            {
                Margin = new Thickness(12),
                FontSize = 26,
                FontWeight = FontWeights.Medium
            };

            Binding contentBinding = new Binding("Content");
            contentBinding.Source = this;
            content.SetBinding(TextBlock.TextProperty, contentBinding);

            content.SetBinding(TextBlock.ForegroundProperty, foregroundBinding);
            content.SetValue(Grid.RowProperty, 1);
            container.Children.Add(content);

            switch (MessageBoxButtons)
            {
                case MessageBoxButton.OK:
                    {
                        Button btn = new Button()
                        {
                            Content = "OK",
                            Margin = new Thickness(0, 0, 0, 10)
                        };

                        btn.Click += (s, args) =>
                        {
                            var handler = OKClick;
                            if (null != handler)
                            {
                                handler(this, new RoutedEventArgs());
                            }

                            GetCloseAnimation();
                        };

                        btn.SetValue(Grid.RowProperty, 2);
                        container.Children.Add(btn);
                    }
                    break;
                case MessageBoxButton.OKCancel:
                    {
                        Grid btnGrid = new Grid();
                        btnGrid.Margin = new Thickness(0, 0, 0, 10);
                        btnGrid.SetValue(Grid.RowProperty, 2);
                        ColumnDefinition column1 = new ColumnDefinition();
                        ColumnDefinition column2 = new ColumnDefinition();
                        btnGrid.ColumnDefinitions.Add(column1);
                        btnGrid.ColumnDefinitions.Add(column2);

                        Button btnOK = new Button()
                        {
                            Content = "OK"
                        };
                        btnOK.Click += (s, args) =>
                        {
                            var handler = OKClick;
                            if (null != handler)
                            {
                                handler(this, new RoutedEventArgs());
                            }

                            GetCloseAnimation();
                        };
                        btnGrid.Children.Add(btnOK);

                        Button btnCancel = new Button()
                        {
                            Content = "Cancel"
                        };
                        btnCancel.Click += (s, args) =>
                        {
                            var handler = CancelClick;
                            if (null != handler)
                            {
                                handler(this, new RoutedEventArgs());
                            }

                            GetCloseAnimation();
                        };
                        btnCancel.SetValue(Grid.ColumnProperty, 1);
                        btnGrid.Children.Add(btnCancel);

                        container.Children.Add(btnGrid);
                    }
                    break;
            }

            border.Children.Add(container);
            popup.Child = border;
        }
示例#16
0
 /// <summary>
 /// Sets the value of <see cref="RowsProperty"/> for a given <see cref="Grid"/>.
 /// </summary>
 /// <param name="obj">The given <see cref="Grid"/>.</param>
 /// <param name="value">The new value of <see cref="RowsProperty"/>.</param>
 public static void SetRows(Grid obj, string value)
 {
     obj.SetValue(RowsProperty, value);
 }
示例#17
0
        private void CreateGraphUI(double[] percentages, int length)
        {
            graphGrid.Children.Clear();
            graphGrid.ColumnDefinitions.Clear();
            for (int i = 0; i < length; i++)
            {
                graphGrid.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Star)
                });
                Grid grid = new Grid()
                {
                    Margin = new Thickness(5, 0, 5, 0),
                    Background = new SolidColorBrush(_colors[i % _colors.Length]),
                    Height = 0,
                    Name = "rect" + i,
                    VerticalAlignment = System.Windows.VerticalAlignment.Bottom,
                    Tag = Drinks[i].Id
                };

                TextBlock text = new TextBlock()
                {
                    Text = Math.Round(percentages[i] * 100, 2) + "%",
                    VerticalAlignment = System.Windows.VerticalAlignment.Center,
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                    FontFamily = new FontFamily(new Uri("pack://application:/Styles/"), "Coolvetica Rg"),
                    Foreground = new SolidColorBrush(Colors.White),

                };

                grid.Children.Add(text);

                grid.SetValue(Grid.ColumnProperty, i);
                graphGrid.Children.Add(grid);

            }
        }
 private void StepSelected(object sender, RoutedEventArgs e)
 {
     if (_stepChanger != null)
     {
         TreeCanvas.Children.Remove(_stepChanger);
     }
     int id = Convert.ToInt32((sender as ListBoxItem).Name.Substring(1));
     var step = BL.ChangesBuffer.CurrentState.StepBuffer.First(st => st.Id == id);
     var valueSetter = new Grid() { Width = 120, Height = 80, Background = Brushes.CornflowerBlue };
     valueSetter.Children.Add(new Label
         {
             Content = "Фиксация прогресса",
             VerticalAlignment = VerticalAlignment.Top,
             HorizontalAlignment = HorizontalAlignment.Left
         });
     valueSetter.Children.Add(new TextBox
         {
             Text = step.Criteria.CurrentValue.ToString(),
             VerticalAlignment = VerticalAlignment.Center,
             HorizontalAlignment = HorizontalAlignment.Right,
             Width = 40,
             MaxLength = step.Criteria.TargetValue.ToString().Length,
             Name = "ValueChanger"
         });
     var b = new Button()
         {
             HorizontalAlignment = HorizontalAlignment.Left,
             VerticalAlignment = VerticalAlignment.Bottom,
             Width = 25,
             Height = 25,
             Content = FindResource("Edit1"),
             Name = "Q" + id.ToString()
         };
     var b1 = new Button()
     {
         HorizontalAlignment = HorizontalAlignment.Left,
         VerticalAlignment = VerticalAlignment.Bottom,
         Width = 25,
         Height = 25,
         Margin = new Thickness(26,0,0,0),
         Content = FindResource("Remove1"),
         Name = "R" + id.ToString()
     };
     var ok = new Button()
     {
         HorizontalAlignment = HorizontalAlignment.Right,
         VerticalAlignment = VerticalAlignment.Bottom,
         Width = 40,
         Height = 25,
         Content = "OK",
         Name = "O" + step.Id.ToString()
     };
     valueSetter.Children.Add(b);
     valueSetter.Children.Add(b1);
     valueSetter.Children.Add(ok);
     b1.Click += RemoveStep;
     b.Click += EditStep;
     ok.Click += ChangeCurrentValueOfStep;
     TreeCanvas.Children.Add(valueSetter);
     var p = Mouse.GetPosition(TreeCanvas);
     valueSetter.SetValue(Canvas.LeftProperty, p.X);
     valueSetter.SetValue(Canvas.TopProperty, p.Y);
     _stepChanger = valueSetter;
 }
示例#19
0
 //操作安全判断
 private void Safety(object sender, RoutedEventArgs e)
 {
     TreeViewItem tvi = ((sender as TreeView).SelectedItem as TreeViewItem);
     string save = tvi.Uid.ToString();
     if (save == null || "".Equals(save)) return;
     if (save.Equals("loginDiary"))
     {
         Grid saveGrid = new Grid();
         showGrid.Children.Add(saveGrid);
         saveGrid.SetValue(Grid.RowProperty, 0);
         saveGrid.SetValue(Grid.ColumnProperty, 1);
         saveGrid.Background = Brushes.DarkCyan;
     }
     else
     {
         Grid saveGrid = new Grid();
         showGrid.Children.Add(saveGrid);
         saveGrid.SetValue(Grid.RowProperty, 0);
         saveGrid.SetValue(Grid.ColumnProperty, 1);
         saveGrid.Background = Brushes.DarkOrchid;
     }
 }
示例#20
0
        /// <summary>
        /// Gets the grid panel.
        /// </summary>
        /// <returns>Grid.</returns>
        private Grid GetGridPanel()
        {
            const string popupName = "__PopupGridPanel";
            if (_panel == null) _panel = PopupHelper.FindTopLevelPanel(Application.Current.RootVisual);
            var gridPanel = _panel.FindName(popupName) as Grid;
            if (gridPanel == null)
            {
                gridPanel = new Grid { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Name = popupName };
                gridPanel.SetValue(Grid.RowSpanProperty, 20);
                gridPanel.SetValue(Grid.ColumnSpanProperty, 20);

                _panel.Children.Add(gridPanel);
            }

            return gridPanel;
        }
示例#21
0
        private void Paint(Size finalSize)
        {
            //maxValue = 100;
            var circleWidth = 4d;
            var pointWidth = 4d;
            var keduWidth = 1d;
            var keduLength = 5d;
            var standWidth = 3d;

            var startDegree = 290d;
            var standLength = 10d;
            var minValue = MinValue;
            var maxValue = MaxValue;
            if (minValue >= maxValue)
                return;
            //if (currenValue < minValue || currenValue > maxValue)
            //{
            //    currenValue = (minValue + maxValue) / 2;
            //}
            var widthSpan = 40d;
            var heightSpan = 20d;
            var width = finalSize.Width;
            var height = finalSize.Height;

            if (width < 100d || height < 50d)
            {
                this.Width = width = 100d;
                this.Height = height = 50d;
            }
            var centerX = (width - widthSpan) / 2d + heightSpan;
            var centerY = height - heightSpan + 10d;

            //Single MyWidth, MyHeight;
            //MyWidth = Width - widthSpan;
            //MyHeight = Height - heightSpan;
            //Single DI = 2 * MyHeight;
            //if (MyWidth < MyHeight)
            //{
            //    DI = MyWidth;
            //}

            var degreePerStandKeDu = (720d - 2d * startDegree) / 5d;  //计算出每个标准大刻度之间的角度
            var degreePerKeDu = degreePerStandKeDu / 5d;
            var valuePerKeDu = (maxValue - minValue) / 5;  //每个大刻度之间的值

            //Rectangle MyRect;
            //g = e.Graphics;
            //g.Clear(this.BackColor);
            //g.DrawRectangle(new Pen(Color.Black, 2), 2, 2, this.Width - 4, this.Height - 4);
            _background.SetValue(WidthProperty, width);
            _background.SetValue(HeightProperty, height);

            //MyRect = new Rectangle(0, 0, this.Width, this.Height);
            //g.SmoothingMode = SmoothingMode.AntiAlias;
            ////将绘图平面的坐标原点移到窗口中心
            //g.TranslateTransform(MyWidth / 2 + heightSpan, MyHeight + 10);
            //绘制表盘
            //g.FillEllipse(Brushes.Black,MyRect);
            //string word = currenValue.ToString().Trim() + title;
            //int len = ((word.Trim().Length) * (myFont.Height)) / 2;
            //g.DrawString(word.Trim(), myFont, Brushes.Red, new PointF(-len / 2, -MyHeight / 2 - myFont.Height / 2));
            Size textSize = _text.MeasureTextSize();
            _text.SetValue(Canvas.LeftProperty, centerX - textSize.Width / 2d);
            _text.SetValue(Canvas.TopProperty, centerY - (height - heightSpan - textSize.Height) / 2d);

            //g.RotateTransform(startDegree);
            //绘制刻度标记
            _calibrationCanvas.Children.Clear();
            var calibrationBrush = new SolidColorBrush(Colors.Green);
            _calibrationCanvas.Background = calibrationBrush;
            var calibrationLeft = centerX - 2d;
            var calibrationTop = centerY + 2d - height + heightSpan;
            var calibrationDegree = startDegree;
            var origin = new Point(0.5d, (centerY - calibrationTop) / keduLength);
            for (int x = 0; x < 26; x++)
            {
                //g.FillRectangle(Brushes.Green, new Rectangle(-2, (System.Convert.ToInt16(DI) / 2 - 2) * (-1), keduWidth, keduLength));
                //g.RotateTransform(degreePerKeDu);
                var calibrationLine = new Rectangle();
                calibrationLine.SetValue(Canvas.LeftProperty, calibrationLeft);
                calibrationLine.SetValue(Canvas.TopProperty, calibrationTop);
                calibrationLine.SetValue(WidthProperty, keduWidth);
                calibrationLine.SetValue(HeightProperty, keduLength);
                calibrationLine.Fill = calibrationBrush;
                calibrationLine.RenderTransformOrigin = origin;
                calibrationLine.RenderTransform = new RotateTransform() { Angle = calibrationDegree, };
                _calibrationCanvas.Children.Add(calibrationLine);
                calibrationDegree += degreePerKeDu;
            }
            ////重置绘图平面的坐标变换
            //g.ResetTransform();
            //g.TranslateTransform(MyWidth / 2 + heightSpan, MyHeight + 10);
            //g.RotateTransform(startDegree);
            //mySpeed = minValue;
            ////绘制刻度值
            var speed = minValue;
            var labelBrush = new SolidColorBrush(Colors.Red);
            var lableLineLeft = centerX - 3d;
            var lableLineTop = centerY + 2d - height + heightSpan;
            var labelTop = centerY - (height - heightSpan) + 26d;
            var lableLineDegree = startDegree;
            var lableLineOrigin = new Point(0.5d, (centerY - lableLineTop) / standLength);
            for (int x = 0; x < 6; x++)
            {
                //myString = mySpeed.ToString();
                ////绘制红色刻度
                //g.FillRectangle(Brushes.Red, new Rectangle(-3, (System.Convert.ToInt16(DI) / 2 - 2) * (-1), standWidth, standLength));
                ////绘制数值
                //g.DrawString(myString, myFont, Brushes.Green, new PointF(myString.Length * (-6), -MyHeight + 26));
                ////旋转45度
                //g.RotateTransform(degreePerStandKeDu);
                //mySpeed = mySpeed + valuePerKeDu;

                var lableLine = new Rectangle();
                lableLine.SetValue(Canvas.LeftProperty, lableLineLeft);
                lableLine.SetValue(Canvas.TopProperty, lableLineTop);
                lableLine.SetValue(WidthProperty, standWidth);
                lableLine.SetValue(HeightProperty, standLength);
                lableLine.Fill = labelBrush;
                lableLine.RenderTransformOrigin = lableLineOrigin;
                lableLine.RenderTransform = new RotateTransform() { Angle = lableLineDegree, };
                _calibrationCanvas.Children.Add(lableLine);

                //绘制数值
                var grid = new Grid();
                var label = new TextBlock();
                label.Text = speed.ToString();
                label.FontSize = this.FontSize;
                label.FontFamily = this.FontFamily;
                //label.Foreground = calibrationBrush;
                label.Foreground = this.Foreground;
                Size labelSize = label.MeasureTextSize();
                grid.SetValue(Canvas.LeftProperty, centerX - labelSize.Width / 2d);
                grid.SetValue(Canvas.TopProperty, labelTop);
                grid.RenderTransformOrigin = new Point(0.5d, (centerY - labelTop) / labelSize.Height);
                grid.RenderTransform = new RotateTransform() { Angle = lableLineDegree, };
                grid.Children.Add(label);
                _calibrationCanvas.Children.Add(grid);

                lableLineDegree += degreePerStandKeDu;

                speed += valuePerKeDu;
            }
            ////重置绘图平面坐标变换
            //g.ResetTransform();
            //g.TranslateTransform(MyWidth / 2 + heightSpan, MyHeight + 10);
            ////绘制指针在speed的情形
            var currenValue = CurrenValue;
            int tureValue = currenValue;
            if (currenValue < minValue)
            {
                tureValue = minValue - 1;
            }
            else
                if (currenValue > maxValue)
                {
                    tureValue = maxValue + 1;
                }

            //g.RotateTransform((float)((tureValue - minValue) * (720 - 2 * startDegree) / (maxValue - minValue) + startDegree));
            ////设置线帽
            //myPen = new Pen(Color.Blue, pointWidth);
            //myPen.EndCap = LineCap.ArrowAnchor;
            ////绘制指针
            //g.DrawLine(myPen, new PointF(0, 0), new PointF((float)0, (float)((-1) * (MyHeight / 1.25))));

            var pointerLine = new Line();
            pointerLine.Stroke = new SolidColorBrush(Colors.Blue);
            pointerLine.StrokeThickness = pointWidth;
            //_pointerLine.X1 = 0;
            //_pointerLine.Y1 = 0;
            //_pointerLine.X2 = 0;
            pointerLine.Y2 = (height - heightSpan) / 1.25d;
            pointerLine.StrokeEndLineCap = PenLineCap.Triangle;
            pointerLine.RenderTransformOrigin = new Point(0.5d, 0d);
            pointerLine.RenderTransform = new RotateTransform();
            pointerLine.SetValue(Canvas.LeftProperty, centerX);
            pointerLine.SetValue(Canvas.TopProperty, centerY - pointerLine.Y2);

            var arrowFigure = new PathFigure();
            arrowFigure.StartPoint = new Point(centerX, centerY - pointerLine.Y2 - pointWidth);
            arrowFigure.Segments.Add(new LineSegment() { Point = new Point(centerX - pointWidth,centerY- pointerLine.Y2) });
            arrowFigure.Segments.Add(new LineSegment() { Point = new Point(centerX + pointWidth, centerY -pointerLine.Y2) });
            var arrowGeometry = new PathGeometry();
            arrowGeometry.Figures.Add(arrowFigure);

            var arrowPath = new Path();
            arrowPath.Fill = pointerLine.Stroke;
            arrowPath.Stroke = pointerLine.Stroke;
            arrowPath.Data = arrowGeometry;

            _pointCanvas.Children.Clear();
            _pointCanvas.Height = centerY;
            _pointCanvas.Width = width;
            _pointCanvas.Children.Add(arrowPath);
            _pointCanvas.Children.Add(pointerLine);

            PaintPointer();

            _axisOuterEllipse.Fill = new SolidColorBrush(Colors.Black);
            _axisOuterEllipse.SetValue(Canvas.LeftProperty, centerX - 7d);
            _axisOuterEllipse.SetValue(Canvas.TopProperty, centerY - 7d);
            _axisOuterEllipse.SetValue(WidthProperty, 14d);
            _axisOuterEllipse.SetValue(HeightProperty, 14d);

            _axisInnerEllipse.Fill = new SolidColorBrush(Colors.Red);
            _axisInnerEllipse.SetValue(Canvas.LeftProperty, centerX - 5d);
            _axisInnerEllipse.SetValue(Canvas.TopProperty, centerY - 5d);
            _axisInnerEllipse.SetValue(WidthProperty, 10d);
            _axisInnerEllipse.SetValue(HeightProperty, 10d);

            var radian = 7d * Math.PI / 18d;
            var radius = centerY - calibrationTop;
            var offsetX = radius * Math.Sin(radian);
            var offsetY = radius * Math.Cos(radian);
            var arcSegment = new ArcSegment();
            arcSegment.IsLargeArc = false;
            arcSegment.SweepDirection = SweepDirection.Clockwise;
            arcSegment.Point = new Point(centerX + offsetX, centerY - offsetY);
            arcSegment.Size = new Size(radius, radius);
            var figure = new PathFigure();
            figure.StartPoint = new Point(centerX - offsetX, centerY - offsetY);
            figure.Segments.Add(arcSegment);
            var pathGeometry = new PathGeometry();
            pathGeometry.Figures.Add(figure);

            _arcPath.Stroke = new SolidColorBrush(Color.FromArgb(0xff, 0xBC,0x8F,0x8F));
            _arcPath.StrokeThickness = circleWidth;
            _arcPath.Data = pathGeometry;
            //_arcPath.SetValue(Canvas.LeftProperty, centerX - 100d);
            //_arcPath.SetValue(Canvas.TopProperty, centerY);

            //g.ResetTransform();
            //g.TranslateTransform(MyWidth / 2 + heightSpan, MyHeight + 10);
            ////绘制中心点
            //g.FillEllipse(Brushes.Black, -7, -7, 14, 14);
            //g.FillEllipse(Brushes.Red, -5, -5, 10, 10);
            ////绘制外圆
            //myPen = new Pen(Color.RosyBrown, circleWidth);
            //g.DrawArc(myPen, -MyWidth / 2, -MyHeight, MyWidth, 2 * MyHeight, 200, 140);
            ////g.DrawEllipse(myPen, -MyWidth / 2, -MyHeight, MyWidth, 2 * MyHeight);
        }
示例#22
0
        /// <summary>
        /// Helper method that populates the private variables containing
        /// the UI visuals.
        /// </summary>
        /// <param name="count"></param>
        private void layoutVisuals(int count)
        {
            //double[] centers = new double[count];
            //double widthOne = 30; // this.ActualHeight;
            mainGrid.Children.Clear();
            mainGrid.ColumnDefinitions.Clear();
            for (int i = 0; i < count; i++)
                mainGrid.ColumnDefinitions.Add(new ColumnDefinition());
            canvases.Clear();
            labels.Clear();
            valueLabels.Clear();
            if (count > 0)
            {
                double widthEach = this.ActualWidth / (double)count;
                double offset = (widthEach - widthOne) / 2;
                for (int i = 0; i < count; i++)
                {
                    double left = widthEach * i + offset;
                    //mainVisual.Children.Add(new DrawingVisual());
                    Canvas c = new Canvas()
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment = VerticalAlignment.Center,
                        Width = widthOne,
                        Height = widthOne,
                    };
                    //c.SetValue(Canvas.LeftProperty, left);
                    //c.SetValue(Canvas.TopProperty, 0.0);
                    c.SetValue(Grid.RowProperty, 0);
                    Path p = new Path();
                    if (curColor != null)
                    {
                        p.Fill = Brushes.Transparent;
                        p.Stroke = new SolidColorBrush(Color.FromArgb(128, curColor.R, curColor.G, curColor.B));
                        p.StrokeThickness = -1.0;
                    }
                    c.Children.Add(p);
                    p = new Path();
                    if (curColor != null)
                        p.Fill = new SolidColorBrush(curColor);
                    c.Children.Add(p);
                    int myI = i;
                    c.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e) { valueChangeHelper(myI, e); };
                    canvases.Add(c);

                    TextBlock l = new TextBlock()
                    {
                        VerticalAlignment = VerticalAlignment.Top,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        TextAlignment = TextAlignment.Center,
                        TextWrapping = TextWrapping.WrapWithOverflow,
                        Margin = new Thickness(0),
                        Padding = new Thickness(0),
                        Foreground = Brushes.CadetBlue,
                    };
                    //l.SetValue(Canvas.TopProperty, 0.0);
                    //l.SetValue(Canvas.LeftProperty, 0.0);
                    l.SetValue(Grid.RowProperty, 1);
                    l.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e) { valueChangeHelper(myI, e); };
                    labels.Add(l);

                    Label lv = new Label()
                    {
                        VerticalAlignment = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        Padding = new Thickness(0),
                        Foreground = Brushes.Black,
                        FontSize = 9,
                    };
                    lv.SetValue(Grid.RowProperty, 0);
                    lv.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e) { valueChangeHelper(myI, e); };
                    valueLabels.Add(lv);

                    Grid g = new Grid()
                    {
                        VerticalAlignment = VerticalAlignment.Top,
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                    };
                    g.SetValue(Grid.ColumnProperty, i);
                    g.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                    g.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                    g.Children.Add(c);
                    g.Children.Add(lv);
                    g.Children.Add(l);
                    mainGrid.Children.Add(g);
                }
            }
        }
示例#23
0
 /// <summary>Задать количество строк Grid.</summary>
 /// <param name="grid">Grid в котором задаётся количество строк.</param>
 /// <param name="value">Количестово строк.</param>
 public static void SetRows(System.Windows.Controls.Grid grid, int value)
 {
     grid.SetValue(RowsProperty, value);
 }
示例#24
0
        public void Arrange(Grid grid)
        {
            if (AttachedPane != null)//AttachedPane.IsHidden)
                grid.Children.Add(AttachedPane);
            else if (FirstChildGroup.IsHidden && !SecondChildGroup.IsHidden)
                SecondChildGroup.Arrange(grid);
            else if (!FirstChildGroup.IsHidden && SecondChildGroup.IsHidden)
                FirstChildGroup.Arrange(grid);
            else
            {
                if (Dock == Dock.Left || Dock == Dock.Right)
                {
                    grid.RowDefinitions.Add(new RowDefinition());
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                    //grid.ColumnDefinitions[0].Width = (Dock == Dock.Left) ? new GridLength(AttachedPane.PaneWidth) : new GridLength(1, GridUnitType.Star);
                    //grid.ColumnDefinitions[1].Width = (Dock == Dock.Right) ? new GridLength(AttachedPane.PaneWidth) : new GridLength(1, GridUnitType.Star);
                    grid.ColumnDefinitions[0].Width = (Dock == Dock.Left) ? FirstChildGroup.GroupWidth : new GridLength(1, GridUnitType.Star);
                    grid.ColumnDefinitions[1].Width = (Dock == Dock.Right) ? SecondChildGroup.GroupWidth : new GridLength(1, GridUnitType.Star);

                    //grid.ColumnDefinitions[0].MinWidth = 50;
                    //grid.ColumnDefinitions[1].MinWidth = 50;

                    Grid firstChildGrid = new Grid();
                    firstChildGrid.SetValue(Grid.ColumnProperty, 0);
                    firstChildGrid.Margin = new Thickness(0, 0, 4, 0);
                    FirstChildGroup.Arrange(firstChildGrid);
                    grid.Children.Add(firstChildGrid);

                    Grid secondChildGrid = new Grid();
                    secondChildGrid.SetValue(Grid.ColumnProperty, 1);
                    //secondChildGrid.Margin = (Dock == Dock.Right) ? new Thickness(0, 0, 4, 0) : new Thickness();
                    SecondChildGroup.Arrange(secondChildGrid);
                    grid.Children.Add(secondChildGrid);

                    //AttachedPane.SetValue(Grid.ColumnProperty, (Dock == Dock.Right) ? 1 : 0);
                    //AttachedPane.Margin = (Dock == Dock.Left) ? new Thickness(0, 0, 4, 0) : new Thickness();
                    //grid.Children.Add(AttachedPane);

                    GridSplitter splitter = new GridSplitter();
                    splitter.Width = 4;
                    splitter.HorizontalAlignment = HorizontalAlignment.Right;
                    splitter.VerticalAlignment = VerticalAlignment.Stretch;
                    grid.Children.Add(splitter);
                }
                else // if (Dock == Dock.Top || Dock == Dock.Bottom)
                {
                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                    grid.RowDefinitions.Add(new RowDefinition());
                    grid.RowDefinitions.Add(new RowDefinition());
                    //grid.RowDefinitions[0].Height = (Dock == Dock.Top) ? new GridLength(AttachedPane.PaneHeight) : new GridLength(1, GridUnitType.Star);
                    //grid.RowDefinitions[1].Height = (Dock == Dock.Bottom) ? new GridLength(AttachedPane.PaneHeight) : new GridLength(1, GridUnitType.Star);
                    grid.RowDefinitions[0].Height = (Dock == Dock.Top) ? FirstChildGroup.GroupHeight : new GridLength(1, GridUnitType.Star);
                    grid.RowDefinitions[1].Height = (Dock == Dock.Bottom) ? SecondChildGroup.GroupHeight : new GridLength(1, GridUnitType.Star);

                    grid.RowDefinitions[0].MinHeight = 50;
                    grid.RowDefinitions[1].MinHeight = 50;

                    Grid firstChildGrid = new Grid();
                    //firstChildGrid.SetValue(Grid.RowProperty, (Dock == Dock.Bottom) ? 1 : 0);
                    firstChildGrid.SetValue(Grid.RowProperty, 0);
                    //firstChildGrid.Margin = (Dock == Dock.Bottom) ? new Thickness(0, 0, 0, 4) : new Thickness();
                    firstChildGrid.Margin = new Thickness(0, 0, 0, 4);
                    FirstChildGroup.Arrange(firstChildGrid);
                    grid.Children.Add(firstChildGrid);

                    Grid secondChildGrid = new Grid();
                    //secondChildGrid.SetValue(Grid.RowProperty, (Dock == Dock.Top) ? 1 : 0);
                    secondChildGrid.SetValue(Grid.RowProperty, 1);
                    //secondChildGrid.Margin = (Dock == Dock.Bottom) ? new Thickness(0, 0, 0, 4) : new Thickness();
                    SecondChildGroup.Arrange(secondChildGrid);
                    grid.Children.Add(secondChildGrid);

                    //AttachedPane.SetValue(Grid.RowProperty, (Dock == Dock.Bottom) ? 1 : 0);
                    //AttachedPane.Margin = (Dock == Dock.Top) ? new Thickness(0, 0, 0, 4) : new Thickness();
                    //grid.Children.Add(AttachedPane);

                    GridSplitter splitter = new GridSplitter();
                    splitter.Height = 4;
                    splitter.HorizontalAlignment = HorizontalAlignment.Stretch;
                    splitter.VerticalAlignment = VerticalAlignment.Bottom;
                    grid.Children.Add(splitter);
                }
            }
        }
 public static void SetAutoRowDefinitions(Grid element, AutoRowDefinitions value) { element.SetValue(AutoRowDefinitionsProperty, value); }
        private void DrawLabel(int xFlag1, int yFlag1, int xFlag2, int yFlag2, int levelXGrid, int levelYGrid)
        {
            double cellWidth = WIDTH * xFlag1 / levelXGrid;
            double cellHeight = HEIGHT * yFlag1 / levelYGrid;
            double offsetX = _offsetPositioning.X * WIDTH * xFlag1 * xFlag2 / GridConfig.XSpan;
            double offsetY = _offsetPositioning.Y * HEIGHT * yFlag1 * yFlag2 / GridConfig.YSpan;
            double beginX = offsetX % cellWidth;
            double beginY = offsetY % cellHeight;

            GridPoint gridPoint = new GridPoint();
            for (int row = -1; row <= levelYGrid + 1; row++)
            {
                double y = row * cellHeight + beginY;
                for (int col = -1; col < levelXGrid + 1; col++)
                {
                    var brush = Brushes.White;
                    double x = col * cellWidth + beginX;

                    // 多加 1/2 的值是为了 避免 刚好在边界点因为小数点误差而计算错误
                    gridPoint = TranformPositioning(x - offsetX + cellWidth / 2d, y - offsetY + cellHeight / 2d);

                    if (gridPoint.Y > 0d
                        && gridPoint.X > 0d
                        && gridPoint.Y < GridConfig.YSpan
                        && gridPoint.X < GridConfig.XSpan)
                    {
                        StackPanel stackPanel = new StackPanel();
                        stackPanel.Orientation = Orientation.Horizontal;
                        stackPanel.VerticalAlignment = VerticalAlignment.Center;
                        stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
                        stackPanel.Children.Add(new TextBlock() { Text = "(" });

                        int lv1Index = gridPoint.TranformGridIndex(GridConfig.LEVEL1_X_GRID, GridConfig.LEVEL1_Y_GRID, GridConfig.Level1XCellSpan, GridConfig.Level1YCellSpan);

                        stackPanel.Children.Add(new TextBlock() { Text = lv1Index.ToString(), Foreground = _level1Brush });

                        if (_level > 1)
                        {
                            int lv2Index = gridPoint.TranformGridIndex(GridConfig.LEVEL2_X_GRID, GridConfig.LEVEL2_Y_GRID, GridConfig.Level2XCellSpan, GridConfig.Level2YCellSpan);
                            stackPanel.Children.Add(new TextBlock() { Text = ", " });
                            stackPanel.Children.Add(new TextBlock() { Text = lv2Index.ToString(), Foreground = _level2Brush });
                            if (_level > 2)
                            {
                                int lv3Index = gridPoint.TranformGridIndex(GridConfig.LEVEL3_X_GRID, GridConfig.LEVEL3_Y_GRID, GridConfig.Level3XCellSpan, GridConfig.Level3YCellSpan);

                                stackPanel.Children.Add(new TextBlock() { Text = ", " });
                                stackPanel.Children.Add(new TextBlock() { Text = lv3Index.ToString(), Foreground = _level3Brush });
                                if (_level > 3)
                                {
                                    int lv4Index = gridPoint.TranformGridIndex(GridConfig.LEVEL4_X_GRID, GridConfig.LEVEL4_Y_GRID, GridConfig.Level4XCellSpan, GridConfig.Level4YCellSpan);

                                    stackPanel.Children.Add(new TextBlock() { Text = ", " });
                                    stackPanel.Children.Add(new TextBlock() { Text = lv4Index.ToString(), Foreground = _level4Brush });

                                    if (_gridIndexes.Any(g => g.Index1 == lv1Index && g.Index2 == lv2Index && g.Index3 == lv3Index && g.Index4 == lv4Index))
                                    {
                                        brush = _level4Brush;
                                    }
                                    else if (_gridIndexes.Any(g => g.Index1 == lv1Index && g.Index2 == lv2Index && g.Index3 == lv3Index && !g.Index4.HasValue))
                                    {
                                        brush = _level3Brush;
                                    }
                                    else if (_gridIndexes.Any(g => g.Index1 == lv1Index && g.Index2 == lv2Index && !g.Index3.HasValue))
                                    {
                                        brush = _level2Brush;
                                    }
                                    else if (_gridIndexes.Any(g => g.Index1 == lv1Index && !g.Index2.HasValue))
                                    {
                                        brush = _level1Brush;
                                    }
                                }
                                else if (_gridIndexes.Any(g => g.Index1 == lv1Index && g.Index2 == lv2Index && g.Index3 == lv3Index))
                                {
                                    brush = _level3Brush;
                                }
                                else if (_gridIndexes.Any(g => g.Index1 == lv1Index && g.Index2 == lv2Index && !g.Index3.HasValue))
                                {
                                    brush = _level2Brush;
                                }
                                else if (_gridIndexes.Any(g => g.Index1 == lv1Index && !g.Index2.HasValue))
                                {
                                    brush = _level1Brush;
                                }
                            }
                            else if (_gridIndexes.Any(g => g.Index1 == lv1Index && g.Index2 == lv2Index))
                            {
                                brush = _level2Brush;
                            }
                            else if(_gridIndexes.Any(g => g.Index1 == lv1Index && !g.Index2.HasValue))
                            {
                                brush = _level1Brush;
                            }
                        }
                        else if(_gridIndexes.Any(g=> g.Index1 == lv1Index))
                        {
                            brush = _level1Brush;
                        }
                        stackPanel.Children.Add(new TextBlock() { Text = ")" });

                        Grid grid = new Grid();
                        grid.Children.Add(new Rectangle() { Opacity = brush != Brushes.White ? 0.3d : 1d, Fill = brush });
                        grid.Children.Add(stackPanel);
                        grid.Height = cellHeight;
                        grid.Width = cellWidth;
                        grid.SetValue(Canvas.LeftProperty, x);
                        grid.SetValue(Canvas.TopProperty, y);
                        GridCanvas.Children.Add(grid);
                    }
                }
            }
        }
        void GenerateGroups()
        {
            for(int i = 0; i < 8; i++)
            {
                Border brd = new Border();
                brd.CornerRadius = new CornerRadius(5);
                brd.Margin = new Thickness(2);
                brd.SetValue(Grid.ColumnProperty, i % 4);
                brd.SetValue(Grid.RowProperty, i / 4);

                LinearGradientBrush lgb = new LinearGradientBrush();
                lgb.StartPoint = new Point(0, 0);
                lgb.EndPoint = new Point(1, 1);
                lgb.GradientStops = new GradientStopCollection();
                lgb.GradientStops.Add(new GradientStop() { Offset = 0.0, Color = Color.FromArgb(255, 0, 0, 0)});
                lgb.GradientStops.Add(new GradientStop() { Offset = 0.5, Color = Color.FromArgb(255, 30, 30, 30)});
                lgb.GradientStops.Add(new GradientStop() { Offset = 1.0, Color = Color.FromArgb(255, 40, 40, 40)});
                brd.Background = lgb;

                lgbEven.StartPoint = new Point(0, 0);
                lgbEven.EndPoint = new Point(1, 1);
                lgbEven.GradientStops = new GradientStopCollection();
                lgbEven.GradientStops.Add(new GradientStop() { Offset = 0.0, Color = Color.FromArgb(255, 0, 0, 0) });
                lgbEven.GradientStops.Add(new GradientStop() { Offset = 0.5, Color = Color.FromArgb(255, 30, 30, 30) });
                lgbEven.GradientStops.Add(new GradientStop() { Offset = 1.0, Color = Color.FromArgb(255, 80, 80, 80) });

                Grid grdGroup = new Grid();
                grdGroup.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(28) });
                grdGroup.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                grdGroup.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                grdGroup.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) });
                grdGroup.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) });
                grdGroup.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) });
                grdGroup.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) });

                TextBlock txtGroupID = new TextBlock()
                {
                    Text = ((char)(i + 65)).ToString(),
                    Foreground = new SolidColorBrush(Colors.White),
                    FontSize = 18,
                    FontWeight = FontWeights.Bold
                };
                txtGroupID.SetValue(Grid.ColumnProperty, 0);
                txtGroupID.SetValue(Grid.RowProperty, 0);
                txtGroupID.SetValue(Grid.RowSpanProperty, 4);
                txtGroupID.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center);
                txtGroupID.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
                grdGroup.Children.Add(txtGroupID);

                for (int j = 0; j < 4; j++)
                {
                    Grid grdTeam = new Grid();
                    grdTeam.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    grdTeam.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    grdTeam.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(25) });
                    grdTeam.SetValue(Grid.ColumnProperty, 1);
                    grdTeam.SetValue(Grid.ColumnSpanProperty, 2);
                    grdTeam.SetValue(Grid.RowProperty, j);
                    grdTeam.HorizontalAlignment = HorizontalAlignment.Stretch;
                    grdTeam.VerticalAlignment = VerticalAlignment.Center;
                    grdTeam.Width = 120;

                    Team team = GameHelper.Instance.TeamsDictionary[GameHelper.Instance.TeamCodes[i * 4 + j]];
                    Image img = new Image()
                    {
                        Source = new BitmapImage(new Uri(string.Format(@"http://www.fifa.com/imgml/flags/reflected/m/{0}.png", team.TeamID.ToLower()), UriKind.Absolute)),

                        Width = 28.5,
                        Height = 25.0,
                        VerticalAlignment = VerticalAlignment.Center
                    };
                    img.SetValue(Grid.ColumnProperty, 0);
                    img.SetValue(Grid.RowProperty, j);
                    img.VerticalAlignment = VerticalAlignment.Top;
                    img.HorizontalAlignment = HorizontalAlignment.Stretch;
                    img.Clip = new RectangleGeometry() { Rect = new Rect(new Point(0, 0), new Point(28.5, 14)) };
                    img.Tag = team.TeamID;
                    TranslateTransform tf = new TranslateTransform()
                    {
                         X = 0,
                         Y = 6
                    };
                    img.RenderTransform = tf;

                    TextBlock txt = new TextBlock()
                    {
                        Text = team.TeamName,
                        Foreground = new SolidColorBrush(Colors.White)
                    };
                    txt.SetValue(Grid.ColumnProperty, 1);
                    txt.SetValue(Grid.RowProperty, j);
                    txt.VerticalAlignment = VerticalAlignment.Center;
                    txt.HorizontalAlignment = HorizontalAlignment.Stretch;
                    txt.Tag = team.TeamID;

                    grdTeam.Tag = team.TeamID;
                    grdTeam.Children.Add(img);
                    grdTeam.Children.Add(txt);
                    grdTeam.MouseEnter += new MouseEventHandler(team_MouseEnter);
                    grdTeam.MouseLeave += new MouseEventHandler(team_MouseLeave);
                    grdTeam.MouseLeftButtonUp += new MouseButtonEventHandler(team_MouseLeftButtonUp);

                    grdGroup.Children.Add(grdTeam);
                }

                brd.Child = grdGroup;

                grdGroupsContainer.Children.Add(brd);
            }
        }
        public override void AddConfigUI(System.Windows.Controls.Grid grid)
        {
            TextBlock label;

            #region Header
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            Grid g = new Grid();
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.RowDefinitions.Add(new RowDefinition());
            label = new TextBlock()
            {
                Text = Name,
                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                Margin = new Thickness(2, 10, 2, 2),
                FontWeight = FontWeights.Bold,
                TextTrimming = TextTrimming.WordEllipsis
            };
            g.Children.Add(label);
            g.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            g.SetValue(Grid.ColumnSpanProperty, 2);
            grid.Children.Add(g);
            #endregion

            #region Type
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            label = new TextBlock()
            {
                Text = Resources.Strings.LabelType,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);
            label = new TextBlock()
            {
                Text = Type.ToString(),
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            label.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(label);
            #endregion

            #region Layer name
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            label = new TextBlock()
            {
                Text = Resources.Strings.LabelLayerName,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);
            TextBox tb = new TextBox()
            {
                Text = LayerName,
                Margin = new Thickness(2),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
            };
            tb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            tb.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(tb);
            tb.TextChanged += (s, e) =>
            {
                LayerName = tb.Text;
            };
            #endregion

            #region Popups config
            if (SupportsJobResource && LayerInfos != null && LayerInfos.Count > 0 && LayerInfos.All(l => l.Fields != null && l.Fields.Count > 0))
            {
                grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
                label = new TextBlock()
                {
                    Text = Resources.Strings.LabelPopUps,
                    Margin = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                Button popupButton = new Button
                                        {
                                            Content = new Image
                                            {
                                                Source = new BitmapImage(new Uri("/ESRI.ArcGIS.Mapping.GP;component/Images/Show_Popup16.png", UriKind.Relative)),
                                                Stretch = Stretch.None,
                                                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                                                HorizontalAlignment = System.Windows.HorizontalAlignment.Center
                                            },
                                            Width = 22,
                                            HorizontalAlignment = HorizontalAlignment.Left,
                                            Style = Application.Current.Resources["SimpleButtonStyle"] as Style
                                        };
                ToolTipService.SetToolTip(popupButton, Resources.Strings.ConfigurePopupFieldAliasesAndVisibility);
                popupButton.Click += popupButton_Click;
                popupButton.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                popupButton.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(popupButton);
            }
            #endregion

            #region Opacity
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
            label = new TextBlock()
            {
                Text = Resources.Strings.LabelTransparency,
                Margin = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Top
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);

            ContentControl sliderOpacity = new ContentControl()
            {
                DataContext = this,
                Style = ResourceUtility.LoadEmbeddedStyle("Themes/HorizontalTransparencySlider.xaml", "TransparencySliderStyle")
            };
            sliderOpacity.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            sliderOpacity.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(sliderOpacity);
            #endregion
        }
        /// <summary>
        /// This method constructs the document page (visual) to print
        /// </summary>
        private DocumentPage ConstructPage(Grid content, int pageNumber)
        {
            if (content == null)
                return null;

            //Build the page inc header and footer
            Grid pageGrid = new Grid();

            //Header row
            AddGridRow(pageGrid, GridLength.Auto);

            //Content row
            AddGridRow(pageGrid, new GridLength(1.0d, GridUnitType.Star));

            //Footer row
            AddGridRow(pageGrid, GridLength.Auto);

            ContentControl pageHeader = new ContentControl();
            pageHeader.Content = this.CreateDocumentHeader();
            pageGrid.Children.Add(pageHeader);

            if (content != null)
            {
                content.SetValue(Grid.RowProperty, 1);
                pageGrid.Children.Add(content);
            }

            ContentControl pageFooter = new ContentControl();
            pageFooter.Content = CreateDocumentFooter(pageNumber + 1);
            pageFooter.SetValue(Grid.RowProperty, 2);

            pageGrid.Children.Add(pageFooter);

            double width = this.PageSize.Width - (this.PageMargin.Left + this.PageMargin.Right);
            double height = this.PageSize.Height - (this.PageMargin.Top + this.PageMargin.Bottom);

            pageGrid.Measure(new Size(width, height));
            pageGrid.Arrange(new Rect(this.PageMargin.Left, this.PageMargin.Top, width, height));

            //return new DocumentPage(pageGrid);
            return new DocumentPage(pageGrid, PageSize, new Rect(content.DesiredSize), new Rect(content.DesiredSize));
        }
示例#30
0
        protected void RenderPost(MitbbsPostBase post)
        {
            // Header
            //
            Border headerLine = new Border();
            headerLine.BorderThickness = new Thickness(1);
            headerLine.Margin = new Thickness(0, 10, 0, 0);
            //headerLine.BorderBrush = (Brush)App.Current.Resources["PhoneAccentBrush"];
            headerLine.BorderBrush = new LinearGradientBrush()
            {
                StartPoint = new Point(0, 0),
                EndPoint = new Point(1, 0),
                GradientStops = new GradientStopCollection()
                    {
                        new GradientStop()
                        {
                            Color = ((SolidColorBrush)App.Current.Resources["PhoneAccentBrush"]).Color,
                            Offset = 0
                        },

                        new GradientStop()
                        {
                            Color = ((SolidColorBrush)App.Current.Resources["PhoneSubtleBrush"]).Color,
                            Offset = 0.8
                        },
                        new GradientStop()
                        {
                            Color = ((SolidColorBrush)App.Current.Resources["PhoneBackgroundBrush"]).Color,
                            Offset = 1
                        },
                    }
            };

            //headerLine.BorderBrush = (Brush)App.Current.Resources["PhoneSubtleBrush"];
            //headerLine.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 112, 146, 190));
            headerLine.Height = .5;

            _firstPostControls.Add(headerLine);
            _topicBodyPanel.Children.Add(headerLine);

            StackPanel headerPanel = new StackPanel();
            headerPanel.Orientation = System.Windows.Controls.Orientation.Vertical;

            Grid headerPanel2 = new Grid();
            ColumnDefinition column1 = new ColumnDefinition();
            column1.Width = new GridLength(1, GridUnitType.Star);
            ColumnDefinition column2 = new ColumnDefinition();
            column2.Width = new GridLength(1, GridUnitType.Auto);
            headerPanel2.ColumnDefinitions.Add(column1);
            headerPanel2.ColumnDefinitions.Add(column2);

            Grid expandButtonPanel = new Grid();
            expandButtonPanel.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;

            StackPanel headerPanel3 = new StackPanel();
            headerPanel3.Orientation = System.Windows.Controls.Orientation.Vertical;
            headerPanel3.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;

            Button expandButton = new Button();
            ImageBrush expandButtonImage = new ImageBrush();
            expandButtonImage.ImageSource = new BitmapImage(new Uri("/MitbbsReader;component/Images/overflowdots.png", UriKind.Relative));
            expandButtonImage.Stretch = Stretch.None;
            expandButton.Style = (Style)Application.Current.Resources["ImageButton"];
            expandButton.Content = expandButtonImage;
            expandButton.Padding = new Thickness(0);
            expandButton.BorderThickness = new Thickness(0);
            expandButton.Margin = new Thickness(0);
            expandButton.Width = 93;
            expandButton.Height = 54;

            GestureListener gl = GestureService.GetGestureListener(expandButton);
            gl.Tap += new EventHandler<Microsoft.Phone.Controls.GestureEventArgs>(GeneralButton_Tapped);

            expandButton.Click += ExpandButton_Click;

            headerPanel3.SetValue(Grid.ColumnProperty, 0);
            expandButtonPanel.SetValue(Grid.ColumnProperty, 1);
            headerPanel2.Children.Add(headerPanel3);
            headerPanel2.Children.Add(expandButtonPanel);
            expandButtonPanel.Children.Add(expandButton);

            headerPanel.Children.Add(headerPanel2);

            TextBlock authorText = new TextBlock();
            authorText.Text = "作者: " + post.Author;
            authorText.FontWeight = FontWeights.ExtraBold;
            //authorText.Style = (Style)App.Current.Resources["PhoneTextAccentStyle"];
            authorText.FontSize = (double)App.Current.Resources["MitbbsFontSizeNormal"];
            authorText.Margin = new Thickness(0);
            authorText.TextWrapping = TextWrapping.Wrap;

            TextBlock sourceText = new TextBlock();
            sourceText.Text = "时间: " + post.IssueDate;
            sourceText.FontWeight = FontWeights.ExtraBold;
            //sourceText.Style = (Style)App.Current.Resources["PhoneTextAccentStyle"];
            sourceText.FontSize = (double)App.Current.Resources["MitbbsFontSizeNormal"];
            sourceText.Margin = new Thickness(0);
            sourceText.TextWrapping = TextWrapping.Wrap;

            headerPanel3.Children.Add(authorText);
            headerPanel3.Children.Add(sourceText);

            //Header buttons
            StackPanel buttonPanel = new StackPanel();
            buttonPanel.Orientation = System.Windows.Controls.Orientation.Horizontal;
            buttonPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;

            Border buttonBorder = new Border();
            buttonBorder.BorderBrush = (Brush)App.Current.Resources["PhoneAccentBrush"];
            buttonBorder.BorderThickness = new Thickness(2);
            buttonBorder.CornerRadius = new CornerRadius(3);
            buttonBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            buttonBorder.Visibility = Visibility.Collapsed;
            buttonBorder.Child = buttonPanel;

            //expandButton.DataContext = buttonBorder;
            expandButton.DataContext = post;

            int buttonSize = 72;

            //int buttonCount = 0;

            //if (!_offline && post.ReplyPostUrl != null)
            //{
            //    Button replyButton = new Button();
            //    ImageBrush replyButtonImage = new ImageBrush();
            //    replyButtonImage.ImageSource = new BitmapImage(new Uri("/MitbbsReader;component/Images/reply_roundbutton.png", UriKind.Relative));
            //    replyButtonImage.Stretch = Stretch.None;
            //    replyButton.Style = (Style)Application.Current.Resources["ImageButton"];
            //    replyButton.Content = replyButtonImage;
            //    replyButton.Padding = new Thickness(0);
            //    replyButton.BorderThickness = new Thickness(0);
            //    replyButton.Margin = new Thickness(0);
            //    replyButton.Width = buttonSize;
            //    replyButton.Height = buttonSize;

            //    GestureListener gl2 = GestureService.GetGestureListener(replyButton);
            //    gl2.Tap += new EventHandler<Microsoft.Phone.Controls.GestureEventArgs>(GeneralButton_Tapped);

            //    replyButton.Click += ReplyButton_Click;
            //    replyButton.DataContext = post;
            //    buttonPanel.Children.Add(replyButton);
            //    buttonCount++;
            //}

            //if (!_offline && _showQuickReply && (post.ReplyPostUrl != null))
            //{
            //    Button quickReplyButton = new Button();
            //    ImageBrush quickReplyButtonImage = new ImageBrush();
            //    quickReplyButtonImage.ImageSource = new BitmapImage(new Uri("/MitbbsReader;component/Images/quicksend_roundbutton.png", UriKind.Relative));
            //    quickReplyButtonImage.Stretch = Stretch.None;
            //    quickReplyButton.Style = (Style)Application.Current.Resources["ImageButton"];
            //    quickReplyButton.Content = quickReplyButtonImage;
            //    quickReplyButton.Padding = new Thickness(0);
            //    quickReplyButton.BorderThickness = new Thickness(0);
            //    quickReplyButton.Margin = new Thickness(0);
            //    quickReplyButton.Width = buttonSize;
            //    quickReplyButton.Height = buttonSize;

            //    GestureListener gl2 = GestureService.GetGestureListener(quickReplyButton);
            //    gl2.Tap += new EventHandler<Microsoft.Phone.Controls.GestureEventArgs>(GeneralButton_Tapped);

            //    quickReplyButton.Click += QuickReplyButton_Click;
            //    quickReplyButton.DataContext = post;
            //    buttonPanel.Children.Add(quickReplyButton);
            //    buttonCount++;
            //}

            //if (!_offline && post.ForwardUrl != null)
            //{
            //    Button forwardButton = new Button();
            //    ImageBrush forwardButtonImage = new ImageBrush();
            //    forwardButtonImage.ImageSource = new BitmapImage(new Uri("/MitbbsReader;component/Images/Clipboard-file_roundbutton.png", UriKind.Relative));
            //    forwardButtonImage.Stretch = Stretch.None;
            //    forwardButton.Style = (Style)Application.Current.Resources["ImageButton"];
            //    forwardButton.Content = forwardButtonImage;
            //    forwardButton.Padding = new Thickness(0);
            //    forwardButton.BorderThickness = new Thickness(0);
            //    forwardButton.Margin = new Thickness(0);
            //    forwardButton.Width = buttonSize;
            //    forwardButton.Height = buttonSize;

            //    GestureListener gl2 = GestureService.GetGestureListener(forwardButton);
            //    gl2.Tap += new EventHandler<Microsoft.Phone.Controls.GestureEventArgs>(GeneralButton_Tapped);

            //    forwardButton.Click += ForwardButton_Click;
            //    forwardButton.DataContext = post;
            //    buttonPanel.Children.Add(forwardButton);
            //    buttonCount++;
            //}

            //if (!_offline && _showReplyToUser && (post.AuthorId != null) && !(App.WebSession.IsLoggedIn && App.WebSession.Username.ToLower() == post.AuthorId.ToLower()))
            //{
            //    Button replyUserButton = new Button();
            //    ImageBrush replyUserButtonImage = new ImageBrush();
            //    replyUserButtonImage.ImageSource = new BitmapImage(new Uri("/MitbbsReader;component/Images/contact_roundbutton.png", UriKind.Relative));
            //    replyUserButtonImage.Stretch = Stretch.None;
            //    replyUserButton.Style = (Style)Application.Current.Resources["ImageButton"];
            //    replyUserButton.Content = replyUserButtonImage;
            //    replyUserButton.Padding = new Thickness(0);
            //    replyUserButton.BorderThickness = new Thickness(0);
            //    replyUserButton.Margin = new Thickness(0);
            //    replyUserButton.Width = buttonSize;
            //    replyUserButton.Height = buttonSize;

            //    GestureListener gl2 = GestureService.GetGestureListener(replyUserButton);
            //    gl2.Tap += new EventHandler<Microsoft.Phone.Controls.GestureEventArgs>(GeneralButton_Tapped);

            //    replyUserButton.Click += ReplyUserButton_Click;
            //    replyUserButton.DataContext = post;
            //    buttonPanel.Children.Add(replyUserButton);
            //    buttonCount++;
            //}

            //if (!_offline && App.WebSession.IsLoggedIn && App.WebSession.Username.ToLower() == post.AuthorId.ToLower())
            //{
            //    if (post.DeletePostUrl != null)
            //    {
            //        Button deleteButton = new Button();
            //        ImageBrush deleteButtonImage = new ImageBrush();
            //        deleteButtonImage.ImageSource = new BitmapImage(new Uri("/MitbbsReader;component/Images/trash_roundbutton.png", UriKind.Relative));
            //        deleteButtonImage.Stretch = Stretch.None;
            //        deleteButton.Style = (Style)Application.Current.Resources["ImageButton"];
            //        deleteButton.Content = deleteButtonImage;
            //        deleteButton.Padding = new Thickness(0);
            //        deleteButton.BorderThickness = new Thickness(0);
            //        deleteButton.Margin = new Thickness(0);
            //        deleteButton.Width = buttonSize;
            //        deleteButton.Height = buttonSize;

            //        GestureListener gl2 = GestureService.GetGestureListener(deleteButton);
            //        gl2.Tap += new EventHandler<Microsoft.Phone.Controls.GestureEventArgs>(GeneralButton_Tapped);

            //        deleteButton.Click += DeleteButton_Click;
            //        deleteButton.DataContext = post;
            //        buttonPanel.Children.Add(deleteButton);
            //        buttonCount++;
            //    }
            //}

            //if (!_offline && App.WebSession.IsLoggedIn && App.WebSession.Username.ToLower() == post.AuthorId.ToLower())
            //{
            //    if (post.ModifyPostUrl != null)
            //    {
            //        Button modifyButton = new Button();
            //        ImageBrush modifyButtonImage = new ImageBrush();
            //        modifyButtonImage.ImageSource = new BitmapImage(new Uri("/MitbbsReader;component/Images/edit_roundbutton.png", UriKind.Relative));
            //        modifyButtonImage.Stretch = Stretch.None;
            //        modifyButton.Style = (Style)Application.Current.Resources["ImageButton"];
            //        modifyButton.Content = modifyButtonImage;
            //        modifyButton.Padding = new Thickness(0);
            //        modifyButton.BorderThickness = new Thickness(0);
            //        modifyButton.Margin = new Thickness(0);
            //        modifyButton.Width = buttonSize;
            //        modifyButton.Height = buttonSize;

            //        GestureListener gl2 = GestureService.GetGestureListener(modifyButton);
            //        gl2.Tap += new EventHandler<Microsoft.Phone.Controls.GestureEventArgs>(GeneralButton_Tapped);

            //        modifyButton.Click += ModifyButton_Click;
            //        modifyButton.DataContext = post;
            //        buttonPanel.Children.Add(modifyButton);
            //        buttonCount++;
            //    }
            //}

            //{
            //    Button shareButton = new Button();
            //    ImageBrush shareButtonImage = new ImageBrush();
            //    shareButtonImage.ImageSource = new BitmapImage(new Uri("/MitbbsReader;component/Images/share_roundbutton.png", UriKind.Relative));
            //    shareButtonImage.Stretch = Stretch.None;
            //    shareButton.Style = (Style)Application.Current.Resources["ImageButton"];
            //    shareButton.Content = shareButtonImage;
            //    shareButton.Padding = new Thickness(0);
            //    shareButton.BorderThickness = new Thickness(0);
            //    shareButton.Margin = new Thickness(0);
            //    shareButton.Width = buttonSize;
            //    shareButton.Height = buttonSize;

            //    GestureListener gl2 = GestureService.GetGestureListener(shareButton);
            //    gl2.Tap += new EventHandler<Microsoft.Phone.Controls.GestureEventArgs>(GeneralButton_Tapped);

            //    shareButton.Click += ShareButton_Click;
            //    shareButton.DataContext = post;
            //    buttonPanel.Children.Add(shareButton);
            //    buttonCount++;
            //}

            //if (buttonCount > 0)
            //{
            //    buttonBorder.Width = buttonCount * buttonSize;
            //    headerPanel.Children.Add(buttonBorder);
            //}
            //else
            //{
            //    expandButtonPanel.Visibility = Visibility.Collapsed;
            //}

            _topicBodyPanel.Children.Add(headerPanel);

            // Body
            //
            bool firstContent = true;
            for (int index = 0; index < post.Contents.Count; index++)
            {
                ContentBlock content = post.Contents[index];
                bool isSignature = (post.SignatureStart >= 0) && (index > post.SignatureStart);

                if (content is ImageBlock)
                {
                    String imageUrl = (content as ImageBlock).ImageUrl;

                    try
                    {
                        _imageLoader.LoadImage(
                                        imageUrl,
                                        HtmlUtilities.GetAbsoluteUrl(imageUrl, "/")
                                        );
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.ToString());
                    }
                }
                else if (content is LinkBlock)
                {
                    String url = (content as LinkBlock).Url;
                    if (MitbbsLinkConverter.IsMitbbsFullTopicLink(url))
                    {
                        Button articleButton = new Button();
                        ImageBrush articleButtonImage = new ImageBrush();
                        articleButtonImage.ImageSource = new BitmapImage(new Uri("/MitbbsReader;component/Images/right_roundbutton.png", UriKind.Relative));
                        articleButtonImage.Stretch = Stretch.Uniform;
                        articleButton.Style = (Style)Application.Current.Resources["ImageButton"];
                        articleButton.Content = articleButtonImage;
                        articleButton.Padding = new Thickness(0);
                        articleButton.BorderThickness = new Thickness(0);
                        articleButton.Margin = new Thickness(0);

                        GestureListener gl2 = GestureService.GetGestureListener(articleButton);
                        gl2.Tap += new EventHandler<Microsoft.Phone.Controls.GestureEventArgs>(GeneralButton_Tapped);

                        articleButton.Click += ArticleButton_Click;
                        articleButton.DataContext = content;

                        HyperlinkButton link = new HyperlinkButton();
                        link.SetValue(TiltEffect.IsTiltEnabledProperty, true);
                        link.Click += GeneralLink_Click;
                        link.DataContext = content;
                        link.Content = "打开未名空间文章";
                        link.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                        link.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;

                        Border articlePanelBorder = new Border();
                        articlePanelBorder.BorderBrush = (Brush)App.Current.Resources["PhoneForegroundBrush"];
                        articlePanelBorder.BorderThickness = new Thickness(2);

                        if (isSignature)
                        {
                            articleButton.Width = buttonSize * 2 / 3;
                            articleButton.Height = buttonSize * 2 / 3;
                            articleButton.Foreground = (Brush)App.Current.Resources["PhoneSubtleBrush"];
                            link.FontSize = (double)App.Current.Resources["PhoneFontSizeSmall"];
                            link.Foreground = (Brush)App.Current.Resources["PhoneSubtleBrush"];
                            articlePanelBorder.BorderBrush = (Brush)App.Current.Resources["PhoneSubtleBrush"];
                            articlePanelBorder.BorderThickness = new Thickness(1);
                            articlePanelBorder.Width = 300;
                            articlePanelBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                        }
                        else
                        {
                            articleButton.Width = buttonSize;
                            articleButton.Height = buttonSize;
                            link.FontSize = (double)App.Current.Resources["MitbbsFontSizeText"];
                            articlePanelBorder.BorderBrush = (Brush)App.Current.Resources["PhoneForegroundBrush"];
                            articlePanelBorder.BorderThickness = new Thickness(2);
                            articlePanelBorder.Width = 350;
                        }

                        StackPanel articlePanel = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal };

                        articlePanelBorder.Child = articlePanel;
                        articlePanel.Children.Add(articleButton);
                        articlePanel.Children.Add(link);

                        _topicBodyPanel.Children.Add(articlePanelBorder);
                    }
                    else
                    {
                        HyperlinkButton link = new HyperlinkButton();
                        link.SetValue(TiltEffect.IsTiltEnabledProperty, true);

                        if (isSignature)
                        {
                            link.FontSize = (double)App.Current.Resources["PhoneFontSizeSmall"];
                            link.Foreground = (Brush)App.Current.Resources["PhoneSubtleBrush"];
                        }
                        else
                        {
                            link.FontSize = (double)App.Current.Resources["MitbbsFontSizeText"];
                        }

                        //link.TargetName = "_new";
                        //link.NavigateUri = new Uri((content as LinkBlock).Url, UriKind.Absolute);
                        link.Click += GeneralLink_Click;
                        link.DataContext = content;
                        link.Content = (content as LinkBlock).Text;
                        link.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                        link.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
                        _topicBodyPanel.Children.Add(link);
                    }
                }
                else if (content is VideoBlock)
                {
                    Button playButton = new Button();
                    ImageBrush playButtonImage = new ImageBrush();
                    playButtonImage.ImageSource = new BitmapImage(new Uri("/MitbbsReader;component/Images/play_roundbutton.png", UriKind.Relative));
                    playButtonImage.Stretch = Stretch.Uniform;
                    playButton.Style = (Style)Application.Current.Resources["ImageButton"];
                    playButton.Content = playButtonImage;
                    playButton.Padding = new Thickness(0);
                    playButton.BorderThickness = new Thickness(0);
                    playButton.Margin = new Thickness(0);

                    GestureListener gl2 = GestureService.GetGestureListener(playButton);
                    gl2.Tap += new EventHandler<Microsoft.Phone.Controls.GestureEventArgs>(GeneralButton_Tapped);

                    playButton.Click += PlayButton_Click;
                    playButton.DataContext = content;

                    HyperlinkButton link = new HyperlinkButton();
                    link.SetValue(TiltEffect.IsTiltEnabledProperty, true);

                    Border playPanelBorder = new Border();

                    if (isSignature)
                    {
                        playButton.Width = buttonSize * 2 / 3;
                        playButton.Height = buttonSize * 2 / 3;
                        playButton.Foreground = (Brush)App.Current.Resources["PhoneSubtleBrush"];
                        link.FontSize = (double)App.Current.Resources["PhoneFontSizeSmall"];
                        link.Foreground = (Brush)App.Current.Resources["PhoneSubtleBrush"];
                        playPanelBorder.BorderBrush = (Brush)App.Current.Resources["PhoneSubtleBrush"];
                        playPanelBorder.BorderThickness = new Thickness(1);
                        playPanelBorder.Width = 200;
                        playPanelBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    }
                    else
                    {
                        playButton.Width = buttonSize;
                        playButton.Height = buttonSize;
                        link.FontSize = (double)App.Current.Resources["MitbbsFontSizeText"];
                        playPanelBorder.BorderBrush = (Brush)App.Current.Resources["PhoneForegroundBrush"];
                        playPanelBorder.BorderThickness = new Thickness(2);
                        playPanelBorder.Width = 300;
                    }

                    link.Content = "点击播放视频";
                    link.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    link.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
                    link.DataContext = content;

                    link.Click += VideoLink_Click;

                    StackPanel playPanel = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal };

                    playPanelBorder.Child = playPanel;
                    playPanel.Children.Add(playButton);
                    playPanel.Children.Add(link);

                    _topicBodyPanel.Children.Add(playPanelBorder);
                }
                else if (content is TextContentBlock)
                {
                    String contentText = (content as TextContentBlock).Text;

                    if (firstContent)
                    {
                        if (!contentText.StartsWith("\n"))
                        {
                            contentText = "\n" + contentText;
                        }

                        firstContent = false;
                    }

                    TextBlock tb = new TextBlock();
                    tb.Text = contentText;
                    tb.TextWrapping = TextWrapping.Wrap;

                    if (content is QuoteBlock)
                    {
                        tb.Style = (Style)App.Current.Resources["PhoneTextSubtleStyle"];
                        tb.FontSize = (double)App.Current.Resources["MitbbsFontSizeNormal"];
                        Border bd = new Border();
                        Thickness bdMgn = new Thickness(0);
                        bdMgn.Left = 20;

                        bd.Margin = bdMgn;
                        bd.BorderThickness = new Thickness(1);
                        bd.CornerRadius = new CornerRadius(8);
                        bd.BorderBrush = (Brush)App.Current.Resources["PhoneSubtleBrush"];

                        bd.Child = tb;
                        _topicBodyPanel.Children.Add(bd);
                    }
                    else
                    {
                        if (isSignature)
                        {
                            tb.Style = (Style)App.Current.Resources["PhoneTextSubtleStyle"];
                            tb.FontSize = (double)App.Current.Resources["MitbbsFontSizeNormal"];
                        }

                        _topicBodyPanel.Children.Add(tb);
                    }
                }
            }

            // Padding
            //
            Grid sep = new Grid();
            sep.Margin = new Thickness(10);

            _topicBodyPanel.Children.Add(sep);
        }
示例#31
0
        private void InternalArrange(Grid grid, IPane pane)
        {
            if (pane is UIElement)
            {
                grid.Children.Add(pane as UIElement);
            }
            else if (pane is PaneGroup)
            {
                PaneGroup group = pane as PaneGroup;
                if (group.First.Hidden && !group.Second.Hidden)
                    InternalArrange(grid, group.Second);
                else if (!group.First.Hidden && group.Second.Hidden)
                    InternalArrange(grid, group.First);
                else
                {
                    Grid firstGrid = new Grid();
                    Grid secondGrid = new Grid();

                    if (group.Split == SplitOrientation.Horizontal)
                    {
                        grid.ColumnDefinitions.Add(new ColumnDefinition());
                        grid.RowDefinitions.Add(new RowDefinition());
                        grid.RowDefinitions.Add(new RowDefinition());

                        grid.RowDefinitions[0].Height = group.First.GridHeight;
                        grid.RowDefinitions[1].Height = group.Second.GridHeight;

                        //if (!grid.RowDefinitions[0].Height.IsStar &&
                        //    !grid.RowDefinitions[1].Height.IsStar)
                        //    grid.RowDefinitions[1].Height = new GridLength(1, GridUnitType.Star);

                        firstGrid.SetValue(Grid.ColumnProperty, 0);
                        firstGrid.SetValue(Grid.RowProperty, 0);
                        secondGrid.SetValue(Grid.ColumnProperty, 0);
                        secondGrid.SetValue(Grid.RowProperty, 1);

                        GridSplitter splitter = new GridSplitter();
                        splitter.VerticalAlignment = VerticalAlignment.Top;
                        splitter.HorizontalAlignment = HorizontalAlignment.Stretch;
                        splitter.SetValue(Grid.ColumnProperty, 0);
                        splitter.SetValue(Grid.RowProperty, 1);
                        splitter.Height = 5;
                        secondGrid.Margin = new Thickness(0, 5, 0, 0);

                        grid.Children.Add(firstGrid);
                        grid.Children.Add(splitter);
                        grid.Children.Add(secondGrid);

                        InternalArrange(firstGrid, group.First);
                        InternalArrange(secondGrid, group.Second);
                    }
                    else
                    {
                        grid.ColumnDefinitions.Add(new ColumnDefinition());
                        grid.ColumnDefinitions.Add(new ColumnDefinition());
                        grid.RowDefinitions.Add(new RowDefinition());

                        grid.ColumnDefinitions[0].Width = group.First.GridWidth;
                        grid.ColumnDefinitions[1].Width = group.Second.GridWidth;
                        if (!grid.ColumnDefinitions[0].Width.IsStar &&
                            !grid.ColumnDefinitions[1].Width.IsStar)
                            grid.ColumnDefinitions[1].Width = new GridLength(1, GridUnitType.Star);

                        firstGrid.SetValue(Grid.ColumnProperty, 0);
                        firstGrid.SetValue(Grid.RowProperty, 0);
                        secondGrid.SetValue(Grid.ColumnProperty, 1);
                        secondGrid.SetValue(Grid.RowProperty, 0);

                        GridSplitter splitter = new GridSplitter();
                        splitter.VerticalAlignment = VerticalAlignment.Stretch;
                        splitter.HorizontalAlignment = HorizontalAlignment.Left;
                        splitter.SetValue(Grid.ColumnProperty, 1);
                        splitter.SetValue(Grid.RowProperty, 0);
                        splitter.Width = 5;
                        secondGrid.Margin = new Thickness(5, 0, 0, 0);

                        grid.Children.Add(firstGrid);
                        grid.Children.Add(splitter);
                        grid.Children.Add(secondGrid);

                        InternalArrange(firstGrid, group.First);
                        InternalArrange(secondGrid, group.Second);
                    }
                }
            }
        }
示例#32
0
 /// <summary>
 /// Helper for setting ColumnDefinitions property on a Grid.
 /// </summary>
 /// <param name="element">Grid to set ColumnDefinitions property on.</param>
 /// <param name="value">ColumnDefinitions property value.</param>
 public static void SetColumnDefinitions(System.Windows.Controls.Grid element, ColumnDefinitions value)
 {
     element.SetValue(ColumnDefinitionsProperty, value);
 }