System.Windows.Controls.UIElementCollection.Add(System.Windows.UIElement)

Here are the examples of the csharp api System.Windows.Controls.UIElementCollection.Add(System.Windows.UIElement) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

681 Examples 7

19 Source : TransitionPresenter.cs
with MIT License
from ay2015

internal void OnTransitionCompleted()
        {
            _children.Clear();
            _children.Add(_currentHost);
            _currentHost.Visibility = Visibility.Visible;
            _previousHost.Visibility = Visibility.Visible;
            ((ContentPresenter)_previousHost.Child).Content = null;

            IsTransitioning = false;
            _activeTransition = null;
            CoerceValue(TransitionProperty);
            CoerceValue(ClipToBoundsProperty);
            CoerceValue(ContentProperty);
        }

19 Source : FluidMoveBehavior.cs
with MIT License
from ay2015

internal override void UpdateLayoutTransitionCore(FrameworkElement child, FrameworkElement root, object tag, TagData newTagData)
		{
			bool flag = false;
			bool flag2 = false;
			object initialIdenreplacedyTag = GetInitialIdenreplacedyTag(child);
			TagData value;
			bool flag3 = FluidMoveBehaviorBase.TagDictionary.TryGetValue(tag, out value);
			if (flag3 && value.InitialTag != initialIdenreplacedyTag)
			{
				flag3 = false;
				FluidMoveBehaviorBase.TagDictionary.Remove(tag);
			}
			Rect rect;
			if (!flag3)
			{
				TagData value2;
				if (initialIdenreplacedyTag != null && FluidMoveBehaviorBase.TagDictionary.TryGetValue(initialIdenreplacedyTag, out value2))
				{
					rect = FluidMoveBehaviorBase.TranslateRect(value2.AppRect, root, newTagData.Parent);
					flag = true;
					flag2 = true;
				}
				else
				{
					rect = Rect.Empty;
				}
				TagData tagData = new TagData();
				tagData.ParentRect = Rect.Empty;
				tagData.AppRect = Rect.Empty;
				tagData.Parent = newTagData.Parent;
				tagData.Child = child;
				tagData.Timestamp = DateTime.Now;
				tagData.InitialTag = initialIdenreplacedyTag;
				value = tagData;
				FluidMoveBehaviorBase.TagDictionary.Add(tag, value);
			}
			else if (value.Parent != VisualTreeHelper.GetParent(child))
			{
				rect = FluidMoveBehaviorBase.TranslateRect(value.AppRect, root, newTagData.Parent);
				flag = true;
			}
			else
			{
				rect = value.ParentRect;
			}
			if ((!IsEmptyRect(rect) && !IsEmptyRect(newTagData.ParentRect) && (!IsClose(rect.Left, newTagData.ParentRect.Left) || !IsClose(rect.Top, newTagData.ParentRect.Top))) || (child != value.Child && TransitionStoryboardDictionary.ContainsKey(tag)))
			{
				Rect currentRect = rect;
				bool flag4 = false;
				Storyboard value3 = null;
				if (TransitionStoryboardDictionary.TryGetValue(tag, out value3))
				{
					object overlay2 = GetOverlay(value.Child);
					AdornerContainer adornerContainer = (AdornerContainer)overlay2;
					flag4 = (overlay2 != null);
					FrameworkElement child2 = value.Child;
					if (overlay2 != null)
					{
						Canvas canvas = adornerContainer.Child as Canvas;
						if (canvas != null)
						{
							child2 = (canvas.Children[0] as FrameworkElement);
						}
					}
					if (!flag2)
					{
						Transform transform = GetTransform(child2);
						currentRect = transform.TransformBounds(currentRect);
					}
					TransitionStoryboardDictionary.Remove(tag);
					value3.Stop();
					value3 = null;
					RemoveTransform(child2);
					if (overlay2 != null)
					{
						AdornerLayer.GetAdornerLayer(root).Remove(adornerContainer);
						TransferLocalValue(value.Child, CacheDuringOverlayProperty, UIElement.RenderTransformProperty);
						SetOverlay(value.Child, null);
					}
				}
				object overlay = null;
				if (flag4 || (flag && FloatAbove))
				{
					Canvas canvas2 = new Canvas();
					canvas2.Width = newTagData.ParentRect.Width;
					canvas2.Height = newTagData.ParentRect.Height;
					canvas2.IreplacedTestVisible = false;
					Canvas canvas3 = canvas2;
					Rectangle rectangle = new Rectangle();
					rectangle.Width = newTagData.ParentRect.Width;
					rectangle.Height = newTagData.ParentRect.Height;
					rectangle.IreplacedTestVisible = false;
					Rectangle rectangle2 = rectangle;
					rectangle2.Fill = new VisualBrush(child);
					canvas3.Children.Add(rectangle2);
					AdornerContainer adornerContainer2 = new AdornerContainer(child);
					adornerContainer2.Child = canvas3;
					AdornerContainer adorner = (AdornerContainer)(overlay = adornerContainer2);
					SetOverlay(child, overlay);
					AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(root);
					adornerLayer.Add(adorner);
					TransferLocalValue(child, UIElement.RenderTransformProperty, CacheDuringOverlayProperty);
					child.RenderTransform = new TranslateTransform(-10000.0, -10000.0);
					canvas3.RenderTransform = new TranslateTransform(10000.0, 10000.0);
					child = rectangle2;
				}
				Rect layoutRect = newTagData.ParentRect;
				Storyboard transitionStoryboard = CreateTransitionStoryboard(child, flag2, ref layoutRect, ref currentRect);
				TransitionStoryboardDictionary.Add(tag, transitionStoryboard);
				transitionStoryboard.Completed += delegate
				{
					Storyboard value4;
					if (TransitionStoryboardDictionary.TryGetValue(tag, out value4) && value4 == transitionStoryboard)
					{
						TransitionStoryboardDictionary.Remove(tag);
						transitionStoryboard.Stop();
						RemoveTransform(child);
						child.InvalidateMeasure();
						if (overlay != null)
						{
							AdornerLayer.GetAdornerLayer(root).Remove((AdornerContainer)overlay);
							TransferLocalValue(child, CacheDuringOverlayProperty, UIElement.RenderTransformProperty);
							SetOverlay(child, null);
						}
					}
				};
				transitionStoryboard.Begin();
			}
			value.ParentRect = newTagData.ParentRect;
			value.AppRect = newTagData.AppRect;
			value.Parent = newTagData.Parent;
			value.Child = newTagData.Child;
			value.Timestamp = newTagData.Timestamp;
		}

19 Source : BayoenMessage.cs
with MIT License
from bayoen

public void Initialize()
        {
            this.Orientation = Orientation.Horizontal;
            this.Margin = new Thickness(5);

            this.HeaderImage = new Image()
            {
                Height = 100,
                Width = 100,
                Margin = new Thickness(5),
                VerticalAlignment = VerticalAlignment.Top,
            };
            RenderOptions.SetBitmapScalingMode(this.HeaderImage, BitmapScalingMode.Fant);
            this.Children.Add(this.HeaderImage);

            this.MessageStackPanel = new StackPanel()
            {
                Orientation = Orientation.Vertical,
            };
            this.Children.Add(this.MessageStackPanel);

            this.HeaderTextBlock = new TextBlock()
            {
                FontSize = 14,
                Margin = new Thickness(20, 0, 0, 0),
                HorizontalAlignment = HorizontalAlignment.Left,
            };
            this.MessageStackPanel.Children.Add(this.HeaderTextBlock);

            this.MessageGrid = new Grid()
            {
                Margin = new Thickness(5),
            };
            this.MessageStackPanel.Children.Add(this.MessageGrid);

            this.MessageTextBlock = new TextBlock()
            {
                FontSize = 12,
                Margin = new Thickness(10),
                MaxWidth = 200,
                TextWrapping = TextWrapping.Wrap,
            };
            this.MessageColl = new ObservableCollection<string>();
            this.MessageColl.CollectionChanged += MessageColl_CollectionChanged;

            this.MessageBorder = new Border()
            {
                Child = this.MessageTextBlock,
                CornerRadius = new CornerRadius(0, 10, 10, 10),
                BorderBrush = Brushes.White,
                BorderThickness = new Thickness(2),
                Margin = new Thickness(15, 0, 0, 0),
            };
            this.MessageGrid.Children.Add(this.MessageBorder);

            this.ModifyingPolyline = new Polyline()
            {
                Points = new PointCollection()
                    {
                        new Point(15,0),
                        new Point(15,15),
                    },
                Stroke = new SolidColorBrush(Color.FromRgb(37, 37, 37)),
                StrokeThickness = 2,
                Margin = new Thickness(1, 1, 0, 0),
            };
            this.MessageGrid.Children.Add(this.ModifyingPolyline);

            this.TimeTextBlock = new TextBlock()
            {
                FontSize = 12,
                Margin = new Thickness(0, 0, 0, 7),
                VerticalAlignment = VerticalAlignment.Bottom,
            };
            this.Children.Add(this.TimeTextBlock);

            this.TailPolyline = new Polyline()
            {
                Points = new PointCollection()
                    {
                        new Point(16,0),
                        new Point(0,0),
                        new Point(15,15),

                    },
                Stroke = Brushes.White,
                StrokeThickness = 2,
                Margin = new Thickness(1, 1, 0, 0),
            };
            this.MessageGrid.Children.Add(this.TailPolyline);

            this._messageDirection = BayoenMessageDirection.Null;
            this.MessageDirection = BayoenMessageDirection.Left;
        }

19 Source : TabControlEx.cs
with Apache License 2.0
from beckzhu

private ContentPresenter CreateChildContentPresenter(object item)
        {
            if (item == null)
            {
                return null;
            }

            ContentPresenter cp = this.FindChildContentPresenter(item);

            if (cp != null)
            {
                return cp;
            }

            // the actual child to be added.  cp.Tag is a reference to the TabItem
            var tabItem = item as TabItem;
            cp = new ContentPresenter();
            cp.Content = tabItem != null ? tabItem.Content : item;
            cp.ContentTemplate = this.SelectedContentTemplate;
            cp.ContentTemplateSelector = this.SelectedContentTemplateSelector;
            cp.ContentStringFormat = this.SelectedContentStringFormat;
            cp.Visibility = this.ChildContentVisibility;
            cp.Tag = tabItem ?? this.ItemContainerGenerator.ContainerFromItem(item);
            this._itemsHolder.Children.Add(cp);
            return cp;
        }

19 Source : TiltBehavior.cs
with Apache License 2.0
from beckzhu

protected override void OnAttached()
        {
            attachedElement = replacedociatedObject;
            if (attachedElement is ListBox)
            {
                return;
            }

            var attachedElementPanel = attachedElement as Panel;
            if (attachedElementPanel != null)
            {
                attachedElementPanel.Loaded += (sl, el) =>
                {
                    var elements = attachedElementPanel.Children.Cast<UIElement>().ToList();

                    elements.ForEach(element =>
                        Interaction.GetBehaviors(element).Add(
                            new TiltBehavior
                            {
                                KeepDragging = KeepDragging,
                                TiltFactor = TiltFactor
                            }));
                };

                return;
            }

            originalPanel = attachedElement.Parent as Panel ?? GetParentPanel(attachedElement);

            originalMargin = attachedElement.Margin;
            originalSize = new Size(attachedElement.Width, attachedElement.Height);
            double left = Canvas.GetLeft(attachedElement);
            double right = Canvas.GetRight(attachedElement);
            double top = Canvas.GetTop(attachedElement);
            double bottom = Canvas.GetBottom(attachedElement);
            int z = Panel.GetZIndex(attachedElement);
            VerticalAlignment va = attachedElement.VerticalAlignment;
            HorizontalAlignment ha = attachedElement.HorizontalAlignment;

            RotatorParent = new Planerator
            {
                Margin = originalMargin,
                Width = originalSize.Width,
                Height = originalSize.Height,
                VerticalAlignment = va,
                HorizontalAlignment = ha
            };

            RotatorParent.SetValue(Canvas.LeftProperty, left);
            RotatorParent.SetValue(Canvas.RightProperty, right);
            RotatorParent.SetValue(Canvas.TopProperty, top);
            RotatorParent.SetValue(Canvas.BottomProperty, bottom);
            RotatorParent.SetValue(Panel.ZIndexProperty, z);

            originalPanel.Children.Remove(attachedElement);
            attachedElement.Margin = new Thickness();
            attachedElement.Width = double.NaN;
            attachedElement.Height = double.NaN;

            originalPanel.Children.Add(RotatorParent);
            RotatorParent.Child = attachedElement;

            CompositionTarget.Rendering += CompositionTargetRendering;
        }

19 Source : SettingControl.cs
with Apache License 2.0
from beckzhu

public void AddUtilityButton(Grid grid, int row, int column, int rowSpan = 1, int columnSpan = 1)
        {
            DefaultButton button = new DefaultButton();
            Grid.SetRow(button, row);
            Grid.SetColumn(button, column);
            Grid.SetRowSpan(button, rowSpan);
            Grid.SetColumnSpan(button, columnSpan);
            grid.Children.Add(button);
            button.PART_Reset.Click += PART_Reset_Click;
            button.PART_Default.Click += PART_Default_Click;
        }

