Example #1
0
        /// <summary>
        /// Select nearby conenctions
        /// </summary>
        /// <param name="e"></param>
        private bool SelectNearLine(MouseButtonEventArgs e)
        {
            var paths = VisualHelper.FindVisualChildren <Path>(this);
            var mouseNeighbourhood = Helper.CreateCenteredRect(e.GetPosition(CanvasItemContainer), new Size(10, 10));

            foreach (Path path in paths)
            {
                if (path.Name == "ConnectionPath")
                {
                    ElementsConnectionViewModel viewModel = path.DataContext as ElementsConnectionViewModel;
                    if (viewModel != null)
                    {
                        List <Rect> rects = Helper.GetPathRects(viewModel);
                        foreach (Rect rect in rects)
                        {
                            if (mouseNeighbourhood.IntersectsWith(rect))
                            {
                                if (e.ChangedButton == MouseButton.Left)
                                {
                                    viewModel.Select();
                                }
                                else if (e.ChangedButton == MouseButton.Right)
                                {
                                    viewModel.IsContextMenuOpened = true;
                                }
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Example #2
0
        private void imagePc_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            MainWindow mainWindow = new MainWindow();
            string     txt;
            Image      img  = (Image)sender;
            var        obj  = img.Parent;
            Grid       grid = (Grid)obj;
            /////////////////////////
            string ip = "", text = "";//ip и имя второго пк

            /////////////////////////
            foreach (var label in VisualHelper.FindVisualChildren <Label>(grid))
            {
                if (label.Name == "label_text")
                {
                    text = label.Content.ToString();
                }
                if (label.Name == "label_ip")
                {
                    ip = label.Content.ToString();
                }
            }

            var    myIp = "127.0.0.1";
            string pass = "******";
            //*********************************
            var nextIp = ip;

            pass = "******";
            loadform(myIp, ip, "", ".");
        }
Example #3
0
 private void ExecuteToggleItemDeleteAllConfirmationCommand(Popup popup)
 {
     popup.Opened += (sender, e) =>
     {
         Keyboard.ClearFocus();
         var firstFocus = VisualHelper.FindVisualChildren <System.Windows.Controls.Button>(popup.Child).FirstOrDefault();
         firstFocus?.Focus();
     };
     popup.IsOpen = !popup.IsOpen;
 }
    private static void OnClick(object sender, RoutedEventArgs routedEventArgs)
    {
        ListBox lb = GetListBox(sender as Button);
        IEnumerable <CheckBox> allCBs = VisualHelper.FindVisualChildren <CheckBox>(lb);

        foreach (CheckBox checkBox in allCBs)
        {
            checkBox.GetBindingExpression(CheckBox.IsCheckedProperty).UpdateSource();
        }
    }
Example #5
0
 private void SetTabControlItemsChangedEventHandler()
 {
     foreach (var item in VisualHelper.FindVisualChildren <TearableTabControl>(this))
     {
         TabHelper.AdjustTabItemWidth(item.Items);
         var view = CollectionViewSource.GetDefaultView(item.Items);
         view.CollectionChanged += TabItem_AdjustWidth;
         item.SizeChanged       += TabControl_AdjustWidthOfTabItems;
     }
 }
 private void listView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
 {
     foreach (var item in VisualHelper.FindVisualChildren <Button>(this))
     {
         if (item.Name == "DownloadButton")
         {
             item.Visibility = Visibility.Visible;
             item.IsEnabled  = true;
         }
     }
 }
Example #7
0
        private void CalculateFontSize()
        {
            double fontSize = this.MaxFontSize;

            List <TextBlock> tbs = VisualHelper.FindVisualChildren <TextBlock>(this.AssociatedObject);

            // get grid height (if limited)
            double gridHeight = double.MaxValue;
            Grid   parentGrid = VisualHelper.FindUpVisualTree <Grid>(this.AssociatedObject.Parent);

            if (parentGrid != null)
            {
                RowDefinition row = parentGrid.RowDefinitions[Grid.GetRow(this.AssociatedObject)];
                gridHeight = row.Height == GridLength.Auto ? double.MaxValue : this.AssociatedObject.ActualHeight;
            }

            foreach (var tb in tbs)
            {
                // get desired size with fontsize = MaxFontSize
                System.Windows.Size desiredSize = MeasureText(tb);
                double widthMargins             = tb.Margin.Left + tb.Margin.Right;
                double heightMargins            = tb.Margin.Top + tb.Margin.Bottom;

                double desiredHeight = desiredSize.Height + heightMargins;
                double desiredWidth  = desiredSize.Width + widthMargins;

                // adjust fontsize if text would be clipped vertically
                if (gridHeight < desiredHeight)
                {
                    double factor = (desiredHeight - heightMargins) / (this.AssociatedObject.ActualHeight - heightMargins);
                    fontSize = Math.Min(fontSize, MaxFontSize / factor);
                }

                // get column width (if limited)
                if (AssociatedObject.ColumnDefinitions.Count > 0)
                {
                    ColumnDefinition col      = this.AssociatedObject.ColumnDefinitions[Grid.GetColumn(tb)];
                    double           colWidth = col.Width == GridLength.Auto ? double.MaxValue : col.ActualWidth;

                    // adjust fontsize if text would be clipped horizontally
                    if (colWidth < desiredWidth)
                    {
                        double factor = (desiredWidth - widthMargins) / (col.ActualWidth - widthMargins);
                        fontSize = Math.Min(fontSize, MaxFontSize / factor);
                    }
                }
            }

            // apply fontsize (always equal fontsizes)
            foreach (var tb in tbs)
            {
                tb.FontSize = fontSize;
            }
        }
Example #8
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            WindowsFormsHost formHost = VisualHelper.FindVisualChildren <WindowsFormsHost>(this).FirstOrDefault();

            PlotViewWrapper pvWrapper = formHost?.Child as PlotViewWrapper;

            if (pvWrapper == null)
            {
                return;
            }
            pvWrapper.GetPlotView().Model = PlotModel;
        }
Example #9
0
        public override void OnApplyTemplate()
        {
            ListBox = ListBox ?? VisualHelper.FindVisualChildren <ListBox>(this).FirstOrDefault();

            if (ListBox != null)
            {
                var myBinding = new Binding
                {
                    Source = this,
                    Path   = new PropertyPath("ItemsList"),
                    Mode   = BindingMode.TwoWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                };

                ListBox.SetBinding(ItemsControl.ItemsSourceProperty, myBinding);
            }
        }
Example #10
0
        // Determines if the width of all textblocks within TextBlockContainer (using MaxFontSize) are wider than the AssociatedObject grid
        private bool CalculateIsClipped()
        {
            double totalDesiredWidth = 0d;
            //Grid grid = VisualHelper.FindVisualChildByName<Grid>(this.AssociatedObject, "TextBlockContainer");
            List <TextBlock> tbs = VisualHelper.FindVisualChildren <TextBlock>(this.AssociatedObject);

            foreach (var tb in tbs)
            {
                if (tb.TextWrapping != TextWrapping.NoWrap)
                {
                    return(false);
                }

                totalDesiredWidth += MeasureText(tb).Width + tb.Margin.Left + tb.Margin.Right + tb.Padding.Left + tb.Padding.Right;
            }

            return(Math.Round(this.AssociatedObject.ActualWidth, 5) < Math.Round(totalDesiredWidth, 5));
        }
Example #11
0
 private void btnClearAllTabs_Click(object sender, RoutedEventArgs e)
 {
     foreach (TearableTabControl tabControl in VisualHelper.FindVisualChildren <TearableTabControl>(this))
     {
         if (tabControl.Name.StartsWith("ttcTest"))
         {
             tabControl.Items.Clear();
         }
     }
     foreach (TearableTabItemWindow tabWindow in tabWindows)
     {
         foreach (TearableTabControl tabControl in VisualHelper.FindVisualChildren <TearableTabControl>(tabWindow))
         {
             if (tabControl.Name.StartsWith("ttcTest"))
             {
                 tabControl.Items.Clear();
             }
         }
     }
 }
Example #12
0
        /// <summary>
        /// Display on the screen the paste bare with an animation.
        /// </summary>
        /// <param name="actionOnHidding">Action to perform when the paste bar is hidden.</param>
        internal void DisplayBar(Action actionOnHidding)
        {
            if (_isDisplayed)
            {
                throw new Exception("Paste bar already displayed.");
            }

            var dataContext = (PasteBarWindowViewModel)DataContext;

            _isDisplayed     = true;
            _actionOnHidding = actionOnHidding;

            var activeScreen = Screen.FromPoint(new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X,
                                                                         System.Windows.Forms.Cursor.Position.Y));
            var screen = SystemInfoHelper.GetAllScreenInfos().Single(s => s.DeviceName == activeScreen.DeviceName);

            InitializePosition(screen);
            InitializeStoryboards(screen);

            Messenger.Default.Register <ComponentModel.Messages.Message>(this, MessageIdentifiers.HidePasteBarWindow,
                                                                         HidePasteBarWindow);

            Show();
            Activate();
            Focus();
            var firstFocus = VisualHelper.FindVisualChildren <System.Windows.Controls.ListBox>(this).FirstOrDefault();

            firstFocus?.Focus();
            Keyboard.Focus(firstFocus);

            Logger.Instance.Information("Paste bar displayed.");
            var delayer = new Delayer <object>(TimeSpan.FromMilliseconds(50));

            delayer.Action += (o, args) => _openingStoryboard.Begin();
            delayer.ResetAndTick();

            dataContext.DisplayBar();
        }
Example #13
0
        private void Active(object sender, RoutedEventArgs e)
        {// обработка шаха область
            //обработка шаха конец сначала для черных
            if (flag)
            {
                firstpos         = sender;
                string[,] massdo = figuresarr.figures;
                bool mogno = rulesmain.rules(figure, firstpos, figuresarr.figures, 0);
                if (hody.hodch)
                {
                    foreach (var image in VisualHelper.FindVisualChildren <Image>(stack))
                    {
                        var figurechah = image as Image;
                        chah = chahblack.rules(figurechah, chkorol, figuresarr.figures, 0);
                        if (chah)
                        {
                            mogno = false;
                            break;
                        }
                    }
                }
                if (hody.hodb)
                {
                    foreach (var image in VisualHelper.FindVisualChildren <Image>(stack))
                    {
                        var figurechah = image as Image;
                        chah = chahwhite.rules(figurechah, bkorol, figuresarr.figures, 0);
                        if (chah)
                        {
                            figuresarr.figures = massdo;
                            mogno = false;
                            break;
                        }
                    }
                }
                string str = "";
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        str += figuresarr.figures[i, j] + i + j + chah + mogno + " ";
                    }
                }
                MessageBox.Show(str);
                if (sender is Image && mogno)
                {
                    hody.hodch = !hody.hodch;
                    hody.hodb  = !hody.hodb;
                    var ii = sender as Image;

                    int column = Grid.GetColumn(ii);
                    int row    = Grid.GetRow(ii);
                    stack.Children.Remove(ii);
                    var figurecopy = figure as Image;

                    string name         = figurecopy.Name;
                    int    columnfigure = Grid.GetColumn(figurecopy);
                    int    rowfigure    = Grid.GetRow(figurecopy);
                    var    figuredelete = figure as Image;
                    stack.Children.Remove(figuredelete);
                    if (figurecopy.Name == "бпешка" && bpeshka.bpeshkarule2(figure, firstpos, figuresarr.figures, 0))
                    {
                        figurecopy.Source = new BitmapImage(new System.Uri("pack://application:,,,/Resources/бферзь.jpeg"));
                        figurecopy.Name   = "бферзь";
                        Grid.SetColumn(figurecopy, column);
                        Grid.SetRow(figurecopy, row);
                        stack.Children.Add(figurecopy);
                        bferz = false;
                    }
                    else
                    {
                        if (figurecopy.Name == "чпешка" && chpeshka.bpeshkarule2(figure, firstpos, figuresarr.figures, 0))
                        {
                            figurecopy.Source = new BitmapImage(new System.Uri("pack://application:,,,/Resources/чферзь.jpg"));
                            figurecopy.Name   = "чферзь";
                            Grid.SetColumn(figurecopy, column);
                            Grid.SetRow(figurecopy, row);
                            stack.Children.Add(figurecopy);
                        }
                        else
                        {
                            Grid.SetColumn(figurecopy, column);
                            Grid.SetRow(figurecopy, row);
                            stack.Children.Add(figurecopy);
                        }
                    }
                    mogno = false;
                    forbor();
                }
                if (sender is Button && mogno)
                {
                    hody.hodch = !hody.hodch;
                    hody.hodb  = !hody.hodb;
                    var ii           = sender as Button;
                    var figurecopy   = figure as Image;
                    int row          = Grid.GetRow(ii);
                    int column       = Grid.GetColumn(ii);
                    var figuredelete = figure as Image;
                    int columnfigure = Grid.GetColumn(figurecopy);
                    int rowfigure    = Grid.GetRow(figurecopy);
                    stack.Children.Remove(figuredelete);
                    if (figurecopy.Name == "бпешка" && bpeshka.bpeshkarule2(figure, firstpos, figuresarr.figures, 0))
                    {
                        figurecopy.Source = new BitmapImage(new System.Uri("pack://application:,,,/Resources/бферзь.jpeg"));
                        figurecopy.Name   = "бферзь";
                        Grid.SetColumn(figurecopy, column);
                        Grid.SetRow(figurecopy, row);
                        stack.Children.Add(figurecopy);
                        bferz = false;
                    }
                    else
                    {
                        if (figurecopy.Name == "чпешка" && chpeshka.bpeshkarule2(figure, firstpos, figuresarr.figures, 0))
                        {
                            figurecopy.Source = new BitmapImage(new System.Uri("pack://application:,,,/Resources/чферзь.jpg"));
                            figurecopy.Name   = "чферзь";
                            Grid.SetColumn(figurecopy, column);
                            Grid.SetRow(figurecopy, row);
                            stack.Children.Add(figurecopy);
                        }
                        else
                        {
                            Grid.SetColumn(figurecopy, column);
                            Grid.SetRow(figurecopy, row);
                            stack.Children.Add(figurecopy);
                        }
                    }
                    mogno = false;
                    forbor();
                }

                flag = false;
                forbor();
            }
            else
            {
                if (sender is Image)
                {
                    ActiveSecond(sender);
                }
            }
        }