public FrameworkElement CreateWidgetControl(IDiagram widgetViewModel, ContextMenu contextMenu) { var buttonHolder = widgetViewModel as DefaultWidgetViewModel; var brd = new Border { DataContext = buttonHolder, ContextMenu = contextMenu, BorderBrush = System.Windows.Media.Brushes.Gray, Background = System.Windows.Media.Brushes.White }; var ret = new Button { DataContext = buttonHolder, ContextMenu = contextMenu, Content = "New Widget" }; brd.Child = ret; var heightBinding = new Binding("Height") { Source = buttonHolder, Mode = BindingMode.TwoWay }; var widthBinding = new Binding("Width") { Source = buttonHolder, Mode = BindingMode.TwoWay }; var xBinding = new Binding("X") { Source = buttonHolder, Mode = BindingMode.TwoWay }; var yBinding = new Binding("Y") { Source = buttonHolder, Mode = BindingMode.TwoWay }; var transformBinding = new Binding("RenderTransform") { Source = buttonHolder, Mode = BindingMode.OneWay }; brd.SetBinding(InkCanvas.LeftProperty, xBinding); brd.SetBinding(InkCanvas.TopProperty, yBinding); brd.SetBinding(FrameworkElement.HeightProperty, heightBinding); brd.SetBinding(FrameworkElement.WidthProperty, widthBinding); brd.SetBinding(UIElement.RenderTransformProperty, transformBinding); return brd; }
// Be sure to call the base class constructor. public BorderSelectionAdorner(TreeViewEx treeViewEx) : base(treeViewEx) { this.treeViewEx = treeViewEx; this.border = new Border { BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(1), Opacity = 0.5 }; Binding brushBinding = new Binding("BorderBrushSelectionRectangle"); brushBinding.Source = treeViewEx; border.SetBinding(Border.BorderBrushProperty, brushBinding); Binding backgroundBinding = new Binding("BackgroundSelectionRectangle"); backgroundBinding.Source = treeViewEx; border.SetBinding(Border.BackgroundProperty, backgroundBinding); layer = AdornerLayer.GetAdornerLayer(treeViewEx); layer.Add(this); }
/// <summary> /// Changes the given control's border based on whether it has focus. /// </summary> /// <param name="sender">The target border.</param> /// <param name="isFocussed">Indicates whether or not the control has focus.</param> public static void ChangeFocusBorder(Border target, bool isFocussed) { if(target == null) { return; } if(isFocussed) { target.SetBinding(Border.BorderBrushProperty, _focusBorderBrushBinding); } else { target.SetBinding(Border.BorderBrushProperty, _defaultForegroundBinding); } }
// Be sure to call the base class constructor. public BorderSelectionAdorner(TreeViewEx treeViewEx) : base(treeViewEx) { this.border = new Border { BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(1), Opacity = 0.5 }; Binding brushBinding = new Binding("BorderBrushSelectionRectangle"); brushBinding.Source = treeViewEx; border.SetBinding(Border.BorderBrushProperty, brushBinding); Binding backgroundBinding = new Binding("BackgroundSelectionRectangle"); backgroundBinding.Source = treeViewEx; border.SetBinding(Border.BackgroundProperty, backgroundBinding); layer = AdornerLayer.GetAdornerLayer(treeViewEx); layer.Add(this); }
/// <summary> /// Initializes a new instance of the <see cref="InlineModalDecorator"/> class. /// </summary> public InlineModalDecorator() { _panel = new Grid(); AddVisualChild(_panel); AddLogicalChild(_panel); _blurrer = new Border { Visibility = Visibility.Collapsed }; _blurrer.SetBinding(StyleProperty, new Binding { Source = this, Path = new PropertyPath(BlurrerStyleProperty) }); _panel.Children.Add(_blurrer); }
protected override System.Runtime.InteropServices.HandleRef BuildWindowCore(System.Runtime.InteropServices.HandleRef hwndParent) { _wpfContentHost = new HwndSource(new HwndSourceParameters() { ParentWindow = hwndParent.Handle, WindowStyle = Win32Helper.WS_CHILD | Win32Helper.WS_VISIBLE | Win32Helper.WS_CLIPSIBLINGS | Win32Helper.WS_CLIPCHILDREN, Width = 1, Height = 1 }); _rootPresenter = new Border() { Child = new AdornerDecorator() { Child = Content }, Focusable = true }; _rootPresenter.SetBinding(Border.BackgroundProperty, new Binding("Background") { Source = _owner }); _wpfContentHost.RootVisual = _rootPresenter; _wpfContentHost.SizeToContent = SizeToContent.Manual; _manager = _owner.Model.Root.Manager; _manager.InternalAddLogicalChild(_rootPresenter); return new HandleRef(this, _wpfContentHost.Handle); }
private void GenerateGrid_Click(object sender, RoutedEventArgs e) { ChristmasLightsGrid dc = (ChristmasLightsGrid) DataContext; dc.Rows = dc.Columns; dc.GenerateGridCommand.Execute(null); for (int y = 0; y < dc.Rows; y++) { LightGrid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(2)}); LightGrid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(2)}); } int i = 0; Stopwatch stopwatch = Stopwatch.StartNew(); for (int x = 0; x < dc.Columns; x++) { for (int y = 0; y < dc.Rows; y++) { Border cell = new Border(); cell.SetBinding(Border.BackgroundProperty, new Binding { Path = new PropertyPath( $"Lights[{i}].Lit"), Source = dc, Converter = new BoolToBrushConverter(), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, IsAsync = true }); Grid.SetColumn(cell, x); Grid.SetRow(cell, y); LightGrid.Children.Add(cell); i++; } } stopwatch.Stop(); TimeSpan span = new TimeSpan(stopwatch.ElapsedTicks); Console.WriteLine($"Time taken for {dc.Columns}x{dc.Rows} grid: {span}"); }
public Grid CreerTerrain() { var grid = new Grid(); for (int x = 0; x < 17; x++) grid.ColumnDefinitions.Add(new ColumnDefinition()); for (int y = 0; y < 20; y++) grid.RowDefinitions.Add(new RowDefinition()); for (int x = 0; x < 20; x++) for (int y = 0; y < 17; y++) { var childrenGrid = new Grid(); var border = new Border(); if (_plateauDeJeu.ZoneList.Exists(a => a.PositionX == x && a.PositionY == y)) { var zone = _plateauDeJeu.ZoneList.First(a => a.PositionX == x && a.PositionY == y); childrenGrid.DataContext = zone; foreach (var objet in zone.ObjetList) { var binding = new Binding("Image"); border.SetBinding(Border.BackgroundProperty, binding); if (objet is PacGomme) zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\point.png", UriKind.Relative))); if (objet is SuperPacGomme) zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\pomme.png", UriKind.Relative))); if (objet is Porte) zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\porte.png", UriKind.Relative))); } childrenGrid.Children.Add(border); } else { border.Background = new SolidColorBrush(Colors.Red); childrenGrid.Children.Add(border); } if (_plateauDeJeu.PersonnageList.Any(a => a.ZoneAbstraite.PositionX == x && a.ZoneAbstraite.PositionY == y)) { var zone = _plateauDeJeu.ZoneList.First(a => a.PositionX == x && a.PositionY == y); var personnage = _plateauDeJeu.PersonnageList.FirstOrDefault(a => a.ZoneAbstraite.PositionX == x && a.ZoneAbstraite.PositionY == y); { if (personnage is PacMan) zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman.png", UriKind.Relative))); if (personnage is Fantome) { var random = new Random(); var res = random.Next(1, 3); switch (res) { case 1: zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman-bleu.png", UriKind.Relative))); break; case 2: zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman-rose.png", UriKind.Relative))); break; case 3: zone.Image = new ImageBrush(new BitmapImage(new Uri("..\\Debug\\Ressources\\Pacman\\Pacman-rouge.png", UriKind.Relative))); break; } } } } childrenGrid.SetValue(Grid.RowProperty, x); childrenGrid.SetValue(Grid.ColumnProperty, y); grid.Children.Add(childrenGrid); } return grid; }
private static void TargetDataGridChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { var footersPresenter = dependencyObject as DataGridFootersPresenter; Debug.Assert(footersPresenter != null, "footersPresenter != null"); var newGrid = dependencyPropertyChangedEventArgs.NewValue as DataGrid; Debug.Assert(newGrid != null, "newGrid != null"); FooterData conatiner = GetFooterContainer(newGrid); foreach (DataGridColumn column in newGrid.Columns) { var columnFooterContent = new TextBlock { TextWrapping = TextWrapping.WrapWithOverflow, TextTrimming = TextTrimming.CharacterEllipsis, FontWeight = FontWeights.SemiBold }; string conent = GetFooterContent(column); if (!string.IsNullOrWhiteSpace(conent)) { columnFooterContent.Text = conent; } string columnId = GetFooterColumnId(column); if (!string.IsNullOrWhiteSpace(columnId)) { columnFooterContent.SetBinding(TextBlock.TextProperty, new Binding(string.Format("[{0}]", columnId)) {Source = conatiner}); } var border = new Border { BorderThickness = new Thickness(0.0f, 0.0f, 0.0f, 0.0f), BorderBrush = new SolidColorBrush(Colors.LightGray) }; var actualWidthBinding = new Binding("ActualWidth") {Source = column}; border.SetBinding(WidthProperty, actualWidthBinding); border.Child = columnFooterContent; footersPresenter.Items.Add(border); } }
/// <summary> /// ORC自动分析图片 /// </summary> /// <param name="filePath"></param> private List <UnChekedWordInfo> AutoExcutePicOCR(string filePath, Microsoft.Office.Interop.Excel.Shape shape) { List <UnChekedWordInfo> listResult = new List <UnChekedWordInfo>(); try { try { APIService service = new APIService(); var userStateInfos = service.GetUserStateByToken(); if (!userStateInfos) { try { CommonExchangeInfo commonExchangeInfo = new CommonExchangeInfo(); commonExchangeInfo.Code = "ShowNotifyMessageView"; commonExchangeInfo.Data = "500"; string jsonData = JsonConvert.SerializeObject(commonExchangeInfo); //序列化 Win32Helper.SendMessage("WordAndImgOperationApp", jsonData); } catch { } return(null); } } catch { return(null); } countWhile = 0; isInitCompleted = false; Dispatcher.Invoke(new System.Action(() => { //清除框选 TextOverlay.Children.Clear(); //生成绑定图片 bitmap = Util.GetBitmapImage(filePath); img.Width = bitmap.PixelWidth; img.Height = bitmap.PixelHeight; img.Source = bitmap; })); ImgGeneralInfo resultImgGeneral = null; try { var image = File.ReadAllBytes(filePath); //集成云处理OCR APIService service = new APIService(); var result = service.GetOCRResultByToken(image); //反序列化 resultImgGeneral = JsonConvert.DeserializeObject <ImgGeneralInfo>(result.ToString().Replace("char", "Char")); ////////var options = new Dictionary<string, object>{ //////// {"recognize_granularity", "small"}, //////// {"vertexes_location", "true"} //////// }; ////////string apiName = ""; ////////try ////////{ //////// apiName = ConfigurationManager.AppSettings["CallAPIName"].ToString(); ////////} ////////catch (Exception ex) ////////{ } ////////DESHelper dESHelper = new DESHelper(); ////////OCR clientOCR = new OCR(dESHelper.DecryptString(ConfigurationManager.AppSettings["APIKey"].ToString()), dESHelper.DecryptString(ConfigurationManager.AppSettings["SecretKey"].ToString())); ////////var result = clientOCR.Accurate(apiName, image, options); //////////反序列化 ////////resultImgGeneral = JsonConvert.DeserializeObject<ImgGeneralInfo>(result.ToString().Replace("char", "Char")); } catch (Exception ex) { CheckWordUtil.Log.TextLog.SaveError(ex.Message); } while (!isInitCompleted && countWhile < 10) { System.Threading.Thread.Sleep(100); countWhile++; } if (resultImgGeneral != null && resultImgGeneral.words_result_num > 0) { string desiredFolderName = CheckWordTempPath + " \\" + Guid.NewGuid().ToString() + "\\"; if (!Directory.Exists(desiredFolderName)) { Directory.CreateDirectory(desiredFolderName); } List <WordInfo> listUnValidInfos = new List <WordInfo>(); foreach (var item in resultImgGeneral.words_result) { string lineWord = ""; List <Rect> rects = new List <Rect>(); foreach (var charInfo in item.Chars) { lineWord += charInfo.Char; rects.Add(new Rect() { X = charInfo.location.left * xScale, Y = charInfo.location.top * yScale, Width = charInfo.location.width * xScale, Height = charInfo.location.height * yScale }); } var listUnChekedWordInfo = CheckWordUtil.CheckWordHelper.GetUnChekedWordInfoList(lineWord); foreach (var itemInfo in listUnChekedWordInfo) { listUnValidInfos.Add(new WordInfo() { UnValidText = itemInfo.Name, AllText = lineWord, Rects = rects }); MatchCollection mc = Regex.Matches(lineWord, itemInfo.Name, RegexOptions.IgnoreCase); if (mc.Count > 0) { foreach (Match m in mc) { var infoResult = listResult.FirstOrDefault(x => x.Name == itemInfo.Name); if (infoResult == null) { itemInfo.UnChekedWordInLineDetailInfos.Add(new UnChekedInLineDetailWordInfo() { TypeTextFrom = "Img", UnCheckWordExcelRangeShape = shape, InLineText = lineWord, ImgResultPath = desiredFolderName + System.IO.Path.GetFileName(filePath) }); itemInfo.ErrorTotalCount++; listResult.Add(itemInfo); } else { infoResult.UnChekedWordInLineDetailInfos.Add(new UnChekedInLineDetailWordInfo() { TypeTextFrom = "Img", UnCheckWordExcelRangeShape = shape, InLineText = lineWord, ImgResultPath = desiredFolderName + System.IO.Path.GetFileName(filePath) }); infoResult.ErrorTotalCount++; } } } } } var list = CheckWordHelper.GetUnValidRects(listUnValidInfos); foreach (var item in list) { try { Dispatcher.Invoke(new System.Action(() => { WordOverlay wordBoxOverlay = new WordOverlay(item); var overlay = new System.Windows.Controls.Border() { Style = (System.Windows.Style) this.Resources["HighlightedWordBoxHorizontalLine"] }; overlay.SetBinding(System.Windows.Controls.Border.MarginProperty, wordBoxOverlay.CreateWordPositionBinding()); overlay.SetBinding(System.Windows.Controls.Border.WidthProperty, wordBoxOverlay.CreateWordWidthBinding()); overlay.SetBinding(System.Windows.Controls.Border.HeightProperty, wordBoxOverlay.CreateWordHeightBinding()); TextOverlay.Children.Add(overlay); })); } catch (Exception ex) { } } if (listUnValidInfos.Count > 0) { System.Threading.Thread.Sleep(50); SavePic(desiredFolderName + System.IO.Path.GetFileName(filePath)); } } } catch (Exception ex) { } return(listResult); }
private StackPanel GeneratePanel(object dataItem) { StackPanel panel = new StackPanel(); panel.Orientation = Orientation.Horizontal; IGanttNode node = (IGanttNode)dataItem; Binding bind = new Binding("Level"); bind.ConverterParameter = dataItem; bind.Mode = BindingMode.OneWay; bind.Converter = new LevelToWidthConverter(); Border b = new Border(); b.BorderThickness = new Thickness(0); b.Background = new SolidColorBrush(Colors.Transparent); b.SetBinding(Border.WidthProperty, bind); bind = new Binding("Expanded"); bind.Mode = BindingMode.TwoWay; SimpleExpander expander = new SimpleExpander(); expander.Visibility = (node.ChildNodes.Count == 0) ? Visibility.Collapsed : Visibility.Visible; expander.IsExpandedChanged += new EventHandler(expander_IsExpandedChanged); expander.SetBinding(SimpleExpander.IsExpandedProperty, bind); panel.Children.Add(b); panel.Children.Add(expander); return panel; }
protected override HandleRef BuildWindowCore(HandleRef hwndParent) { _wpfContentHost = new HwndSource(new HwndSourceParameters() { ParentWindow = hwndParent.Handle, WindowStyle = Win32Helper.WsChild | Win32Helper.WsVisible | Win32Helper.WsClipsiblings | Win32Helper.WsClipchildren, Width = 1, Height = 1 }); _rootPresenter = new Border() {Child = new AdornerDecorator() {Child = Content}, Focusable = true}; _rootPresenter.SetBinding(Border.BackgroundProperty, new Binding("Background") {Source = _owner}); _wpfContentHost.RootVisual = _rootPresenter; _wpfContentHost.SizeToContent = SizeToContent.Manual; _manager = _owner.Model.Root.Manager; _manager.InternalAddLogicalChild(_rootPresenter); return new HandleRef(this, _wpfContentHost.Handle); }
Border GenerateIndent() { var bind = new Binding(LevelPath); bind.Mode = BindingMode.OneWay; bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; bind.Converter = IndentConverter; var b = new Border(); b.BorderThickness = new Thickness(0); b.Background = new SolidColorBrush(Colors.Transparent); b.SetBinding(Border.WidthProperty, bind); return b; }
public DragGrip Clone() { var newItem = new DragGrip { Name = "Cloned" + Guid.NewGuid().ToString().Replace("-", ""), RenderTransform = new TranslateTransform(((TranslateTransform) RenderTransform).X, ((TranslateTransform) RenderTransform).Y), InitialPoint = InitialPoint, IsDragable = false, IsToolBarItem = true, IsSelected = false, ContextMenuName = ContextMenuName, }; var binding = new Binding { RelativeSource = new RelativeSource { Mode = RelativeSourceMode.FindAncestor, AncestorType = typeof (DragGrip) }, Path = new PropertyPath("IsSelected"), Converter = new BoolToIntConverter(), ConverterParameter = "2.5", UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.TwoWay }; var border = new Border { Background = ((Border) Child).Background, Width = ActualWidth, Height = ActualHeight, BorderBrush = Brushes.DeepSkyBlue, Child = new TextBlock { Text = ((TextBlock) ((Border) Child).Child).Text, FontSize = 16, Foreground = Brushes.White, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Margin = ((TextBlock) ((Border) Child).Child).Margin } }; border.SetBinding(Border.BorderThicknessProperty, binding); newItem.ContextMenu = (ContextMenu)((Canvas)Parent).FindResource(ContextMenuName); newItem.Child = border; return newItem; }
/// <summary> /// Regenerate tone display /// </summary> private void refresh() { //Stop if we have the tone collection is not set if (Tones == null) return; //Clear the tone container grdTones.Children.Clear(); //Stop here if there are no tones to display if (Tones.Count == 0) return; //Calculate the width of pixels that is one unit tone duration double width = getBlockWidth(); //Add each tone foreach (var tone in Tones) { //Create the tone border var b = new Border(); //Create the textblock to hold the tone string var t = new TextBlock(); t.Text = tone.KeyString; //Position the tone b.Margin = new Thickness(width * tone.StartBlock, 0, 0, 0); //Bind the tone width var binding = new Binding("Duration"); binding.Source = tone; binding.Converter = new MultiplyConverter(); binding.ConverterParameter = width; b.SetBinding(Border.WidthProperty, binding); //Add the tone to the display b.Child = t; grdTones.Children.Add(b); } padDisplay(); }