19 Source : RemoteTabControl.xaml.cs
with Apache License 2.0
from beckzhu

public void Open(DbItemRemoteLink linkSettings, DbItemSetting itemSetting, bool jump)
        {
            _tabItem = MainWindow.AddTabItem(linkSettings.Name, this, jump);
            if (linkSettings.Preplacedword == null) linkSettings.Preplacedword = "";
            _tabItem.Closed = _tabItem_Closed;

            try
            {
                if (linkSettings.Type == (int)RemoteType.rdp)
                {
                    _remoteControl = new RemoteControl_rdp(this);
                }
                if (linkSettings.Type == (int)RemoteType.ssh)
                {
                    _remoteControl = new RemoteControl_ssh(this);
                }
                if (linkSettings.Type == (int)RemoteType.telnet)
                {
                    _remoteControl = new RemoteControl_telnet(this);
                }
                if (_remoteControl == null)
                {
                    throw new Exception("可能是不支持的远程连接类型。");
                }
                _remoteControl.Visibility = Visibility.Collapsed;
                Panel_Animation.Visibility = Visibility.Visible;
                Grid.Children.Add(_remoteControl);

                _remoteControl.OnConnected = _remoteControl_OnConnected;
                _remoteControl.OnFatalError = OnFatalError;
                _remoteControl.OnNonfatal = OnNonfatal;
                _remoteControl.Closed = Remove;
                _remoteControl.FullScreen = FullScreen;
                _remoteControl.MouseMoveProc = MouseMoveProc;

                _remoteControl.Connect(linkSettings, itemSetting.GetLastSetting());
                _startFullScreen = itemSetting.GetIsFullscreen();
                _fullScreenWindow.Connectionreplacedle = linkSettings.Name;
               
            }
            catch (Exception e)
            {
                OnFatalError("错误", $"远程桌面连接失败。\n原因:{e.Message}");
            }
        }

19 Source : RemoteTabControl.xaml.cs
with Apache License 2.0
from beckzhu

public bool FullScreen(bool state)
        {
            if (!_isConntec) return false;
            if (_fullScreen == state) return true;

            _fullScreen = state;
            if (state)
            {
                Grid.Children.Remove(_remoteControl);
                _fullScreenWindow.Content = _remoteControl;
                _fullScreenWindow.Show();
                Button_ExitFull.Visibility = Visibility.Visible;
            }
            else
            {
                _fullScreenWindow.Visibility = Visibility.Collapsed;
                _fullScreenWindow.Content = null;
                Grid.Children.Add(_remoteControl);
                Button_ExitFull.Visibility = Visibility.Collapsed;
            }
            _remoteControl.GoFullScreen(state);
            return true;
        }

19 Source : RemoteWinControl.xaml.cs
with Apache License 2.0
from beckzhu

public void Open(DbItemRemoteLink linkSettings, DbItemSetting itemSetting, bool jump)
        {
            _itemRemoteLink = linkSettings;
            if (linkSettings.Preplacedword == null) linkSettings.Preplacedword = "";

            replacedle = linkSettings.Name;
            Window mainWindow = Application.Current.MainWindow;
            Width = linkSettings.ExternalWindowWidth > MinWidth ? linkSettings.ExternalWindowWidth : mainWindow.Width;
            Height = linkSettings.ExternalWindowHeight > MinHeight ? linkSettings.ExternalWindowHeight : mainWindow.Height;

            try
            {
                Show();
                if (linkSettings.Type == (int)RemoteType.rdp)
                {
                    _remoteControl = new RemoteControl_rdp(this);
                }
                if (linkSettings.Type == (int)RemoteType.ssh)
                {
                    _remoteControl = new RemoteControl_ssh(this);
                }
                if (linkSettings.Type == (int)RemoteType.telnet)
                {
                    _remoteControl = new RemoteControl_telnet(this);
                }
                if (_remoteControl == null)
                {
                    throw new Exception("可能是不支持的远程连接类型。");
                }
                _remoteControl.Visibility = Visibility.Collapsed;
                Panel_Animation.Visibility = Visibility.Visible;
                Grid.Children.Add(_remoteControl);

                _remoteControl.OnConnected = _remoteControl_OnConnected;
                _remoteControl.OnFatalError = OnFatalError;
                _remoteControl.OnNonfatal = OnNonfatal;
                _remoteControl.Closed = Remove;
                _remoteControl.FullScreen = FullScreen;
                _remoteControl.MouseMoveProc = MouseMoveProc;

                _remoteControl.Connect(linkSettings, itemSetting.GetLastSetting());
                _startFullScreen = itemSetting.GetIsFullscreen();
            }
            catch (Exception e)
            {
                OnFatalError("错误", $"远程桌面连接失败。\n原因:{e.Message}");
            }
        }

19 Source : RemoteWinControl.xaml.cs
with Apache License 2.0
from beckzhu

public bool FullScreen(bool state)
        {
            if (!_isConntec) return false;
            if (_fullScreen == state) return true;

            _fullScreen = state;
            if (state)
            {
                Grid.Children.Remove(_remoteControl);
                _fullScreenWindow.Content = _remoteControl;
                _fullScreenWindow.Show();
                Button_ExitFull.Visibility = Visibility.Visible;
            }
            else
            {
                _fullScreenWindow.Visibility = Visibility.Collapsed;
                _fullScreenWindow.Content = null;
                Grid.Children.Add(_remoteControl);
                Button_ExitFull.Visibility = Visibility.Collapsed;
            }

            _remoteControl.GoFullScreen(state);
            return true;
        }

19 Source : DragDrop.cs
with Apache License 2.0
from beckzhu

private static void CreateDragAdorner(DropInfo dropInfo)
        {
            var dragInfo = m_DragInfo;
            var template = GetDragAdornerTemplate(dragInfo.VisualSource);
            var templateSelector = GetDragAdornerTemplateSelector(dragInfo.VisualSource);

            UIElement adornment = null;

            var useDefaultDragAdorner = GetUseDefaultDragAdorner(dragInfo.VisualSource);
            var useVisualSourceItemSizeForDragAdorner = GetUseVisualSourceItemSizeForDragAdorner(dragInfo.VisualSource);

            if (template == null && templateSelector == null && useDefaultDragAdorner)
            {
                var bs = CaptureScreen(dragInfo.VisualSourceItem, dragInfo.VisualSourceFlowDirection);
                if (bs != null)
                {
                    var factory = new FrameworkElementFactory(typeof(Image));
                    factory.SetValue(Image.SourceProperty, bs);
                    factory.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
                    factory.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
                    factory.SetValue(FrameworkElement.WidthProperty, bs.Width);
                    factory.SetValue(FrameworkElement.HeightProperty, bs.Height);
                    factory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                    factory.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Top);
                    template = new DataTemplate { VisualTree = factory };
                }
            }

            if (template != null || templateSelector != null)
            {
                if (dragInfo.Data is IEnumerable && !(dragInfo.Data is string))
                {
                    if (!useDefaultDragAdorner && ((IEnumerable)dragInfo.Data).Cast<object>().Count() <= 10)
                    {
                        var itemsControl = new ItemsControl();
                        itemsControl.ItemsSource = (IEnumerable)dragInfo.Data;
                        itemsControl.ItemTemplate = template;
                        itemsControl.ItemTemplateSelector = templateSelector;

                        if (useVisualSourceItemSizeForDragAdorner)
                        {
                            var bounds = VisualTreeHelper.GetDescendantBounds(dragInfo.VisualSourceItem);
                            itemsControl.SetValue(FrameworkElement.MinWidthProperty, bounds.Width);
                        }

                        // The ItemsControl doesn't display unless we create a grid to contain it.
                        // Not quite sure why we need this...
                        var grid = new Grid();
                        grid.Children.Add(itemsControl);
                        adornment = grid;
                    }
                }
                else
                {
                    var contentPresenter = new ContentPresenter();
                    contentPresenter.Content = dragInfo.Data;
                    contentPresenter.ContentTemplate = template;
                    contentPresenter.ContentTemplateSelector = templateSelector;

                    if (useVisualSourceItemSizeForDragAdorner)
                    {
                        var bounds = VisualTreeHelper.GetDescendantBounds(dragInfo.VisualSourceItem);
                        contentPresenter.SetValue(FrameworkElement.MinWidthProperty, bounds.Width);
                        contentPresenter.SetValue(FrameworkElement.MinHeightProperty, bounds.Height);
                    }

                    adornment = contentPresenter;
                }
            }

            if (adornment != null)
            {
                if (useDefaultDragAdorner)
                {
                    adornment.Opacity = GetDefaultDragAdornerOpacity(dragInfo.VisualSource);
                }

                var rootElement = RootElementFinder.FindRoot(dropInfo.VisualTarget ?? dragInfo.VisualSource);
                DragAdorner = new DragAdorner(rootElement, adornment, GetDragAdornerTranslation(dragInfo.VisualSource));
            }
        }

19 Source : VBExtension.cs
with BSD 2-Clause "Simplified" License
from bhoogter

public static BitmapImage setImage(this Button Cmd, BitmapImage value)
    {
        try
        {
            if (Cmd.Content is string)
            {
                string caption = Cmd.Content.ToString();
                Canvas C = new Canvas();
                Cmd.Content = C;
                C.Width = Cmd.Width;
                C.Height = Cmd.Height;
                Label L = new Label();
                L.Content = caption;
                C.Children.Add(L);
                L.FontSize = 12d;
                L.Padding = new Thickness(0);
                L.Width = L.MeasureString(caption).Width;
                L.Height = L.MeasureString(caption).Height;
                Canvas.SetLeft(L, (Cmd.Width - L.Width) / 2);
                Canvas.SetTop(L, Cmd.Height - L.Height - 10);
                Image I = new Image();
                C.Children.Add(I);
                I.Width = Cmd.Width - 10;
                I.Height = Cmd.Height - L.Height - 12;
                I.Stretch = System.Windows.Media.Stretch.Uniform;
                I.Source = value;
                Canvas.SetLeft(I, (Cmd.Width - I.Width) / 2);
                Canvas.SetTop(I, 0);
                return value;
            }
            else if (Cmd.Content is Panel)
            {
                Image I = (Image)((Panel)Cmd.Content).ControlOf(typeof(Image), 0);
                if (I == null) return null;
                I.Source = value;
                return value;
            }
            else if (Cmd.Content is Image)
            {
                ((Image)Cmd.Content).Source = value;
                return value;
            }
        }
        catch { return null; }
        return null;
    }

19 Source : VBExtension.cs
with BSD 2-Clause "Simplified" License
from bhoogter

public static FrameworkElement loadControlByIndex(this Window Frm, Type type, string Name, int Idx = -1)
    {
        FrameworkElement X = Frm.getControlByIndex(Name, Idx);
        if (X != null) return X;
        FrameworkElement C = (FrameworkElement)Activator.CreateInstance(type);
        C.Name = Name + "_" + Idx;
        List<FrameworkElement> els = controlArray(Frm, Name);
        Panel G;
        FrameworkElement el0 = getControlByIndex(Frm, Name, 0);
        if (els.Count > 0) G = els[0].Parent as Panel;
        else if (el0 != null) G = el0.Parent as Panel;
        else G = Frm.Content as Panel;
        G.Children.Add(C);
        return C;
    }

19 Source : PieChartLabel.cs
with MIT License
from bstollnitz

private void PositionConnected()
        {
            this.RemovePolyline();

            if (this.contentPart != null)
            {
                PointCollection newPoints = new PointCollection();

                // First point
                newPoints.Add(this.SnapPoint(this.arcMidpoint));

                // Second point
                Vector radialDirection = this.arcMidpoint - this.center;
                radialDirection.Normalize();
                Point secondPoint = this.arcMidpoint + (radialDirection * 10);
                newPoints.Add(this.SnapPoint(secondPoint));

                // Third point
                int sign = Math.Sign(radialDirection.X); // 1 if label is on the right side, -1 if it's on the left.
                Point thirdPoint = secondPoint + new Vector(sign * 20, 0);
                newPoints.Add(this.SnapPoint(thirdPoint));

                double contentX = (sign == 1) ? thirdPoint.X : thirdPoint.X - this.contentPart.DesiredSize.Width;
                double contentY = thirdPoint.Y - 0.5 * this.contentPart.DesiredSize.Height;
                Canvas.SetTop(this.contentPart, contentY);
                Canvas.SetLeft(this.contentPart, contentX);

                Polyline polyline = new Polyline();
                polyline.Points = newPoints;
                polyline.SetBinding(Polyline.StrokeThicknessProperty, new Binding("LineStrokeThickness") { Source = this });
                polyline.SetBinding(Polyline.StrokeProperty, new Binding("LineStroke") { Source = this });
                polyline.StrokeLineJoin = PenLineJoin.Round;

                this.canvasPart.Children.Add(polyline);
            }
        }

19 Source : PieLabelBehavior.cs
with MIT License
from bstollnitz

private static void AddLabel(PieDataPoint pieDataPoint, Canvas labelArea)
        {
            PieChartLabel label = new PieChartLabel();

            Style pieChartLabelStyle;
            DataTemplate pieChartLabelItemTemplate;
            LabeledPieChart chart = TreeHelper.FindAncestor<LabeledPieChart>(pieDataPoint);
            if (chart != null)
            {
                pieChartLabelStyle = chart.PieChartLabelStyle;
                if (pieChartLabelStyle != null)
                {
                    label.Style = pieChartLabelStyle;
                }
                pieChartLabelItemTemplate = chart.PieChartLabelItemTemplate;
                if (pieChartLabelItemTemplate != null)
                {
                    label.ContentTemplate = pieChartLabelItemTemplate;
                }
            }

            Binding contentBinding = new Binding("DataContext") { Source = pieDataPoint };
            label.SetBinding(ContentControl.ContentProperty, contentBinding);

            Binding dataContextBinding = new Binding("DataContext") { Source = pieDataPoint };
            label.SetBinding(ContentControl.DataContextProperty, contentBinding);

            Binding formattedRatioBinding = new Binding("FormattedRatio") { Source = pieDataPoint };
            label.SetBinding(PieChartLabel.FormattedRatioProperty, formattedRatioBinding);

            Binding visibilityBinding = new Binding("Ratio") { Source = pieDataPoint, Converter = new DoubleToVisibilityConverter() };
            label.SetBinding(PieChartLabel.VisibilityProperty, visibilityBinding);

            Binding geometryBinding = new Binding("Geometry") { Source = pieDataPoint };
            label.SetBinding(PieChartLabel.GeometryProperty, geometryBinding);

            Binding displayModeBinding = new Binding("LabelDisplayMode") { Source = chart };
            label.SetBinding(PieChartLabel.DisplayModeProperty, displayModeBinding);

            labelArea.Children.Add(label);
            pieDataPoint.Unloaded += delegate
            {
                labelArea.Children.Remove(label);
            };

            pieDataPoint.Loaded += delegate
            {
                if (label.Parent == null)
                {
                    labelArea.Children.Add(label);
                }
            };
        }

19 Source : PieLabelBehavior.cs
with MIT License
from bstollnitz

private static void AddLabel(PieDataPoint pieDataPoint, Panel labelArea)
        {
            PieChartLabel label = new PieChartLabel();

            Style pieChartLabelStyle;
            DataTemplate pieChartLabelItemTemplate;
            LabeledPieChart chart = TreeHelper.FindAncestor<LabeledPieChart>(pieDataPoint);
            if (chart != null)
            {
                pieChartLabelStyle = chart.PieChartLabelStyle;
                if (pieChartLabelStyle != null)
                {
                    label.Style = pieChartLabelStyle;
                }
                pieChartLabelItemTemplate = chart.PieChartLabelItemTemplate;
                if (pieChartLabelItemTemplate != null)
                {
                    label.ContentTemplate = pieChartLabelItemTemplate;
                }
            }

            Binding contentBinding = new Binding("DataContext") { Source = pieDataPoint };
            label.SetBinding(ContentControl.ContentProperty, contentBinding);

            Binding dataContextBinding = new Binding("DataContext") { Source = pieDataPoint };
            label.SetBinding(ContentControl.DataContextProperty, contentBinding);

            Binding formattedRatioBinding = new Binding("FormattedRatio") { Source = pieDataPoint };
            label.SetBinding(PieChartLabel.FormattedRatioProperty, formattedRatioBinding);

            Binding visibilityBinding = new Binding("Ratio") { Source = pieDataPoint, Converter = new DoubleToVisibilityConverter() };
            label.SetBinding(PieChartLabel.VisibilityProperty, visibilityBinding);

            Binding geometryBinding = new Binding("Geometry") { Source = pieDataPoint };
            label.SetBinding(PieChartLabel.GeometryProperty, geometryBinding);

            Binding displayModeBinding = new Binding("LabelDisplayMode") { Source = chart };
            label.SetBinding(PieChartLabel.DisplayModeProperty, displayModeBinding);

            labelArea.Children.Add(label);

            pieDataPoint.Loaded += delegate
            {
                if (label.Parent == null)
                {
                    labelArea.Children.Add(label);
                }
            };

            pieDataPoint.LayoutUpdated += delegate
            {
                if (!pieDataPoint.IsInTree())
                {
                    labelArea.Children.Remove(label);
                }
            };

            //pieDataPoint.Unloaded += delegate
            //{
            //    labelArea.Children.Remove(label);
            //};

        }

19 Source : LabeledPieSeries.cs
with MIT License
from bstollnitz

private void AddLabelPieDataPoint(PieDataPoint pieDataPoint, Panel labelArea)
		{
			PieChartLabel label = new PieChartLabel();
			label.Style = this.PieChartLabelStyle;

			Binding contentBinding = new Binding("DataContext") { Source = pieDataPoint };
			label.SetBinding(ContentControl.ContentProperty, contentBinding);

			Binding dataContextBinding = new Binding("DataContext") { Source = pieDataPoint };
			label.SetBinding(ContentControl.DataContextProperty, contentBinding);

			Binding formattedRatioBinding = new Binding("FormattedRatio") { Source = pieDataPoint };
			label.SetBinding(PieChartLabel.FormattedRatioProperty, formattedRatioBinding);

			Binding visibilityBinding = new Binding("Ratio") { Source = pieDataPoint, Converter = new DoubleToVisibilityConverter() };
			label.SetBinding(PieChartLabel.VisibilityProperty, visibilityBinding);

			Binding geometryBinding = new Binding("Geometry") { Source = pieDataPoint };
			label.SetBinding(PieChartLabel.GeometryProperty, geometryBinding);

			Binding displayModeBinding = new Binding("LabelDisplayMode") { Source = this };
			label.SetBinding(PieChartLabel.DisplayModeProperty, displayModeBinding);

			labelArea.Children.Add(label);

			pieDataPoint.Loaded += delegate
			{
				if (label.Parent == null)
				{
					labelArea.Children.Add(label);
				}
			};

			pieDataPoint.LayoutUpdated += delegate
			{
				if (!pieDataPoint.IsInTree())
				{
					labelArea.Children.Remove(label);
				}
			};
		}

19 Source : LabeledPieSeries.cs
with MIT License
from bstollnitz

private void AddLabelPieDataPoint(PieDataPoint pieDataPoint, Canvas labelArea)
		{
			PieChartLabel label = new PieChartLabel();
			label.Style = this.PieChartLabelStyle;
			label.ContentTemplate = this.PieChartLabelItemTemplate;

			Binding contentBinding = new Binding("DataContext") { Source = pieDataPoint };
			label.SetBinding(ContentControl.ContentProperty, contentBinding);

			Binding dataContextBinding = new Binding("DataContext") { Source = pieDataPoint };
			label.SetBinding(ContentControl.DataContextProperty, contentBinding);

			Binding formattedRatioBinding = new Binding("FormattedRatio") { Source = pieDataPoint };
			label.SetBinding(PieChartLabel.FormattedRatioProperty, formattedRatioBinding);

			Binding visibilityBinding = new Binding("Ratio") { Source = pieDataPoint, Converter = new DoubleToVisibilityConverter() };
			label.SetBinding(PieChartLabel.VisibilityProperty, visibilityBinding);

			Binding geometryBinding = new Binding("Geometry") { Source = pieDataPoint };
			label.SetBinding(PieChartLabel.GeometryProperty, geometryBinding);

			Binding displayModeBinding = new Binding("LabelDisplayMode") { Source = this };
			label.SetBinding(PieChartLabel.DisplayModeProperty, displayModeBinding);

			labelArea.Children.Add(label);
			pieDataPoint.Unloaded += delegate
			{
				labelArea.Children.Remove(label);
			};

			pieDataPoint.Loaded += delegate
			{
				if (label.Parent == null)
				{
					labelArea.Children.Add(label);
				}
			};
		}

19 Source : PieChartLabel.cs
with MIT License
from bstollnitz

private void PositionConnected()
		{
			this.RemovePolyline();

			if (this.contentPart != null)
			{
				PointCollection newPoints = new PointCollection();

				// First point
				newPoints.Add(this.SnapPoint(this.arcMidpoint));

				// Second point
				Vector radialDirection = this.arcMidpoint - this.center;
				radialDirection.Normalize();
				Point secondPoint = this.arcMidpoint + (radialDirection * 10);
				newPoints.Add(this.SnapPoint(secondPoint));

				// Third point
				int sign = Math.Sign(radialDirection.X); // 1 if label is on the right side, -1 if it's on the left.
				Point thirdPoint = secondPoint + new Vector(sign * 20, 0);
				newPoints.Add(this.SnapPoint(thirdPoint));

				double contentX = (sign == 1) ? thirdPoint.X : thirdPoint.X - this.contentPart.DesiredSize.Width;
				double contentY = thirdPoint.Y - 0.5 * this.contentPart.DesiredSize.Height;
				Canvas.SetTop(this.contentPart, contentY);
				Canvas.SetLeft(this.contentPart, contentX);

				Polyline polyline = new Polyline();
				polyline.Points = newPoints;
				polyline.SetBinding(Polyline.StrokeThicknessProperty, new Binding("LineStrokeThickness") { Source = this });
				polyline.SetBinding(Polyline.StrokeProperty, new Binding("LineStroke") { Source = this });
				polyline.StrokeLineJoin = PenLineJoin.Round;

				this.canvasPart.Children.Add(polyline);
			}
		}

19 Source : MetroExpander.cs
with GNU General Public License v2.0
from Cdorey

public void Add(FrameworkElement element)
        {
            if (!(Content is StackPanel))
            {
                Content = new StackPanel();
            }
            (Content as StackPanel).Children.Add(element);
        }

19 Source : MetroWaterfallFlow.cs
with GNU General Public License v2.0
from Cdorey

public void Add(FrameworkElement element)
        {
            element.Width = ListWidth;
            if (element is Grid)
            {
                if ((element as Grid).Children.Count > 0)
                {
                    ((element as Grid).Children[0] as FrameworkElement).Margin = new Thickness(Margin.Left);
                }
            }
            Children.Add(element);
            Refresh();
        }

19 Source : LabelsEditor.xaml.cs
with Apache License 2.0
from Chem4Word

public void PopulateTreeView(string cml)
        {
            _cml = cml;
            var cc = new CMLConverter();
            EditedModel = cc.Import(_cml, Used1D, relabel: false);
            TreeView.Items.Clear();
            bool initialSelectionMade = false;

            if (EditedModel != null)
            {
                OverallConciseFormulaPanel.Children.Add(TextBlockFromFormula(EditedModel.ConciseFormula));

                var root = new TreeViewItem
                {
                    Header = "Structure",
                    Tag = EditedModel
                };
                TreeView.Items.Add(root);
                root.IsExpanded = true;

                AddNodes(root, EditedModel.Molecules.Values);
            }

            SetupNamesEditor(NamesGrid, "Add new Name", OnAddNameClick, "Alternative name(s) for molecule");
            SetupNamesEditor(FormulaGrid, "Add new Formula", OnAddFormulaClick, "Alternative formula for molecule");
            SetupNamesEditor(CaptionsGrid, "Add new Caption", OnAddLabelClick, "Molecule Caption(s)");

            TreeView.Focus();

            TreeView_OnSelectedItemChanged(null, null);

            // Local Function to support recursion
            void AddNodes(TreeViewItem parent, IEnumerable<Molecule> molecules)
            {
                foreach (var molecule in molecules)
                {
                    var tvi = new TreeViewItem();

                    if (molecule.Atoms.Count == 0)
                    {
                        var stackPanel = new StackPanel
                        {
                            Orientation = Orientation.Horizontal
                        };
                        stackPanel.Children.Add(TextBlockFromFormula(molecule.CalculatedFormulaOfChildren, "Group:"));
                        tvi.Header = stackPanel;
                        tvi.Tag = molecule;
                    }
                    else
                    {
                        var stackPanel = new StackPanel
                        {
                            Orientation = Orientation.Horizontal
                        };
                        stackPanel.Children.Add(TextBlockFromFormula(molecule.ConciseFormula));
                        tvi.Header = stackPanel;
                        tvi.Tag = molecule;
                    }

#if DEBUG
                    tvi.ToolTip = molecule.Path;
#endif

                    parent.Items.Add(tvi);
                    tvi.IsExpanded = true;
                    if (!initialSelectionMade)
                    {
                        tvi.IsSelected = true;
                        initialSelectionMade = true;
                    }

                    molecule.Captions.CollectionChanged += OnCollectionChanged;
                    foreach (var property in molecule.Captions)
                    {
                        property.PropertyChanged += OnTextualPropertyChanged;
                    }
                    molecule.Formulas.CollectionChanged += OnCollectionChanged;
                    foreach (var property in molecule.Formulas)
                    {
                        property.PropertyChanged += OnTextualPropertyChanged;
                    }
                    molecule.Names.CollectionChanged += OnCollectionChanged;
                    foreach (var property in molecule.Names)
                    {
                        property.PropertyChanged += OnTextualPropertyChanged;
                    }

                    AddNodes(tvi, molecule.Molecules.Values);
                }
            }
        }

19 Source : ToolTips.cs
with GNU General Public License v3.0
from ciribob

public static void Init()
        {
            ExternalAWACSMode = new ToolTip();
            StackPanel externalAWACSModeContent = new StackPanel();

            externalAWACSModeContent.Children.Add(new TextBlock
            {
                Text = "External AWACS Mode",
                FontWeight = FontWeights.Bold
            });
            externalAWACSModeContent.Children.Add(new TextBlock
            {
                Text = "External AWACS Mode (EAM) allows you to use the AWACS functionality of SRS without having to run IL2."
            });
            externalAWACSModeContent.Children.Add(new TextBlock
            {
                Text = "Enter the side preplacedword provided to you by the SRS server admin to confirm a side selection."
            });

            ExternalAWACSMode.Content = externalAWACSModeContent;


            ExternalAWACSModeName = new ToolTip();
            StackPanel externalAWACSModeNameContent = new StackPanel();

            externalAWACSModeNameContent.Children.Add(new TextBlock
            {
                Text = "External AWACS Mode name",
                FontWeight = FontWeights.Bold
            });
            externalAWACSModeNameContent.Children.Add(new TextBlock
            {
                Text = "Choose a name to display in the client list and export of the SRS server."
            });

            ExternalAWACSModeName.Content = externalAWACSModeNameContent;


            ExternalAWACSModePreplacedword = new ToolTip();
            StackPanel externalAWACSModePreplacedwordContent = new StackPanel();

            externalAWACSModePreplacedwordContent.Children.Add(new TextBlock
            {
                Text = "External AWACS Mode coalition preplacedword",
                FontWeight = FontWeights.Bold
            });
            externalAWACSModePreplacedwordContent.Children.Add(new TextBlock
            {
                Text = "The coalition preplacedword is provided to you by the SRS server admin."
            });
            externalAWACSModePreplacedwordContent.Children.Add(new TextBlock
            {
                Text = "Entering the correct preplacedword for a coalitions allows you to access that side's comms."
            });

            ExternalAWACSModePreplacedword.Content = externalAWACSModePreplacedwordContent;
        }

19 Source : MicAvailabilityTooltipConverter.cs
with GNU General Public License v3.0
from ciribob

private static ToolTip BuildTooltip()
		{
			var NoMicAvailable = new ToolTip();
			StackPanel noMicAvailableContent = new StackPanel();

			noMicAvailableContent.Children.Add(new TextBlock
			{
				Text = "No microphone available",
				FontWeight = FontWeights.Bold
			});
			noMicAvailableContent.Children.Add(new TextBlock
			{
				Text = "No valid microphone is available - others will not be able to hear you."
			});
			noMicAvailableContent.Children.Add(new TextBlock
			{
				Text = "You can still use SRS to listen to radio calls, but will not be able to transmit anything yourself."
			});

			NoMicAvailable.Content = noMicAvailableContent;
			return NoMicAvailable;
		}

19 Source : Installation.cs
with GNU General Public License v3.0
from CrackyStudio

public static void Build(Grid AppGrid)
        {
            helloLabel = new Label
            {
                Content = $"Hello {Utils.GetUserName()}!",
                Width = 800,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(0, -100, 0, 0),
                FontSize = 32,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                FontFamily = new FontFamily("Trebuchet MS")
            };
            AppGrid.Children.Add(helloLabel);

            textLabel = new Label
            {
                Content = "ARKSO needs SteamCMD, do you already have it installed somewhere?",
                Width = 800,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(0, 0, 0, 0),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                FontFamily = new FontFamily("Trebuchet MS")
            };
            AppGrid.Children.Add(textLabel);

            isInstalledButton = new Button
            {
                Content = "Yes, let me show you where",
                Width = 200,
                Height = Double.NaN,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(-250, 100, 0, 0),
                Padding = new Thickness(10, 10, 10, 10),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                FontFamily = new FontFamily("Trebuchet MS"),
                BorderBrush = new SolidColorBrush(Colors.Transparent),
                Style = (Style)Application.Current.Resources["onHoverButton"]
            };
            isInstalledButton.AddHandler(Button.ClickEvent, new RoutedEventHandler(MainWindow.SelectSCMDLocation));
            AppGrid.Children.Add(isInstalledButton);

            notInstalledButton = new Button
            {
                Content = "No, let's install it",
                Width = 200,
                Height = Double.NaN,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(250, 100, 0, 0),
                Padding = new Thickness(10, 10, 10, 10),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                FontFamily = new FontFamily("Trebuchet MS"),
                BorderBrush = new SolidColorBrush(Colors.Transparent),
                Style = (Style)Application.Current.Resources["onHoverButton"]
            };
            notInstalledButton.AddHandler(Button.ClickEvent, new RoutedEventHandler(MainWindow.SCMDSetup));
            AppGrid.Children.Add(notInstalledButton);
        }

19 Source : Main.cs
with GNU General Public License v3.0
from CrackyStudio

public static void Build(Grid AppGrid)
        {
            // Misc
            donateLabel = new Label
            {
                Content = "$",
                Width = 25,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Right,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(0, 0, 25, 0),
                Cursor = Cursors.Hand
            };

            versionLabel = new Label
            {
                Content = MainWindow.currentVersion,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Right,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(0, 0, 2, 0),
                Padding = new Thickness(-10, 0, 0, 0),
                FontSize = 10
            };

            // Server
            serverBox = new Label
            {
                Width = 480,
                Height = 40,
                BorderThickness = new Thickness(0.5),
                BorderBrush = new SolidColorBrush(Colors.LightGray),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(10, 35, 10, 0),
            };

            statusDescLabel = new Label
            {
                Content = "Status:",
                Height = double.NaN,
                Foreground = new SolidColorBrush(Colors.LightGray),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(20, 42, 20, 0),
            };

            statusLabel = new Label
            {
                Content = "OFFLINE",
                Height = double.NaN,
                Foreground = new SolidColorBrush(Colors.Red),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(70, 42, 20, 0)
            };

            latencyDescLabel = new Label
            {
                Content = "Latency:",
                Height = double.NaN,
                Foreground = new SolidColorBrush(Colors.LightGray),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(140, 42, 20, 0),
            };

            latencyLabel = new Label
            {
                Content = "-- ms",
                Height = double.NaN,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(200, 42, 20, 0)
            };

            addressDescLabel = new Label
            {
                Content = "Address:",
                Height = double.NaN,
                Foreground = new SolidColorBrush(Colors.LightGray),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(250, 42, 0, 0),
            };

            addressLabel = new Label
            {
                Content = $"{MainWindow.serverIP}:{Json.GetProperty(Json.serverJson, "port")}",
                Height = double.NaN,
                Foreground = new SolidColorBrush(Colors.LightGray),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(310, 42, 20, 0),
            };

            shareAddressButton = new Button
            {
                Content = "Copy",
                Height = double.NaN,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(0, 42, 25, 0),
                Padding = new Thickness(4, 4, 4, 4),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                BorderBrush = new SolidColorBrush(Colors.LightGray),
                Style = (Style)Application.Current.Resources["onHoverButton"],
                Cursor = Cursors.Hand
            };

            // Settings
            settingsBox = new Label
            {
                Width = 480,
                Height = 260,
                BorderThickness = new Thickness(0.5),
                BorderBrush = new SolidColorBrush(Colors.LightGray),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(10, 90, 10, 0),
            };

            nameLabel = new Label
            {
                Content = "Server Name:",
                Width = 90,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(20, 98, 0, 0),
            };

            nameTextbox = new TextBox
            {
                Name = "name",
                Text = Json.GetProperty(Json.serverJson, "name"),
                Width = 362,
                Height = 22,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(115, 101, 0, 0),
                Padding = new Thickness(5, 1.5, 5, 0)
            };

            mapLabel = new Label
            {
                Content = "Map:",
                Width = 90,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(20, 128, 0, 0),
            };

            mapCbb = new ComboBox
            {
                Name = "map",
                Width = 130,
                Height = 22,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(115, 130, 0, 0),
                ItemsSource = Json.GetKeys(Json.mapsJson),
                SelectedIndex = Json.GetSelectedIndexProperty("map", Json.Read(Json.mapsJson)),
            };

            playersLabel = new Label
            {
                Content = "Players:",
                Width = 100,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(260, 128, 0, 0),
            };

            playersTextbox = new TextBox
            {
                Name = "players",
                Text = Json.GetProperty(Json.serverJson, "players"),
                Width = 50,
                Height = 22,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(365, 130, 0, 0),
                Padding = new Thickness(5, 1.5, 0, 0)
            };

            VACLabel = new Label
            {
                Content = "VAC:",
                Width = 90,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(20, 158, 0, 0),
            };

            VACCbb = new ComboBox
            {
                Name = "vac",
                Width = 75,
                Height = 22,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(115, 160, 0, 0),
                ItemsSource = Json.GetKeys(Json.VACJson),
                SelectedIndex = Json.GetSelectedIndexProperty("vac", Json.Read(Json.VACJson))
            };

            battlEyeLabel = new Label
            {
                Content = "BattlEye:",
                Width = 100,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(260, 158, 0, 0),
            };

            battlEyeCbb = new ComboBox
            {
                Name = "battleye",
                Width = 75,
                Height = 22,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(365, 160, 0, 0),
                ItemsSource = Json.GetKeys(Json.VACJson),
                SelectedIndex = Json.GetSelectedIndexProperty("battleye", Json.Read(Json.BattlEyeJson))
            };

            preplacedwordLabel = new Label
            {
                Content = "Preplacedword:",
                Width = 90,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(20, 188, 0, 0),
            };

            preplacedwordTextbox = new TextBox
            {
                Name = "preplacedword",
                Text = Json.GetProperty(Json.serverJson, "preplacedword"),
                Width = 110,
                Height = 22,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(115, 190, 0, 0),
                Padding = new Thickness(5, 1.5, 0, 0)
            };

            adminPreplacedwordLabel = new Label
            {
                Content = "Admin Preplacedword:",
                Width = 100,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(260, 188, 0, 0),
            };

            adminPreplacedwordTextbox = new TextBox
            {
                Name = "admin_preplacedword",
                Text = Json.GetProperty(Json.serverJson, "admin_preplacedword"),
                Width = 110,
                Height = 22,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(365, 190, 0, 0),
                Padding = new Thickness(5, 1.5, 0, 0)
            };

            portLabel = new Label
            {
                Content = "Port:",
                Width = 90,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(20, 218, 0, 0),
            };

            portTextbox = new TextBox
            {
                Name = "port",
                Text = Json.GetProperty(Json.serverJson, "port"),
                Width = 80,
                Height = 22,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(115, 220, 0, 0),
                Padding = new Thickness(5, 1.5, 0, 0)
            };

            queryPortLabel = new Label
            {
                Content = "Query Port:",
                Width = 100,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(260, 218, 0, 0),
            };

            queryPortTextbox = new TextBox
            {
                Name = "query_port",
                Text = Json.GetProperty(Json.serverJson, "query_port"),
                Width = 80,
                Height = 22,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(365, 220, 0, 0),
                Padding = new Thickness(5, 1.5, 0, 0)
            };

            argumentsLabel = new Label
            {
                Content = "Arguments:",
                Width = 90,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(20, 248, 0, 0),
            };

            argumentsTextbox = new TextBox
            {
                Name = "arguments",
                Text = Json.GetProperty(Json.serverJson, "arguments"),
                Width = 362,
                Height = 22,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(115, 250, 0, 0),
                Padding = new Thickness(5, 1.5, 0, 0)
            };

            optionsLabel = new Label
            {
                Content = "Options:",
                Width = 90,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(20, 278, 0, 0),
            };

            optionsTextbox = new TextBox
            {
                Name = "options",
                Text = Json.GetProperty(Json.serverJson, "options"),
                Width = 362,
                Height = 22,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(115, 280, 0, 0),
                Padding = new Thickness(5, 1.5, 0, 0)
            };

            manualConfigLabel = new Label
            {
                Content = "Maunal Config:",
                Width = 90,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                HorizontalContentAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(20, 310, 0, 0),
            };

            gameIniButton = new Button
            {
                Name = "Game",
                Content = "Edit Game",
                Width = 160,
                Height = double.NaN,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(115, 310, 0, 0),
                Padding = new Thickness(5, 5, 5, 5),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                BorderBrush = new SolidColorBrush(Colors.LightGray),
                Style = (Style)Application.Current.Resources["onHoverButton"]
            };

            gameUserSettingsIniButton = new Button
            {
                Name = "GameUserSettings",
                Content = "Edit GameUserSettings",
                Width = 160,
                Height = double.NaN,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(316, 310, 0, 0),
                Padding = new Thickness(5, 5, 5, 5),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                BorderBrush = new SolidColorBrush(Colors.LightGray),
                Style = (Style)Application.Current.Resources["onHoverButton"]
            };

            // Management
            managementBox = new Label
            {
                Width = 480,
                Height = 35,
                BorderThickness = new Thickness(0.5),
                BorderBrush = new SolidColorBrush(Colors.LightGray),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(10, 365, 10, 0),
            };

            autoBnU = new CheckBox
            {
                Name = "auto_unb",
                Content = "Automatic backup and update",
                IsChecked = bool.Parse(Json.GetProperty(Json.serverJson, "auto_unb")),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                Margin = new Thickness(25, 375, 10, 0),
            };

            autoUnBTime = new TimeSpanUpDown
            {
                Name = "auto_unb_time",
                Width = 55,
                Height = 22,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(220, 371, 0, 0),
                Padding = new Thickness(0, 1.5, 0, 0),
                AllowTextInput = false,
                ShowDays = false,
                ShowSeconds = false,
                Maximum = new TimeSpan(0, 24, 0, 0),
                Minimum = new TimeSpan(0, 0, 0, 0),
                CurrentDateTimePart = DateTimePart.Hour24,
                TextAlignment = TextAlignment.Center,
                Value = Server.GetUpdateTime()
            };

            hideConsoleCheckbox = new CheckBox
            {
                Name = "hide_console",
                Content = "Hide server console",
                IsChecked = bool.Parse(Json.GetProperty(Json.serverJson, "hide_console")),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                Margin = new Thickness(315, 375, 10, 0),
            };

            // Action
            actionBox = new Label
            {
                Width = 480,
                Height = 47,
                BorderThickness = new Thickness(0.5),
                BorderBrush = new SolidColorBrush(Colors.LightGray),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(10, 415, 10, 0),
            };

            turnOnOffButton = new Button
            {
                Content = "Start server",
                Width = 140,
                Height = double.NaN,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(20, 425, 0, 0),
                Padding = new Thickness(5, 5, 5, 5),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                BorderBrush = new SolidColorBrush(Colors.LightGray),
                Style = (Style)Application.Current.Resources["onHoverButton"]
            };

            updateButton = new Button
            {
                Content = "Update server",
                Width = 140,
                Height = double.NaN,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(180, 425, 0, 0),
                Padding = new Thickness(5, 5, 5, 5),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                BorderBrush = new SolidColorBrush(Colors.LightGray),
                Style = (Style)Application.Current.Resources["onHoverButton"]
            };

            backupButton = new Button
            {
                Content = "Backup server",
                Width = 140,
                Height = double.NaN,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Thickness(340, 425, 0, 0),
                Padding = new Thickness(5, 5, 5, 5),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                BorderBrush = new SolidColorBrush(Colors.LightGray),
                Style = (Style)Application.Current.Resources["onHoverButton"]
            };

            // Credits
            credits = new TextBlock
            {
                Text = "ARKSO and Cracky are not affiliated with anyone. All trademarks and registered trademarks are the property of their respective owners.",
                Width = 480,
                Height = 47,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                TextAlignment = TextAlignment.Center,
                TextWrapping = TextWrapping.WrapWithOverflow,
                Margin = new Thickness(12, 470, 20, 0),
                Padding = new Thickness(5, 5, 5, 5)
            };

            // Add handlers
            donateLabel.AddHandler(UIElement.PreviewMouseDownEvent, new RoutedEventHandler(MainWindow.Donate));
            shareAddressButton.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new RoutedEventHandler(MainWindow.ShareServer));
            nameTextbox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new RoutedEventHandler(Json.Update));
            mapCbb.AddHandler(System.Windows.Controls.Primitives.Selector.SelectionChangedEvent, new RoutedEventHandler(Json.UpdateMap));
            playersTextbox.AddHandler(UIElement.PreviewTextInputEvent, new TextCompositionEventHandler(Utils.TextBoxNumberValidation));
            playersTextbox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new RoutedEventHandler(Json.Update));
            VACCbb.AddHandler(System.Windows.Controls.Primitives.Selector.SelectionChangedEvent, new RoutedEventHandler(Json.UpdateVAC));
            battlEyeCbb.AddHandler(System.Windows.Controls.Primitives.Selector.SelectionChangedEvent, new RoutedEventHandler(Json.UpdateBattlEye));
            preplacedwordTextbox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new RoutedEventHandler(Json.Update));
            adminPreplacedwordTextbox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new RoutedEventHandler(Json.Update));
            portTextbox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new RoutedEventHandler(Json.Update));
            queryPortTextbox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new RoutedEventHandler(Json.Update));
            argumentsTextbox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new RoutedEventHandler(Json.Update));
            optionsTextbox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new RoutedEventHandler(Json.Update));
            turnOnOffButton.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new RoutedEventHandler(MainWindow.StartNStopServer));
            updateButton.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new RoutedEventHandler(MainWindow.UpdateServer));
            gameIniButton.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new RoutedEventHandler(Utils.EditFile));
            gameUserSettingsIniButton.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new RoutedEventHandler(Utils.EditFile));
            hideConsoleCheckbox.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new RoutedEventHandler(Server.UpdateCheckbox));
            autoBnU.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new RoutedEventHandler(Server.UpdateCheckbox));
            backupButton.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new RoutedEventHandler(Server.Backup));
            autoUnBTime.AddHandler(TimeSpanUpDown.ValueChangedEvent, new RoutedEventHandler(Utils.TimePicker));

            // Adjust window size
            Application.Current.MainWindow.Width = 500;
            Application.Current.MainWindow.Height = 520;
            AppGrid.Width = 501;
            MainWindow.CenterApp();

            // Add controls
            AppGrid.Children.Add(donateLabel);
            AppGrid.Children.Add(versionLabel);

            AppGrid.Children.Add(serverBox);
            AppGrid.Children.Add(statusDescLabel);
            AppGrid.Children.Add(statusLabel);
            AppGrid.Children.Add(latencyDescLabel);
            AppGrid.Children.Add(latencyLabel);
            AppGrid.Children.Add(addressDescLabel);
            AppGrid.Children.Add(addressLabel);
            AppGrid.Children.Add(shareAddressButton);

            AppGrid.Children.Add(settingsBox);
            AppGrid.Children.Add(nameLabel);
            AppGrid.Children.Add(nameTextbox);
            AppGrid.Children.Add(mapLabel);
            AppGrid.Children.Add(mapCbb);
            AppGrid.Children.Add(playersLabel);
            AppGrid.Children.Add(playersTextbox);
            AppGrid.Children.Add(VACLabel);
            AppGrid.Children.Add(VACCbb);
            AppGrid.Children.Add(battlEyeLabel);
            AppGrid.Children.Add(battlEyeCbb);
            AppGrid.Children.Add(preplacedwordLabel);
            AppGrid.Children.Add(preplacedwordTextbox);
            AppGrid.Children.Add(adminPreplacedwordLabel);
            AppGrid.Children.Add(adminPreplacedwordTextbox);
            AppGrid.Children.Add(portLabel);
            AppGrid.Children.Add(portTextbox);
            AppGrid.Children.Add(queryPortLabel);
            AppGrid.Children.Add(queryPortTextbox);
            AppGrid.Children.Add(argumentsLabel);
            AppGrid.Children.Add(argumentsTextbox);
            AppGrid.Children.Add(optionsLabel);
            AppGrid.Children.Add(optionsTextbox);
            AppGrid.Children.Add(manualConfigLabel);
            AppGrid.Children.Add(gameIniButton);
            AppGrid.Children.Add(gameUserSettingsIniButton);

            AppGrid.Children.Add(managementBox);
            AppGrid.Children.Add(autoBnU);
            AppGrid.Children.Add(autoUnBTime);
            AppGrid.Children.Add(hideConsoleCheckbox);

            AppGrid.Children.Add(actionBox);
            AppGrid.Children.Add(turnOnOffButton);
            AppGrid.Children.Add(updateButton);
            AppGrid.Children.Add(backupButton);

            AppGrid.Children.Add(credits);
        }

19 Source : Loading.cs
with GNU General Public License v3.0
from CrackyStudio

public static void Build(Grid Grid, string message)
        {
            isInstallingLabel = new Label
            {
                Content = message,
                Width = 800,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                FontSize = 32,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                FontFamily = new FontFamily("Trebuchet MS")
            };
            Grid.Children.Add(isInstallingLabel);
        }

19 Source : Update.cs
with GNU General Public License v3.0
from CrackyStudio

public static void Build(Grid AppGrid)
        {
            textLabel = new Label
            {
                Content = "A new version is available, would you like to udpate?",
                Width = 800,
                Height = Double.NaN,
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(0, -50, 0, 0),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                FontFamily = new FontFamily("Trebuchet MS")
            };
            AppGrid.Children.Add(textLabel);

            yesButton = new Button
            {
                Content = "Yes",
                Width = 200,
                Height = Double.NaN,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(-250, 50, 0, 0),
                Padding = new Thickness(10, 10, 10, 10),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                FontFamily = new FontFamily("Trebuchet MS"),
                BorderBrush = new SolidColorBrush(Colors.Transparent),
                Style = (Style)Application.Current.Resources["onHoverButton"]
            };
            yesButton.AddHandler(Button.ClickEvent, new RoutedEventHandler(MainWindow.UpdateApp));
            AppGrid.Children.Add(yesButton);

            noButton = new Button
            {
                Content = "No",
                Width = 200,
                Height = Double.NaN,
                Background = new SolidColorBrush(Color.FromRgb(48, 65, 87)),
                Foreground = new SolidColorBrush(Color.FromRgb(171, 173, 168)),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Thickness(250, 50, 0, 0),
                Padding = new Thickness(10, 10, 10, 10),
                HorizontalContentAlignment = HorizontalAlignment.Center,
                FontFamily = new FontFamily("Trebuchet MS"),
                BorderBrush = new SolidColorBrush(Colors.Transparent),
                Style = (Style)Application.Current.Resources["onHoverButton"]
            };
            noButton.AddHandler(Button.ClickEvent, new RoutedEventHandler(MainWindow.BuildInterface));
            AppGrid.Children.Add(noButton);
        }

19 Source : Dialog2DMatch.xaml.cs
with GNU General Public License v3.0
from cramerlab

private async void ButtonMatch_OnClick(object sender, RoutedEventArgs e)
        {
            bool Filter = (bool)CheckFilter.IsChecked;
            bool Manual = (bool)CheckManual.IsChecked;

            #region Get all movies that can potentially be used

            List<Movie> ValidMovies = Movies.Where(v =>
            {
                if (!Filter && v.UnselectFilter && v.UnselectManual == null)
                    return false;
                if (!Manual && v.UnselectManual != null && (bool)v.UnselectManual)
                    return false;
                if (v.OptionsCTF == null)
                    return false;
                return true;
            }).ToList();

            if (ValidMovies.Count == 0)
            {
                Close?.Invoke();
                return;
            }

            #endregion

            #region Set up progress displays

            NParallel = Math.Min(ValidMovies.Count, GPU.GetDeviceCount());
            GridSizes = Helper.ArrayOfConstant(new int3(1), NParallel);
            GridProgress = new int[NParallel];
            GridNames = new string[NParallel];

            GridControls = Helper.ArrayOfFunction(i => new FlatGridMiniature() { Width = 256 }, NParallel);
            GridLabels = Helper.ArrayOfFunction(i => new TextBlock { FontSize = 18, Margin = new Thickness(0, 15, 0, 0), HorizontalAlignment = HorizontalAlignment.Center }, NParallel);

            for (int n = 0; n < NParallel; n++)
            {
                StackPanel SP = new StackPanel { Orientation = Orientation.Vertical, Margin = new Thickness(15, 0, 15, 0) };
                SP.Children.Add(GridControls[n]);
                SP.Children.Add(GridLabels[n]);

                PanelGrids.Children.Add(SP);
            }

            #endregion

            PanelConfiguration.Visibility = Visibility.Collapsed;
            PanelProgress.Visibility = Visibility.Visible;

            int Completed = 0;
            ProgressOverall.Maximum = ValidMovies.Count;

            await Task.Run(() =>
            {
                #region Load template and make copies for all devices

                Image[] Template = new Image[NParallel];
                {
                    Template[0] = Image.FromFile(PathTemplate);
                    Template[0].PixelSize = (float)Options.Tasks.TomoMatchTemplatePixel;

                    for (int i = 0; i < Template.Length; i++)
                        Template[i] = Template[0].GetCopy();
                }

                #endregion

                #region Load gain reference if needed

                Image[] ImageGain = new Image[NParallel];
                DefectModel[] DefectMap = new DefectModel[NParallel];
                if (!string.IsNullOrEmpty(Options.Import.GainPath) && Options.Import.CorrectGain && File.Exists(Options.Import.GainPath))
                    for (int d = 0; d < NParallel; d++)
                        ImageGain[d] = MainWindow.LoadAndPrepareGainReference();
                if (!string.IsNullOrEmpty(Options.Import.DefectsPath) && Options.Import.CorrectDefects && File.Exists(Options.Import.DefectsPath))
                    for (int d = 0; d < NParallel; d++)
                        DefectMap[d] = MainWindow.LoadAndPrepareDefectMap();

                #endregion

                object SyncDummy = new object();

                Helper.ForEachGPU(ValidMovies, (item, gpuID) =>
                {
                    if (IsCanceled)
                        return true;    // This cancels the iterator

                    Dispatcher.Invoke(() =>
                    {
                        SetGridSize(gpuID, new int3(1, 1, 1));
                        SetGridProgress(gpuID, 0);
                        SetGridName(gpuID, "Loading data...");
                    });

                    ProcessingOptionsFullMatch MatchOptions = Options.GetProcessingFullMatch();
                    MatchOptions.TemplateName = Helper.PathToName(PathTemplate);

                    #region Load and prepare original movie

                    Image OriginalStack = null;
                    decimal ScaleFactor = 1M / MatchOptions.DownsampleFactor;

                    MapHeader OriginalHeader = MapHeader.ReadFromFile(item.Path);

                    MainWindow.LoadAndPrepareHeaderAndMap(item.Path, ImageGain[gpuID], DefectMap[gpuID], ScaleFactor, out OriginalHeader, out OriginalStack);

                    if (IsCanceled)
                    {
                        OriginalStack?.Dispose();

                        return true;
                    }

                    #endregion

                    item.MatchFull(OriginalStack, MatchOptions, Template[gpuID], (size, value, name) =>
                    {
                        Dispatcher.Invoke(() =>
                        {
                            SetGridSize(gpuID, size);
                            SetGridProgress(gpuID, value);
                            SetGridName(gpuID, name);
                        });

                        return IsCanceled;
                    });

                    OriginalStack?.Dispose();

                    Dispatcher.Invoke(() => ProgressOverall.Value = ++Completed);

                    return false;   // No need to cancel GPU ForEach iterator
                }, 1);
            });

            Close?.Invoke();
        }

19 Source : DialogTomoMatch.xaml.cs
with GNU General Public License v3.0
from cramerlab

private async void ButtonReconstruct_OnClick(object sender, RoutedEventArgs e)
        {
            bool Filter = (bool)CheckFilter.IsChecked;
            bool Manual = (bool)CheckManual.IsChecked;

            #region Get all movies that can potentially be used

            List<TiltSeries> ValidSeries = Series.Where(v =>
            {
                if (!Filter && v.UnselectFilter && v.UnselectManual == null)
                    return false;
                if (!Manual && v.UnselectManual != null && (bool)v.UnselectManual)
                    return false;
                if (v.OptionsCTF == null)
                    return false;
                return true;
            }).ToList();

            if (ValidSeries.Count == 0)
            {
                Close?.Invoke();
                return;
            }

            #endregion

            #region Set up progress displays

            NParallel = Math.Min(ValidSeries.Count, GPU.GetDeviceCount());
            GridSizes = Helper.ArrayOfConstant(new int3(1), NParallel);
            GridProgress = new int[NParallel];
            GridNames = new string[NParallel];

            GridControls = Helper.ArrayOfFunction(i => new ReconstructionMiniature { Width = 256 }, NParallel);
            GridLabels = Helper.ArrayOfFunction(i => new TextBlock { FontSize = 18, Margin = new Thickness(0, 15, 0, 0), HorizontalAlignment = HorizontalAlignment.Center }, NParallel);

            for (int n = 0; n < NParallel; n++)
            {
                StackPanel SP = new StackPanel { Orientation = Orientation.Vertical, Margin = new Thickness(15, 0, 15, 0) };
                SP.Children.Add(GridControls[n]);
                SP.Children.Add(GridLabels[n]);

                PanelGrids.Children.Add(SP);
            }

            #endregion

            PanelConfiguration.Visibility = Visibility.Collapsed;
            PanelProgress.Visibility = Visibility.Visible;

            int Completed = 0;
            ProgressOverall.Maximum = ValidSeries.Count;

            await Task.Run(() =>
            {
                #region Load template and make copies for all devices

                Image[] Template = new Image[NParallel];
                {
                    Template[0] = Image.FromFile(PathTemplate);

                    if (Options.Tasks.TomoMatchWhitenSpectrum)
                    {
                        Image Whitened = Template[0].replacedpectrumFlattened(true, 0.99f);
                        Template[0].Dispose();
                        Template[0] = Whitened;
                    }

                    Template[0].FreeDevice();

                    Template[0].PixelSize = (float)Options.Tasks.TomoMatchTemplatePixel;
                    for (int i = 0; i < Template.Length; i++)
                        Template[i] = Template[0].GetCopy();
                }

                #endregion

                Helper.ForEachGPU(ValidSeries, (item, gpuID) =>
                {
                    if (IsCanceled)
                        return true;    // This cancels the iterator

                    ProcessingOptionsTomoFullMatch SeriesOptions = Options.GetProcessingTomoFullMatch();
                    SeriesOptions.TemplateName = Helper.PathToName(PathTemplate);

                    item.MatchFull(SeriesOptions, Template[gpuID], (size, value, name) =>
                    {
                        Dispatcher.Invoke(() =>
                        {
                            SetGridSize(gpuID, size);
                            SetGridProgress(gpuID, value);
                            SetGridName(gpuID, name);
                        });

                        return IsCanceled;
                    });

                    Dispatcher.Invoke(() => ProgressOverall.Value = ++Completed);

                    return false;   // No need to cancel GPU ForEach iterator
                }, 1, Helper.ArrayOfSequence(0, NParallel, 1).ToList());
            });

            Close?.Invoke();
        }

19 Source : DialogTomoReconstruction.xaml.cs
with GNU General Public License v3.0
from cramerlab

private async void ButtonReconstruct_OnClick(object sender, RoutedEventArgs e)
        {
            bool Filter = (bool)CheckFilter.IsChecked;
            bool Manual = (bool)CheckManual.IsChecked;

            #region Get all movies that can potentially be used

            List<TiltSeries> ValidSeries = Series.Where(v =>
            {
                if (!Filter && v.UnselectFilter && v.UnselectManual == null)
                    return false;
                if (!Manual && v.UnselectManual != null && (bool)v.UnselectManual)
                    return false;
                if (v.OptionsCTF == null)
                    return false;
                return true;
            }).ToList();

            if (ValidSeries.Count == 0)
            {
                Close?.Invoke();
                return;
            }

            #endregion

            #region Set up progress displays

            NParallel = Math.Min(ValidSeries.Count, GPU.GetDeviceCount());
            GridSizes = Helper.ArrayOfConstant(new int3(1), NParallel);
            GridProgress = new int[NParallel];
            GridNames = new string[NParallel];

            GridControls = Helper.ArrayOfFunction(i => new ReconstructionMiniature { Width = 256 }, NParallel);
            GridLabels = Helper.ArrayOfFunction(i => new TextBlock { FontSize = 18, Margin = new Thickness(0, 15, 0, 0), HorizontalAlignment = HorizontalAlignment.Center }, NParallel);

            for (int n = 0; n < NParallel; n++)
            {
                StackPanel SP = new StackPanel { Orientation = Orientation.Vertical, Margin = new Thickness(15, 0, 15, 0) };
                SP.Children.Add(GridControls[n]);
                SP.Children.Add(GridLabels[n]);

                PanelGrids.Children.Add(SP);
            }

            #endregion

            PanelConfiguration.Visibility = Visibility.Collapsed;
            PanelProgress.Visibility = Visibility.Visible;

            int Completed = 0;
            ProgressOverall.Maximum = ValidSeries.Count;

            await Task.Run(() =>
            {
                Helper.ForEachGPU(ValidSeries, (item, gpuID) =>
                {
                    if (IsCanceled)
                        return true;    // This cancels the iterator

                    ProcessingOptionsTomoFullReconstruction SeriesOptions = Options.GetProcessingTomoFullReconstruction();

                    item.ReconstructFull(SeriesOptions, (size, value, name) =>
                    {
                        Dispatcher.Invoke(() =>
                        {
                            SetGridSize(gpuID, size);
                            SetGridProgress(gpuID, value);
                            SetGridName(gpuID, name);
                        });

                        return IsCanceled;
                    });

                    Dispatcher.Invoke(() => ProgressOverall.Value = ++Completed);

                    return false;   // No need to cancel GPU ForEach iterator
                }, 1);
            });

            Close?.Invoke();
        }

19 Source : MainWindow.xaml.cs
with MIT License
from CutFlame

private Panel createStatField(string fieldName, long fieldValue)
        {
            var label = new TextBlock() {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Center,
                Padding = new Thickness(0),
                Margin = new Thickness(5),
                FontSize = 14,
                Text = fieldName,
            };

            var textbox = new TextBox() {
                VerticalContentAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right,
                TextAlignment = TextAlignment.Right,
                Margin = new Thickness(0, 5, 0, 5),
                Background = null,
                Width = 70,
                FontSize = 16,
                Text = fieldValue.ToString(),
                Tag = fieldName,
            };
            textbox.TextChanged += statTextbox_TextChanged;

            var stepper = new Stepper() {
                HorizontalAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(0, 5, 0, 5),
                Width = 12,
                Tag = textbox,
            };
            stepper.UpButtonClick += statStepper_UpButtonClick;
            stepper.DownButtonClick += statStepper_DownButtonClick;

            var dockPanel = new DockPanel() { Height = 40, Margin = new Thickness(5, 0, 5, 0) };

            dockPanel.Children.Add(label);
            DockPanel.SetDock(label, Dock.Left);
            dockPanel.Children.Add(stepper);
            DockPanel.SetDock(stepper, Dock.Right);
            dockPanel.Children.Add(textbox);
            DockPanel.SetDock(textbox, Dock.Right);

            return dockPanel;
        }

19 Source : ItemScreen.xaml.cs
with MIT License
from CutFlame

public void updateArmorPropertiesUI()
        {
            armorPropertiesStack.Children.Clear();
            if (_item == null || !_item.isArmor()) {
                armorPropertiesScrollViewer.Visibility = Visibility.Collapsed;
                return;
            }

            armorPropertiesScrollViewer.Visibility = Visibility.Visible;
            if (_item?.Armorproperties != null)
            {
                foreach (var armorProperty in _item.Armorproperties)
                {
                    var stack = new DockPanel() {
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                    };

                    var removeButton = new Button();
                    removeButton.Content = "X";
                    removeButton.Width = 20;
                    removeButton.CommandParameter = armorProperty;
                    removeButton.Command = new RelayCommand<Armorproperty>(armorPropertyRemoveButton_Click);
                    stack.Children.Add(removeButton);
                    DockPanel.SetDock(removeButton, Dock.Right);

                    var button = new ArmorPropertyButton(armorProperty);
                    button.ClipToBounds = true;
                    button.CommandParameter = armorProperty;
                    button.Command = new RelayCommand<Armorproperty>(armorPropertyButton_Click);
                    stack.Children.Add(button);
                    DockPanel.SetDock(button, Dock.Left);

                    armorPropertiesStack.Children.Add(stack);
                }
            }

            //Add Plus button
            var label = new Label();
            label.FontSize = 16;
            label.Content = "+";
            label.Padding = new Thickness(0);

            var plusButton = new Button();
            plusButton.IsEnabled = AppModel.gameContentLoaded;
            plusButton.HorizontalContentAlignment = HorizontalAlignment.Center;
            plusButton.VerticalContentAlignment = VerticalAlignment.Center;
            plusButton.HorizontalAlignment = HorizontalAlignment.Stretch;
            plusButton.Height = 32;
            plusButton.Padding = new Thickness(0);
            plusButton.Content = label;
            plusButton.Command = new RelayCommand<object>(plusArmorPropertyButton_Click);

            armorPropertiesStack.Children.Add(plusButton);
        }

19 Source : SelectionWindow.cs
with MIT License
from CutFlame

public void loadItems(string? selectedItem = null)
        {
            replacedle = R.getString("merchant_slot_select_item") ?? R.SELECT_ITEM;

            var anyButton = createFilterButton(ItemFilterEnum.All);
            var meleeButton = createFilterButton(ItemFilterEnum.MeleeWeapons);
            var rangedButton = createFilterButton(ItemFilterEnum.RangedWeapons);
            var armorButton = createFilterButton(ItemFilterEnum.Armor);
            var artifactButton = createFilterButton(ItemFilterEnum.Artifacts);

            var toolStack = new StackPanel {
                Height = 50,
                HorizontalAlignment = HorizontalAlignment.Center,
                Orientation = Orientation.Horizontal,
            };
            toolStack.Children.Add(anyButton);
            toolStack.Children.Add(meleeButton);
            toolStack.Children.Add(rangedButton);
            toolStack.Children.Add(armorButton);
            toolStack.Children.Add(artifactButton);

            var mainStack = new DockPanel();
            DockPanel.SetDock(toolStack, Dock.Top);
            mainStack.Children.Add(toolStack);
            DockPanel.SetDock(_listBox, Dock.Bottom);
            mainStack.Children.Add(_listBox);

            Content = mainStack;

            buildItemList(selectedItem: selectedItem);
        }

19 Source : Clock.cs
with MIT License
from cxwl3sxl

private void GenerateButtons(Panel canvas, ICollection<int> range, double radiusRatio, IValueConverter isCheckedConverter, Func<int, string> stylePropertySelector,
            string format, ClockDisplayMode clockDisplayMode)
        {
            var anglePerItem = 360.0 / range.Count;
            var radiansPerItem = anglePerItem * (Math.PI / 180);

            //nothing fancy with sizing/measuring...we are demanding a height
            if (canvas.Width < 10.0 || Math.Abs(canvas.Height - canvas.Width) > 0.0) return;

            _centreCanvas = new Point(canvas.Width / 2, canvas.Height / 2);
            var hypotenuseRadius = _centreCanvas.X * radiusRatio;

            foreach (var i in range)
            {
                var button = new ClockItemButton();
                button.SetBinding(StyleProperty, GetBinding(stylePropertySelector(i)));

                var adjacent = Math.Cos(i * radiansPerItem) * hypotenuseRadius;
                var opposite = Math.Sin(i * radiansPerItem) * hypotenuseRadius;

                button.CentreX = _centreCanvas.X + opposite;
                button.CentreY = _centreCanvas.Y - adjacent;

                button.SetBinding(ToggleButton.IsCheckedProperty, GetBinding("Time", converter: isCheckedConverter, converterParameter: i));
                button.SetBinding(Canvas.LeftProperty, GetBinding("X", button));
                button.SetBinding(Canvas.TopProperty, GetBinding("Y", button));

                button.Content = (i == 60 ? 0 : (i == 24 && clockDisplayMode == ClockDisplayMode.Hours ? 0 : i)).ToString(format);
                canvas.Children.Add(button);
            }
        }

19 Source : Wpf.cs
with MIT License
from dadhi

private static UIElement CreateUI(UI ui)
        {
            if (ui == null)
                throw new ArgumentNullException(nameof(ui));

            if (ui is UI.Text text)
                return new Label { Content = text.Content };

            if (ui is UI.Input input)
            {
                var elem = new TextBox { Text = input.Content };
                var m = input.Changed;
                elem.TextChanged += (sender, _) => m.Send(((TextBox)sender).Text);
                return elem;
            }

            if (ui is UI.Button b)
            {
                var elem = new Button { Content = b.Label };
                var m = b.Clicked;
                elem.Click += (sender, _) => m.Send(Unit.unit);
                return elem;
            }

            if (ui is UI.Panel panel)
            {
                var orientation = panel.Layout == Layout.Vertical ? Orientation.Vertical : Orientation.Horizontal;
                var elem = new StackPanel { Orientation = orientation };

                var kids = panel.Elements.Map(CreateUI);
                kids.Apply(x => elem.Children.Add(x));
                return elem;
            }

            if (ui is UI.Check check)
            {
                var elem = new CheckBox
                {
                    Content = check.Label,
                    IsChecked = check.IsChecked,
                };

                var m = check.Changed;
                elem.Checked += (sender, _) => m.Send(true);
                elem.Unchecked += (sender, _) => m.Send(false);

                return elem;
            }

            throw new NotSupportedException("The type of UI is not supported: " + ui.GetType());
        }

19 Source : ColorSelector.cs
with GNU General Public License v2.0
from DarthAffe

public override void OnApplyTemplate()
        {
            if ((_selector = GetTemplateChild("PART_Selector") as Panel) != null)
            {
                _selectorBrush = new SolidColorBrush();
                _selectorColor = new Rectangle
                {
                    VerticalAlignment = VerticalAlignment.Stretch,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    SnapsToDevicePixels = true,
                    StrokeThickness = 0,
                    Fill = _selectorBrush
                };
                _selector.Children.Add(_selectorColor);

                Rectangle selectorWhite = new Rectangle
                {
                    VerticalAlignment = VerticalAlignment.Stretch,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    SnapsToDevicePixels = true,
                    StrokeThickness = 0,
                    Fill = new LinearGradientBrush(WpfColor.FromRgb(255, 255, 255), WpfColor.FromArgb(0, 255, 255, 255), new Point(0, 0.5), new Point(1, 0.5))
                };
                _selector.Children.Add(selectorWhite);

                Rectangle selectorBlack = new Rectangle
                {
                    VerticalAlignment = VerticalAlignment.Stretch,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    SnapsToDevicePixels = true,
                    StrokeThickness = 0,
                    Fill = new LinearGradientBrush(WpfColor.FromRgb(0, 0, 0), WpfColor.FromArgb(0, 0, 0, 0), new Point(0.5, 1), new Point(0.5, 0))
                };
                _selector.Children.Add(selectorBlack);

                _selectorGrip = new Grid
                {
                    VerticalAlignment = VerticalAlignment.Bottom,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    SnapsToDevicePixels = true
                };
                _selectorGrip.Children.Add(new Ellipse
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    SnapsToDevicePixels = true,
                    Stroke = new SolidColorBrush(WpfColor.FromRgb(0, 0, 0)),
                    StrokeThickness = 2,
                    Fill = null,
                    Width = 12,
                    Height = 12
                });
                _selectorGrip.Children.Add(new Ellipse
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    SnapsToDevicePixels = true,
                    Stroke = new SolidColorBrush(WpfColor.FromRgb(255, 255, 255)),
                    StrokeThickness = 1,
                    Fill = null,
                    Width = 10,
                    Height = 10
                });
                _selector.Children.Add(_selectorGrip);

                _selector.SizeChanged += (sender, args) => UpdateSelector();
                _selector.MouseLeftButtonDown += (sender, args) =>
                                                 {
                                                     _dragSelector = true;
                                                     UpdateSelectorValue(args.GetPosition(_selector));
                                                 };
                _selector.MouseEnter += (sender, args) =>
                                        {
                                            if (args.LeftButton == MouseButtonState.Pressed)
                                            {
                                                _dragSelector = true;
                                                UpdateSelectorValue(args.GetPosition(_selector));
                                            }
                                        };
                _selector.MouseLeftButtonUp += (sender, args) => _dragSelector = false;
                _selector.MouseLeave += (sender, args) => _dragSelector = false;
                _selector.MouseMove += (sender, args) => UpdateSelectorValue(args.GetPosition(_selector));
                _selector.ClipToBounds = true;
            }

            if ((_sliderAlpha = GetTemplateChild("PART_SliderAlpha") as Slider) != null)
            {
                _alphaBrush = new LinearGradientBrush(new GradientStopCollection(new[] { new GradientStop(new WpfColor(), 0),
                                                                                         new GradientStop(new WpfColor(), 1) }));
                _sliderAlpha.Background = _alphaBrush;
                _sliderAlpha.ValueChanged += AChanged;
            }

            if ((_sliderRed = GetTemplateChild("PART_SliderRed") as Slider) != null)
            {
                _redBrush = new LinearGradientBrush(new GradientStopCollection(new[] { new GradientStop(new WpfColor(), 0),
                                                                                       new GradientStop(new WpfColor(), 1) }));
                _sliderRed.Background = _redBrush;
                _sliderRed.ValueChanged += RChanged;
            }

            if ((_sliderGreen = GetTemplateChild("PART_SliderGreen") as Slider) != null)
            {
                _greenBrush = new LinearGradientBrush(new GradientStopCollection(new[] { new GradientStop(new WpfColor(), 0),
                                                                                         new GradientStop(new WpfColor(), 1) }));
                _sliderGreen.Background = _greenBrush;
                _sliderGreen.ValueChanged += GChanged;
            }

            if ((_sliderBlue = GetTemplateChild("PART_SliderBlue") as Slider) != null)
            {
                _blueBrush = new LinearGradientBrush(new GradientStopCollection(new[] { new GradientStop(new WpfColor(), 0),
                                                                                        new GradientStop(new WpfColor(), 1) }));
                _sliderBlue.Background = _blueBrush;
                _sliderBlue.ValueChanged += BChanged;
            }

            if ((_sliderHue = GetTemplateChild("PART_SliderHue") as Slider) != null)
            {
                _hueBrush = new LinearGradientBrush(new GradientStopCollection(new[] { new GradientStop(new WpfColor(), 0),
                                                                                       new GradientStop(new WpfColor(), 1.0 / 6.0),
                                                                                       new GradientStop(new WpfColor(), 2.0 / 6.0),
                                                                                       new GradientStop(new WpfColor(), 3.0 / 6.0),
                                                                                       new GradientStop(new WpfColor(), 4.0 / 6.0),
                                                                                       new GradientStop(new WpfColor(), 5.0 / 6.0),
                                                                                       new GradientStop(new WpfColor(), 1) }));
                _sliderHue.Background = _hueBrush;
                _sliderHue.ValueChanged += HueChanged;
            }

            if ((_sliderSaturation = GetTemplateChild("PART_SliderSaturation") as Slider) != null)
            {
                _saturationBrush = new LinearGradientBrush(new GradientStopCollection(new[] { new GradientStop(new WpfColor(), 0),
                                                                                              new GradientStop(new WpfColor(), 1) }));
                _sliderSaturation.Background = _saturationBrush;
                _sliderSaturation.ValueChanged += SaturationChanged;
            }

            if ((_sliderValue = GetTemplateChild("PART_SliderValue") as Slider) != null)
            {
                _valueBrush = new LinearGradientBrush(new GradientStopCollection(new[] { new GradientStop(new WpfColor(), 0),
                                                                                         new GradientStop(new WpfColor(), 1) }));
                _sliderValue.Background = _valueBrush;
                _sliderValue.ValueChanged += ValueChanged;
            }

            if ((_preview = GetTemplateChild("PART_Preview") as Rectangle) != null)
            {
                _previewBrush = new SolidColorBrush();
                _preview.Fill = _previewBrush;
            }

            SetColor(SelectedColor);
        }

19 Source : GradientEditor.cs
with GNU General Public License v2.0
from DarthAffe

private void UpdatePreviewRectangleCount(int gradientCount)
        {
            int countDiff = gradientCount - _previewRectangles.Count;
            if (countDiff > 0)
                for (int i = 0; i < countDiff; i++)
                {
                    Rectangle rect = new Rectangle { VerticalAlignment = VerticalAlignment.Stretch };
                    _previewRectangles.Add(rect);
                    _gradientContainer.Children.Add(rect);
                }

            if (countDiff < 0)
                for (int i = 0; i < Math.Abs(countDiff); i++)
                {
                    int index = _previewRectangles.Count - i - 1;
                    Rectangle rect = _previewRectangles[index];
                    _previewRectangles.RemoveAt(index);
                    _gradientContainer.Children.Remove(rect);
                }
        }

19 Source : FrequencyBarsVisualizer.cs
with GNU General Public License v2.0
from DarthAffe

private void InitializeBars()
        {
            if (_panel == null) return;

            _panel.Children.Clear();
            if (VisualizationProvider == null) return;

            _bars = new Rectangle[((FrequencyBarsVisualizationProviderConfiguration)VisualizationProvider.Configuration).Bars];

            for (int i = 0; i < _bars.Length; i++)
            {
                _bars[i] = new Rectangle { VerticalAlignment = VerticalAlignment.Bottom, Width = 0 };
                _panel.Children.Add(_bars[i]);
            }

            UpdateSizes();
            UpdateColors();
        }

19 Source : GradientEditor.cs
with GNU General Public License v2.0
from DarthAffe

private void UpdateGradientStopsCount(List<GradientStop> gradientStops)
        {
            foreach (GradientStop stop in gradientStops)
            {
                if (!_stops.ContainsKey(stop))
                {
                    ContentControl control = new ContentControl
                    {
                        VerticalAlignment = VerticalAlignment.Stretch,
                        Style = GradientStopStyle,
                        Content = stop
                    };
                    control.MouseDown += GradientStopOnMouseDown;
                    _stops.Add(stop, control);
                    _stopContainer.Children.Add(control);
                }
            }

            List<GradientStop> stopsToRemove = new List<GradientStop>();
            foreach (KeyValuePair<GradientStop, ContentControl> stopPair in _stops)
                if (!gradientStops.Contains(stopPair.Key))
                {
                    ContentControl control = stopPair.Value;
                    control.MouseDown -= GradientStopOnMouseDown;
                    stopsToRemove.Add(stopPair.Key);
                    _stopContainer.Children.Remove(control);
                }

            foreach (GradientStop stop in stopsToRemove)
                _stops.Remove(stop);
        }

19 Source : IElementCollection.cs
with MIT License
from DevZest

void ICollection<UIElement>.Add(UIElement item)
            {
                base.Add(item);
            }

19 Source : WindowSwitcher.cs
with MIT License
from DevZest

private void Show()
        {
            if (DockManager.GetFloatingWindowStrategy(DockControl) == FloatingWindowStrategy.Native)
            {
                Window window = new Window();
                window.WindowStyle = WindowStyle.None;
                window.ResizeMode = ResizeMode.NoResize;
                window.ShowInTaskbar = false;
                window.SizeToContent = SizeToContent.WidthAndHeight;
                window.Owner = Window.GetWindow(DockControl);
                window.AllowsTransparency = true;
                window.Background = null;
                window.Focusable = false;
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                window.Content = this;
                window.Show();
            }
            else
            {
                Grid grid = new Grid();
                VerticalAlignment = VerticalAlignment.Center;
                HorizontalAlignment = HorizontalAlignment.Center;
                grid.Children.Add(this);
                _floatingWindowAdorner = FloatingWindowAdorner.Add(DockControl, grid);
                UpdateLayout();
            }
            MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
        }

19 Source : ExpanderSample.xaml.cs
with MIT License
from DinoChan

private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var expanders = new List<ExtendedExpander>();
            Expander firstExpander = null;
            for (int i = 0; i < 10; i++)
            {
                var expander = new ExtendedExpander() { Header = "This is AccordionItem " + i };
                if (i == 0)
                    firstExpander = expander;

                Grid.SetRow(expander, i);
                var panel = new StackPanel();
                panel.Children.Add(new CheckBox { Content = "Calendar" });
                panel.Children.Add(new CheckBox { Content = "中国节假日" });
                panel.Children.Add(new CheckBox { Content = "Birthdays" });
                expander.Content = panel;
                MenuRoot.Children.Add(expander);
                MenuRoot.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
                int index = i;
                expander.Expanded += (s, args) =>
                {

                    var lastExpander = expanders.Where(p => p.IsExpanded && p != s).FirstOrDefault();
                    if (lastExpander != null)
                        lastExpander.IsExpanded = false;

                    MenuRoot.RowDefinitions[index].Height = new GridLength(1, GridUnitType.Star);
                };

                expander.Collapsed += (s, args) =>
                  {
                      if (expanders.Any(p => p.IsExpanded) == false)
                      {
                          expander.IsExpanded = true;
                          return;
                      }

                      MenuRoot.RowDefinitions[index].Height = new GridLength(1, GridUnitType.Auto);
                  };
                expanders.Add(expander);
            }


            firstExpander.IsExpanded = true;
        }

19 Source : LayoutAutoHideWindowControl.cs
with Microsoft Public License
from Dirkster99

private void CreateInternalGrid()
		{
			_internalGrid = new Grid { FlowDirection = FlowDirection.LeftToRight };
			_internalGrid.SetBinding(Panel.BackgroundProperty, new Binding(nameof(Grid.Background)) { Source = this });

			_internalHost = new LayoutAnchorableControl { Model = _model, Style = AnchorableStyle };
			_internalHost.SetBinding(FlowDirectionProperty, new Binding("Model.Root.Manager.FlowDirection") { Source = this });

			KeyboardNavigation.SetTabNavigation(_internalGrid, KeyboardNavigationMode.Cycle);
			_resizer = new LayoutGridResizerControl();

			_resizer.DragStarted += OnResizerDragStarted;
			_resizer.DragDelta += OnResizerDragDelta;
			_resizer.DragCompleted += OnResizerDragCompleted;

			switch (_side)
			{
				case AnchorSide.Right:
					_internalGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(_manager.GridSplitterWidth) });
					_internalGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = _model.AutoHideWidth == 0.0 ? new GridLength(_model.AutoHideMinWidth) : new GridLength(_model.AutoHideWidth, GridUnitType.Pixel) });
					Grid.SetColumn(_resizer, 0);
					Grid.SetColumn(_internalHost, 1);
					_resizer.Cursor = Cursors.SizeWE;
					HorizontalAlignment = HorizontalAlignment.Right;
					VerticalAlignment = VerticalAlignment.Stretch;
					break;

				case AnchorSide.Left:
					_internalGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = _model.AutoHideWidth == 0.0 ? new GridLength(_model.AutoHideMinWidth) : new GridLength(_model.AutoHideWidth, GridUnitType.Pixel) });
					_internalGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(_manager.GridSplitterWidth) });
					Grid.SetColumn(_internalHost, 0);
					Grid.SetColumn(_resizer, 1);
					_resizer.Cursor = Cursors.SizeWE;
					HorizontalAlignment = HorizontalAlignment.Left;
					VerticalAlignment = VerticalAlignment.Stretch;
					break;

				case AnchorSide.Top:
					_internalGrid.RowDefinitions.Add(new RowDefinition { Height = _model.AutoHideHeight == 0.0 ? new GridLength(_model.AutoHideMinHeight) : new GridLength(_model.AutoHideHeight, GridUnitType.Pixel), });
					_internalGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(_manager.GridSplitterHeight) });
					Grid.SetRow(_internalHost, 0);
					Grid.SetRow(_resizer, 1);
					_resizer.Cursor = Cursors.SizeNS;
					VerticalAlignment = VerticalAlignment.Top;
					HorizontalAlignment = HorizontalAlignment.Stretch;
					break;

				case AnchorSide.Bottom:
					_internalGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(_manager.GridSplitterHeight) });
					_internalGrid.RowDefinitions.Add(new RowDefinition { Height = _model.AutoHideHeight == 0.0 ? new GridLength(_model.AutoHideMinHeight) : new GridLength(_model.AutoHideHeight, GridUnitType.Pixel), });
					Grid.SetRow(_resizer, 0);
					Grid.SetRow(_internalHost, 1);
					_resizer.Cursor = Cursors.SizeNS;
					VerticalAlignment = VerticalAlignment.Bottom;
					HorizontalAlignment = HorizontalAlignment.Stretch;
					break;
			}
			_internalGrid.Children.Add(_resizer);
			_internalGrid.Children.Add(_internalHost);
			_internalHostPresenter.Content = _internalGrid;
		}

19 Source : LayoutAutoHideWindowControl.cs
with Microsoft Public License
from Dirkster99

private void ShowResizerOverlayWindow(LayoutGridResizerControl splitter)
		{
			_resizerGhost = new Border { Background = splitter.BackgroundWhileDragging, Opacity = splitter.OpacityWhileDragging };
			var areaElement = _manager.GetAutoHideAreaElement();
			//var modelControlActualSize = this._internalHost.TransformActualSizeToAncestor();
			var ptTopLeftScreen = areaElement.PointToScreenDPIWithoutFlowDirection(new Point());
			var managerSize = areaElement.TransformActualSizeToAncestor();
			Size windowSize;

			if (_side == AnchorSide.Right || _side == AnchorSide.Left)
			{
				windowSize = new Size(managerSize.Width - 25.0 + splitter.ActualWidth, managerSize.Height);
				_resizerGhost.Width = splitter.ActualWidth;
				_resizerGhost.Height = windowSize.Height;
				ptTopLeftScreen.Offset(25, 0.0);
			}
			else
			{
				windowSize = new Size(managerSize.Width, managerSize.Height - _model.AutoHideMinHeight - 25.0 + splitter.ActualHeight);
				_resizerGhost.Height = splitter.ActualHeight;
				_resizerGhost.Width = windowSize.Width;
				ptTopLeftScreen.Offset(0.0, 25.0);
			}
			_initialStartPoint = splitter.PointToScreenDPIWithoutFlowDirection(new Point()) - ptTopLeftScreen;

			if (_side == AnchorSide.Right || _side == AnchorSide.Left)
				Canvas.SetLeft(_resizerGhost, _initialStartPoint.X);
			else
				Canvas.SetTop(_resizerGhost, _initialStartPoint.Y);

			var panelHostResizer = new Canvas { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch };
			panelHostResizer.Children.Add(_resizerGhost);
			_resizerWindowHost = new Window
			{
				Style = new Style(typeof(Window), null),
				ResizeMode = ResizeMode.NoResize,
				WindowStyle = WindowStyle.None,
				ShowInTaskbar = false,
				AllowsTransparency = true,
				Background = null,
				Width = windowSize.Width,
				Height = windowSize.Height,
				Left = ptTopLeftScreen.X,
				Top = ptTopLeftScreen.Y,
				ShowActivated = false,
				Owner = Window.GetWindow(this),
				Content = panelHostResizer
			};

			_resizerWindowHost.Show();
		}

19 Source : TabControlEx.cs
with Microsoft Public License
from Dirkster99

private ContentPresenter CreateChildContentPresenter(object item)
		{
			if (item == null)
				return null;

			ContentPresenter cp = FindChildContentPresenter(item);

			if (cp != null)
				return cp;

			// the actual child to be added.  cp.Tag is a reference to the TabItem
			cp = new ContentPresenter();
			cp.Content = (item is TabItem) ? (item as TabItem).Content : item;
			cp.ContentTemplate = this.SelectedContentTemplate;
			cp.ContentTemplateSelector = this.SelectedContentTemplateSelector;
			cp.ContentStringFormat = this.SelectedContentStringFormat;
			cp.Visibility = Visibility.Collapsed;
			cp.Tag = (item is TabItem) ? item : (this.ItemContainerGenerator.ContainerFromItem(item));
			ItemsHolderPanel.Children.Add(cp);
			return cp;
		}

19 Source : LayoutGridControl.cs
with Microsoft Public License
from Dirkster99

private void UpdateChildren()
		{
			var alreadyContainedChildren = Children.OfType<ILayoutControl>().ToArray();
			DetachOldSplitters();
			DetachPropertyChangeHandler();
			Children.Clear();
			ColumnDefinitions.Clear();
			RowDefinitions.Clear();
			var manager = _model?.Root?.Manager;
			if (manager == null) return;
			foreach (var child in _model.Children)
			{
				var foundContainedChild = alreadyContainedChildren.FirstOrDefault(chVM => chVM.Model == child);
				if (foundContainedChild != null)
					Children.Add(foundContainedChild as UIElement);
				else
					Children.Add(manager.CreateUIElementForModel(child));
			}
			CreateSplitters();
			UpdateRowColDefinitions();
			AttachNewSplitters();
			AttachPropertyChangeHandler();
		}

19 Source : LayoutGridControl.cs
with Microsoft Public License
from Dirkster99

private void UpdateChildren()
		{
			var alreadyContainedChildren = Children.OfType<ILayoutControl>().ToArray();
			DetachOldSplitters();
			DetachPropertyChangeHandler();
			Children.Clear();
			ColumnDefinitions.Clear();
			RowDefinitions.Clear();
			var manager = _model?.Root?.Manager;
			if (manager == null) return;
			foreach (var child in _model.Children)
			{
				var foundContainedChild = alreadyContainedChildren.FirstOrDefault(chVM => chVM.Model == child);
				if (foundContainedChild != null)
					Children.Add(foundContainedChild as UIElement);
				else
					Children.Add(manager.CreateUIElementForModel(child));
			}
			CreateSplitters();
			UpdateRowColDefinitions();
			AttachNewSplitters();
			AttachPropertyChangeHandler();
		}

19 Source : LayoutGridControl.cs
with Microsoft Public License
from Dirkster99

private void ShowResizerOverlayWindow(LayoutGridResizerControl splitter)
		{
			_resizerGhost = new Border { Background = splitter.BackgroundWhileDragging, Opacity = splitter.OpacityWhileDragging };

			var indexOfResizer = InternalChildren.IndexOf(splitter);

			var prevChild = InternalChildren[indexOfResizer - 1] as FrameworkElement;
			var nextChild = GetNextVisibleChild(indexOfResizer);

			var prevChildActualSize = prevChild.TransformActualSizeToAncestor();
			var nextChildActualSize = nextChild.TransformActualSizeToAncestor();

			var prevChildModel = (ILayoutPositionableElement)(prevChild as ILayoutControl).Model;
			var nextChildModel = (ILayoutPositionableElement)(nextChild as ILayoutControl).Model;

			var ptTopLeftScreen = prevChild.PointToScreenDPIWithoutFlowDirection(new Point());

			Size actualSize;

			if (Orientation == System.Windows.Controls.Orientation.Horizontal)
			{
				actualSize = new Size(
					prevChildActualSize.Width - prevChildModel.CalculatedDockMinWidth() + splitter.ActualWidth + nextChildActualSize.Width - nextChildModel.CalculatedDockMinWidth(),
					nextChildActualSize.Height);

				_resizerGhost.Width = splitter.ActualWidth;
				_resizerGhost.Height = actualSize.Height;
				ptTopLeftScreen.Offset(prevChildModel.CalculatedDockMinWidth(), 0.0);
			}
			else
			{
				actualSize = new Size(
					prevChildActualSize.Width,
					prevChildActualSize.Height - prevChildModel.CalculatedDockMinHeight() + splitter.ActualHeight + nextChildActualSize.Height - nextChildModel.CalculatedDockMinHeight());

				_resizerGhost.Height = splitter.ActualHeight;
				_resizerGhost.Width = actualSize.Width;

				ptTopLeftScreen.Offset(0.0, prevChildModel.CalculatedDockMinHeight());
			}

			_initialStartPoint = splitter.PointToScreenDPIWithoutFlowDirection(new Point()) - ptTopLeftScreen;

			if (Orientation == System.Windows.Controls.Orientation.Horizontal)
				Canvas.SetLeft(_resizerGhost, _initialStartPoint.X);
			else
				Canvas.SetTop(_resizerGhost, _initialStartPoint.Y);

			var panelHostResizer = new Canvas { HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch };
			panelHostResizer.Children.Add(_resizerGhost);

			_resizerWindowHost = new Window
			{
				Style = new Style(typeof(Window), null),
				SizeToContent = System.Windows.SizeToContent.Manual,
				ResizeMode = ResizeMode.NoResize,
				WindowStyle = System.Windows.WindowStyle.None,
				ShowInTaskbar = false,
				AllowsTransparency = true,
				Background = null,
				Width = actualSize.Width,
				Height = actualSize.Height,
				Left = ptTopLeftScreen.X,
				Top = ptTopLeftScreen.Y,
				ShowActivated = false,
				//Owner = Window.GetWindow(this),
				Content = panelHostResizer
			};
			_resizerWindowHost.Loaded += (s, e) => _resizerWindowHost.SetParentToMainWindowOf(this);
			_resizerWindowHost.Show();
		}

19 Source : EditBoxAdorner.cs
with MIT License
from Dirkster99

private void BuildTextBox(EditBox editBox)
        {
            _EditBox = editBox;

            _Canvas = new Canvas();
            _Canvas.Children.Add(_TextBox);
            _VisualChildren.Add(_Canvas);

            // Bind TextBox onto editBox control property Text
            Binding binding = new Binding("Text");
            binding.Source = editBox;
            binding.Mode = BindingMode.TwoWay;
            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            _TextBox.SetBinding(TextBox.TextProperty, binding);

            // Bind Text onto AdornedElement property Text
            binding = new Binding("Text");
            binding.Source = this.AdornedElement;
            binding.Mode = BindingMode.TwoWay;
            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            _TextBox.SetBinding(TextBox.TextProperty, binding);
        }

See More Examples