public ButtonBarControl(WebcamControl element) { InitializeComponent(); this.parent = element; this.Name = "buttonBar"; int i; buttons=new Button[numberOfButtons]; double buttonSpace = parent.WebcamImage.ActualWidth / numberOfButtons; Style style = new Style(typeof(Button)); style.Setters.Add(new Setter { Property = OverridesDefaultStyleProperty, Value = true }); Setter templateSetter = new Setter(); templateSetter.Property = TemplateProperty; ControlTemplate controlTemplate = new ControlTemplate(typeof(Button)); FrameworkElementFactory fact = new FrameworkElementFactory(typeof(Border)); controlTemplate.VisualTree = fact; fact.Name = "Border"; //fact.SetValue(Border.BorderThicknessProperty, new Thickness(1)); //fact.SetValue(Border.CornerRadiusProperty, new CornerRadius(2)); fact.SetValue(Border.BackgroundProperty,new TemplateBindingExtension(Button.BackgroundProperty)); //fact.SetValue(Border.BorderBrushProperty, Brushes.Aquamarine); Trigger triggerIsMouseOver = new Trigger { Property = Border.IsMouseOverProperty, Value = true }; Binding b = new Binding(); b.RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent); b.Path = new PropertyPath(Button.BorderBrushProperty); Setter setter = new Setter(Border.BackgroundProperty, b, "Border"); triggerIsMouseOver.Setters.Add(setter); controlTemplate.Triggers.Add(triggerIsMouseOver); templateSetter.Value = controlTemplate; style.Setters.Add(templateSetter); for (i = 0; i < numberOfButtons; i++) { buttons[i] = new Button(); //buttons[i].Foreground = new ImageBrush(new BitmapImage(new Uri("test.png", UriKind.Relative))); buttons[i].Style = style; buttons[i].Background = new ImageBrush(new BitmapImage(new Uri((i+1)+"1.png", UriKind.Relative))); buttons[i].BorderBrush = new ImageBrush(new BitmapImage(new Uri((i+1)+"2.png", UriKind.Relative))); //buttons[i].Content = "Button" + i; buttons[i].Width = (buttonSpace-0.1*buttonSpace); buttons[i].Height = 100 - 20; buttons[i].Margin = new Thickness(0.05*buttonSpace, 10, 0.05*buttonSpace, 0); buttons[i].Click += new RoutedEventHandler(ButtonBar_Click); buttonStack.Children.Add(buttons[i]); } }
public ZoomableInlineAdornment(UIElement content, ITextView parent) { _parent = parent; Debug.Assert(parent is IInputElement); Content = new Border { BorderThickness = new Thickness(1), Child = content, Focusable = true }; _zoom = 1.0; // config.GetConfig().Repl.InlineMedia.MaximizedZoom _zoomStep = 0.25; // config.GetConfig().Repl.InlineMedia.ZoomStep _minimizedZoom = 0.25; // config.GetConfig().Repl.InlineMedia.MinimizedZoom _widthRatio = 0.67; // config.GetConfig().Repl.InlineMedia.WidthRatio _heightRatio = 0.5; // config.GetConfig().Repl.InlineMedia.HeightRatio _isResizing = false; UpdateSize(); GotFocus += OnGotFocus; LostFocus += OnLostFocus; ContextMenu = MakeContextMenu(); var trigger = new Trigger { Property = Border.IsFocusedProperty, Value = true }; var setter = new Setter { Property = Border.BorderBrushProperty, Value = SystemColors.ActiveBorderBrush }; trigger.Setters.Add(setter); var style = new Style(); style.Triggers.Add(trigger); MyContent.Style = style; }
public LabelTextBox() { this.AcceptsReturn = true; this.FontWeight = FontWeights.Bold; this.BorderThickness = new Thickness(0); Setter borderSetter = new Setter(); borderSetter.Property = TextBox.BorderThicknessProperty; borderSetter.Value = new Thickness(0); Trigger readOnlyTrigger = new Trigger(); readOnlyTrigger.Property = TextBox.IsReadOnlyProperty; readOnlyTrigger.Value = true; readOnlyTrigger.Setters.Add(borderSetter); Setter borderFocusSetter = new Setter(); borderFocusSetter.Property = TextBox.BorderThicknessProperty; borderFocusSetter.Value = new Thickness(0); Trigger focusTrigger = new Trigger(); focusTrigger.Property = TextBox.IsFocusedProperty; focusTrigger.Value = true; focusTrigger.Setters.Add(borderFocusSetter); Style style = new Style(); style.Triggers.Add(readOnlyTrigger); style.Triggers.Add(focusTrigger); this.Style = style; this.SnapsToDevicePixels = true; }
public AlternatingListBoxBackground(Color color1, Color color2) { var setter = new Setter(); setter.Property = ListBoxItem.BackgroundProperty; setter.Value = new SolidColorBrush(color1); var trigger = new Trigger(); trigger.Property = ItemsControl.AlternationIndexProperty; trigger.Value = 0; trigger.Setters.Add(setter); var setter2 = new Setter(); setter2.Property = ListBoxItem.BackgroundProperty; setter2.Value = new SolidColorBrush(color2); var trigger2 = new Trigger(); trigger2.Property = ItemsControl.AlternationIndexProperty; trigger2.Value = 1; trigger2.Setters.Add(setter2); var listBoxStyle = new Style(typeof(ListBoxItem)); listBoxStyle.Triggers.Add(trigger); listBoxStyle.Triggers.Add(trigger2); _listBoxStyle = listBoxStyle; }
public void WPFStylesOff() { styleButt.Setters.Add(new WPF.Setter { Property = WPF.Controls.Button.FontSizeProperty, Value = 14.0 }); styleButt.Setters.Add(new WPF.Setter { Property = WPF.Controls.Button.FontWeightProperty, Value = WPF.FontWeights.Bold }); WPF.Trigger triggerIsMouseOver = new WPF.Trigger { Property = WPF.Controls.Button.IsMouseOverProperty, Value = true }; // triggerIsMouseOver.Setters.Add( // new Setter(Button.ForegroundProperty, Brushes.Black)); // triggerIsMouseOver.Setters.Add( // new Setter(Button.BackgroundProperty, Brushes.AliceBlue)); triggerIsMouseOver.Setters.Add(new WPF.Setter(WPF.Controls.Button.CursorProperty, System.Windows.Input.Cursors.Hand)); WPF.Trigger triggerIsPressed = new WPF.Trigger { Property = WPF.Controls.Button.IsPressedProperty, Value = true }; triggerIsPressed.Setters.Add(new WPF.Setter(WPF.Controls.Button.BackgroundProperty, WPF.Media.Brushes.Orange)); styleButt.Triggers.Add(triggerIsMouseOver); styleButt.Triggers.Add(triggerIsPressed); }
public TriggerVm(Trigger trigger, IEnumerable<Signal> avalibleSignals) { IS_SAVED = false; _trigger = trigger; _avalibleSignals = avalibleSignals; //Testing var triggerstatedata = new TriggerStateData(_avalibleSignals); var statement = new Statement.Equals(new Signal() { Name = "A1" }, 0); triggerstatedata.StateNumber = 1; //The trigger will always start with one state initially _triggerStateDatas = new List<TriggerStateData>(); _triggerStateDatas.Add(triggerstatedata); ObservableTriggerStates = new ListCollectionView(_triggerStateDatas); _saveCommand = new DelegateCommand<string>( (s) => { SaveTrigger(); }, //Execute (s) => { return _canSave; } //CanExecute ); _saveCommand = new DelegateCommand<string>( (s) => { SaveTrigger(); }, //Execute (s) => { return _canSave; } //CanExecute ); _saveCommand = new DelegateCommand<string>( (s) => { SaveTrigger(); }, //Execute (s) => { return _canSave; } //CanExecute ); }
public EditableTextBlock() { var textBox = new FrameworkElementFactory(typeof(TextBox)); textBox.SetValue(Control.PaddingProperty, new Thickness(1)); // 1px for border textBox.AddHandler(FrameworkElement.LoadedEvent, new RoutedEventHandler(TextBox_Loaded)); textBox.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown)); textBox.AddHandler(UIElement.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus)); textBox.SetBinding(TextBox.TextProperty, new System.Windows.Data.Binding("Text") { Source = this, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); var editTemplate = new DataTemplate { VisualTree = textBox }; var textBlock = new FrameworkElementFactory(typeof(TextBlock)); textBlock.SetValue(FrameworkElement.MarginProperty, new Thickness(2)); textBlock.AddHandler(UIElement.MouseDownEvent, new MouseButtonEventHandler(TextBlock_MouseDown)); textBlock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding("Text") { Source = this }); var viewTemplate = new DataTemplate { VisualTree = textBlock }; var style = new System.Windows.Style(typeof(EditableTextBlock)); var trigger = new Trigger { Property = IsInEditModeProperty, Value = true }; trigger.Setters.Add(new Setter { Property = ContentTemplateProperty, Value = editTemplate }); style.Triggers.Add(trigger); trigger = new Trigger { Property = IsInEditModeProperty, Value = false }; trigger.Setters.Add(new Setter { Property = ContentTemplateProperty, Value = viewTemplate }); style.Triggers.Add(trigger); Style = style; }
public TriggerVm(Trigger trigger, IEnumerable<Signal> avalibleSignals) { IS_SAVED = false; _trigger = trigger; _avalibleSignals = avalibleSignals; //The trigger will always start with one state initially _triggerStateDatas = new List<TriggerStateDataModel>(); _triggerStateDatas.Add(new TriggerStateDataModel(_avalibleSignals)); ObservableTriggerStates = new ListCollectionView(_triggerStateDatas); _saveCommand = new DelegateCommand<string>( (s) => { SaveTrigger(); }, //Execute (s) => { return true; } //CanExecute ); _addCommand = new DelegateCommand<string>( (s) => { AddState(); }, //Execute (s) => { return true; } //CanExecute ); _removeCommand = new DelegateCommand<string>( (s) => { RemoveState(); }, //Execute (s) => { return true; } //CanExecute ); }
/// <summary> /// Initialises a new instance of the MenuIconImage class. /// </summary> public MenuIconImage() { Style imgStyle = new Style(typeof(Image)); Trigger trg = new Trigger(); trg.Property = Image.IsEnabledProperty; trg.Value = false; Setter setter = new Setter(Image.OpacityProperty, 0.5); trg.Setters.Add(setter); imgStyle.Triggers.Add(trg); this.Style = imgStyle; }
public void setBackgroundImage(string normal_image_uri, string pressed_image_uri) { Style style = new Style(); style.Setters.Add(new Setter(ForegroundProperty, MetrialColor.getBrush(MetrialColor.Name.White))); // Normal ControlTemplate normal_button_template = new ControlTemplate(typeof(Button)); FrameworkElementFactory normal_button_shape = new FrameworkElementFactory(typeof(Ellipse)); normal_button_shape.SetValue(Shape.FillProperty, makeImageBrush(normal_image_uri)); //normal_button_shape.SetValue(Shape.StrokeProperty, Brushes.White); //normal_button_shape.SetValue(Shape.StrokeThicknessProperty, 2.0); FrameworkElementFactory normal_button_content_presenter = new FrameworkElementFactory(typeof(ContentPresenter)); normal_button_content_presenter.SetValue(ContentProperty, new TemplateBindingExtension(ContentProperty)); normal_button_content_presenter.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center); normal_button_content_presenter.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center); FrameworkElementFactory normal_button_merged_element = new FrameworkElementFactory(typeof(Grid)); normal_button_merged_element.AppendChild(normal_button_shape); normal_button_merged_element.AppendChild(normal_button_content_presenter); normal_button_template.VisualTree = normal_button_merged_element; style.Setters.Add(new Setter(TemplateProperty, normal_button_template)); // For Pressed Trigger button_pressed_trigger = new Trigger(); button_pressed_trigger.Property = Button.IsPressedProperty; button_pressed_trigger.Value = true; ControlTemplate pressed_button_template = new ControlTemplate(typeof(Button)); FrameworkElementFactory pressed_button_shape = new FrameworkElementFactory(typeof(Ellipse)); pressed_button_shape.SetValue(Shape.FillProperty, makeImageBrush(pressed_image_uri)); //pressed_button_shape.SetValue(Shape.StrokeProperty, Brushes.White); //pressed_button_shape.SetValue(Shape.StrokeThicknessProperty, 2.0); FrameworkElementFactory pressed_button_button_content_presenter = new FrameworkElementFactory(typeof(ContentPresenter)); pressed_button_button_content_presenter.SetValue(ContentProperty, new TemplateBindingExtension(ContentProperty)); pressed_button_button_content_presenter.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center); pressed_button_button_content_presenter.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center); FrameworkElementFactory pressed_button_mreged_element = new FrameworkElementFactory(typeof(Grid)); pressed_button_mreged_element.AppendChild(pressed_button_shape); pressed_button_mreged_element.AppendChild(pressed_button_button_content_presenter); pressed_button_template.VisualTree = pressed_button_mreged_element; button_pressed_trigger.Setters.Add(new Setter(TemplateProperty, pressed_button_template)); style.Triggers.Add(button_pressed_trigger); button.Style = style; }
public BuildButtonFactory() { Title = "Build Button Factory"; ControlTemplate template = new ControlTemplate(typeof(Button)); FrameworkElementFactory factoryBorder = new FrameworkElementFactory(typeof(Border)); factoryBorder.Name = "border"; factoryBorder.SetValue(Border.BorderBrushProperty, Brushes.Red); factoryBorder.SetValue(Border.BorderThicknessProperty, new Thickness(3)); factoryBorder.SetValue(Border.BackgroundProperty, SystemColors.ControlLightBrush); FrameworkElementFactory factoryContent = new FrameworkElementFactory(typeof(ContentPresenter)); factoryContent.Name = "content"; factoryContent.SetValue(ContentPresenter.ContentProperty, new TemplateBindingExtension(Button.ContentProperty)); factoryContent.SetValue(ContentPresenter.MarginProperty, new TemplateBindingExtension(Button.PaddingProperty)); factoryBorder.AppendChild(factoryContent); template.VisualTree = factoryBorder; Trigger trig = new Trigger(); trig.Property = UIElement.IsMouseOverProperty; trig.Value = true; Setter set = new Setter(); set.Property = Border.CornerRadiusProperty; set.Value = new CornerRadius(24); set.TargetName = "border"; trig.Setters.Add(set); set = new Setter(); set.Property = Control.FontStyleProperty; set.Value = FontStyles.Italic; trig.Setters.Add(set); template.Triggers.Add(trig); Button btn = new Button(); btn.Template = template; btn.Content = "Button with Custom Template"; btn.Padding = new Thickness(20); btn.FontSize = 48; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.VerticalAlignment = VerticalAlignment.Center; btn.Click += ButtonOnClick; Content = btn; }
public void FillTreeView(IEnumerable<ArticleGroup> groups, IEnumerable<Article> articles, TreeView treeView) { treeView.Items.Clear(); var res = GroupHelper.Instance.GetGroups(groups, articles); foreach (var groupViewItem in res.GroupViewItems) { var treeViewItem = new TreeViewItem { Header = string.Format("{0}({1})", groupViewItem.Name, groupViewItem.ArticlesCount), ToolTip = string.Format("{0}({1})", groupViewItem.Name, groupViewItem.ArticlesCount), FontSize = 14, BorderThickness = new Thickness(2), FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Stretch, }; DependencyProperty pr = Border.CornerRadiusProperty; var style = new Style(typeof(TreeViewItem)); var borderStyle = new Style(typeof(Border)); borderStyle.Setters.Add(new Setter(pr, new CornerRadius(10))); style.Resources.Add("", borderStyle); var trigger = new Trigger { Property = TreeViewItem.IsSelectedProperty, Value = true, }; trigger.Setters.Add(new Setter(TreeViewItem.BorderBrushProperty, new SolidColorBrush(Color.FromRgb(0x7d, 0xA2, 0xce)))); style.Triggers.Add(trigger); treeViewItem.ItemContainerStyle = style; foreach (var article in groupViewItem.Articles) { treeViewItem.Items.Add(new TreeViewItem { Header = article.ArticleName, ToolTip = article.ArticleName, Name = _suffix + article.ArticleId, FontSize = 14, BorderThickness = new Thickness(2), FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Stretch, ItemContainerStyle = style }); } treeView.Items.Add(treeViewItem); } }
public TriggerVm(Trigger trigger, IEnumerable<Signal> avalibleSignals) { IS_SAVED = false; _trigger = trigger; _statementString = ""; _avalibleSignals = avalibleSignals; _addStatementCommand = new DelegateCommand<string>( (s) => { EditStatement(); }, //Execute (s) => { return true; } //CanExecute ); _saveCommand = new DelegateCommand<string>( (s) => { SaveTrigger(); }, //Execute (s) => { return _canSave; } //CanExecute ); }
public ZoomableInlineAdornment(UIElement content, ITextView parent) { _parent = parent; Debug.Assert(parent is IInputElement); this.Content = new Border { BorderThickness = new Thickness(1), Child = content, Focusable = true }; _zoom = 1.0; // config.GetConfig().Repl.InlineMedia.MaximizedZoom _zoomStep = 0.25; // config.GetConfig().Repl.InlineMedia.ZoomStep _minimizedZoom = 0.25; // config.GetConfig().Repl.InlineMedia.MinimizedZoom _widthRatio = 0.67; // config.GetConfig().Repl.InlineMedia.WidthRatio _heightRatio = 0.5; // config.GetConfig().Repl.InlineMedia.HeightRatio _isResizing = false; UpdateSize(); this.PreviewMouseLeftButtonDown += (s, e) => { if (MyContent.IsFocused) { Keyboard.Focus(MyParent); e.Handled = true; } }; this.MouseRightButtonDown += (s, e) => { // The editor doesn't support context menus, so even for an // adornment we have to open it explicitly ContextMenu.IsOpen = true; }; this.GotFocus += OnGotFocus; this.LostFocus += OnLostFocus; ContextMenu = MakeContextMenu(); var trigger = new Trigger { Property = IsFocusedProperty, Value = true }; var setter = new Setter { Property = Border.BorderBrushProperty, Value = SystemColors.ActiveBorderBrush }; trigger.Setters.Add(setter); var style = new Style(); style.Triggers.Add(trigger); this.MyContent.Style = style; }
private void setColor(Button button, MetrialColor.Name color_name) { Style style = new Style(); style.Setters.Add(new Setter(BackgroundProperty, MetrialColor.getBrush(color_name, 3))); style.Setters.Add(new Setter(ForegroundProperty, MetrialColor.getBrush(MetrialColor.Name.White))); Trigger button_pressed_trigger = new Trigger(); //mouse_over_trigger.Property = UIElement.IsMouseOverProperty; button_pressed_trigger.Property = Button.IsPressedProperty; button_pressed_trigger.Value = true; button_pressed_trigger.Setters.Add(new Setter(BackgroundProperty, MetrialColor.getBrush(color_name, 4))); button_pressed_trigger.Setters.Add(new Setter(BorderThicknessProperty, new Thickness(5))); button_pressed_trigger.Setters.Add(new Setter(BorderBrushProperty, MetrialColor.getBrush(color_name, 1))); style.Triggers.Add(button_pressed_trigger); ControlTemplate control_template = new ControlTemplate(typeof(Button)); var border = new FrameworkElementFactory(typeof(Border)); border.Name = "button_border"; border.SetValue(BorderThicknessProperty, new Thickness(0)); border.SetValue(BorderBrushProperty, MetrialColor.getBrush(color_name, 3)); var binding = new TemplateBindingExtension(); binding.Property = BackgroundProperty; border.SetValue(BackgroundProperty, binding); /* border color change on mouse pressed Trigger mouse_over_trigger_border = new Trigger(); mouse_over_trigger_border.Property = Button.IsPressedProperty; mouse_over_trigger_border.Value = true; mouse_over_trigger_border.Setters.Add(new Setter(BorderBrushProperty, MetrialColor.getBrush(mItem.getColorName(), 3), "button_border")); control_template.Triggers.Add(mouse_over_trigger_border); */ FrameworkElementFactory content_presenter = new FrameworkElementFactory(typeof(ContentPresenter)); content_presenter.SetValue(ContentPresenter.HorizontalAlignmentProperty, HorizontalAlignment.Center); content_presenter.SetValue(ContentPresenter.VerticalAlignmentProperty, VerticalAlignment.Center); border.AppendChild(content_presenter); control_template.VisualTree = border; style.Setters.Add(new Setter(TemplateProperty, control_template)); button.Style = style; }
public TextBoxAdv_V0() { var p = new System.Windows.Media.VisualBrush(); p.AlignmentX = System.Windows.Media.AlignmentX.Left; // 控制 PlaceHolder 位置 p.AlignmentY = System.Windows.Media.AlignmentY.Center; // 控制 PlaceHolder 位置 p.Stretch = System.Windows.Media.Stretch.None; p.TileMode = System.Windows.Media.TileMode.None; mPlaceHolderTextBlock = new TextBlock(); mPlaceHolderTextBlock.Width = double.NaN; mPlaceHolderTextBlock.FontStyle = System.Windows.FontStyles.Italic; mPlaceHolderTextBlock.Foreground = System.Windows.Media.Brushes.Silver; p.Visual = mPlaceHolderTextBlock; this.Resources.Add("txtPlaceholder", p); var style = new System.Windows.Style(); style.TargetType = typeof(TextBoxAdv_V0); #region PlaceHolder 触发器 -- 当 NULL 或 string.Empty 时显示 PlaceHolder 内容 var tiggerWhenNull = new System.Windows.Trigger(); tiggerWhenNull.Property = TextBoxAdv_V0.TextProperty; tiggerWhenNull.Value = null; tiggerWhenNull.Setters.Add(new System.Windows.Setter(TextBoxAdv_V0.BackgroundProperty, p)); style.Triggers.Add(tiggerWhenNull); var tiggerWhenStringEmpty = new System.Windows.Trigger(); tiggerWhenStringEmpty.Property = TextBoxAdv_V0.TextProperty; tiggerWhenStringEmpty.Value = ""; tiggerWhenStringEmpty.Setters.Add(new System.Windows.Setter(TextBoxAdv_V0.BackgroundProperty, p)); style.Triggers.Add(tiggerWhenStringEmpty); #endregion this.Style = style; }
public PluginWords(SQLiteConnection db) { db_ = db; db.CreateTable<WordMap>(); words_ = new ObservableCollection<WordMap>(db.Table<WordMap>().OrderBy(x => x.Word)); foreach (WordMap newItem in words_) { newItem.PropertyChanged += this.OnItemPropertyChanged; } words_.CollectionChanged += this.OnCollectionChanged; yesStyle_ = new Style(); Trigger omo; omo = new Trigger() { Property = UIElement.IsMouseOverProperty, Value = true }; omo.Setters.Add(new Setter(Control.BackgroundProperty, Brushes.Gainsboro)); yesStyle_.Triggers.Add(omo); omo = new Trigger() { Property = UIElement.IsMouseOverProperty, Value = false }; omo.Setters.Add(new Setter(Control.BackgroundProperty, Brushes.Transparent)); yesStyle_.Triggers.Add(omo); }
public void WPFStyles() { ///WPF styles redefinition /// //styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.OverridesDefaultStyleProperty, false)); //styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.TemplateProperty, true)); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.SnapsToDevicePixelsProperty, true)); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.FocusableProperty, false)); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.FocusVisualStyleProperty, null)); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.AllowDropProperty, true)); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.HorizontalAlignmentProperty, WPF.HorizontalAlignment.Left)); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.VerticalAlignmentProperty, WPF.VerticalAlignment.Top)); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.WidthProperty, Convert.ToDouble(SettingsIO.TileWidth))); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.HeightProperty, Convert.ToDouble(SettingsIO.TileHeight))); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.PaddingProperty, new WPF.Thickness(-4))); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.BorderThicknessProperty, new WPF.Thickness(0))); styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.BorderBrushProperty, WPF.Media.Brushes.Transparent)); //styleButt.Setters.Add(new WPF.Setter(WPF.Controls.Button.BackgroundProperty, WPF.Media.Brushes.Tan)); styleMetroBlu.Setters.Add(new WPF.Setter(WPF.Controls.Button.BackgroundProperty, WPF.Media.Brushes.Red)); styleButt.BasedOn = styleMetroBlu; WPF.Trigger triggerIsPressed = new WPF.Trigger { Property = WPF.Controls.Button.IsPressedProperty, Value = true }; triggerIsPressed.Setters.Add(new WPF.Setter(WPF.Controls.Button.BackgroundProperty, WPF.Media.Brushes.Orange)); triggerIsPressed.Setters.Add(new WPF.Setter(WPF.Controls.Button.BorderThicknessProperty, new WPF.Thickness(0))); triggerIsPressed.Setters.Add(new WPF.Setter(WPF.Controls.Button.BorderBrushProperty, WPF.Media.Brushes.Transparent)); styleButt.Triggers.Add(triggerIsPressed); styleLbl.Setters.Add(new WPF.Setter(WPF.Controls.Label.HorizontalAlignmentProperty, WPF.HorizontalAlignment.Left)); styleLbl.Setters.Add(new WPF.Setter(WPF.Controls.Label.VerticalAlignmentProperty, WPF.VerticalAlignment.Top)); styleLbl.Setters.Add(new WPF.Setter(WPF.Controls.Label.ForegroundProperty, GeneralUtils.ColorToBrush(SettingsIO.MetroText))); styleLbl.Setters.Add(new WPF.Setter(WPF.Controls.Label.FontFamilyProperty, new WPF.Media.FontFamily(SettingsIO.TileFontFamily))); styleLbl.Setters.Add(new WPF.Setter(WPF.Controls.Label.FontSizeProperty, SettingsIO.TileFontSize)); styleLbl.Setters.Add(new WPF.Setter(WPF.Controls.Label.IsHitTestVisibleProperty, false)); }
private static Style CreateHyperLinkStyle() { // this completely override existing hyperlink style. // I couldn't find one that does this for me or change existing style little bit for my purpose. var style = new Style(typeof(Hyperlink)); style.Setters.Add(new Setter { Property = Hyperlink.ForegroundProperty, Value = GetBrush(EnvironmentColors.ControlLinkTextBrushKey) }); style.Setters.Add(new Setter { Property = Hyperlink.TextDecorationsProperty, Value = null }); var mouseOverTrigger = new Trigger { Property = Hyperlink.IsMouseOverProperty, Value = true }; mouseOverTrigger.Setters.Add(new Setter { Property = Hyperlink.ForegroundProperty, Value = GetBrush(EnvironmentColors.ControlLinkTextHoverBrushKey) }); style.Triggers.Add(mouseOverTrigger); var disabledTrigger = new Trigger { Property = Hyperlink.IsEnabledProperty, Value = false }; disabledTrigger.Setters.Add(new Setter { Property = Hyperlink.ForegroundProperty, Value = GetBrush(EnvironmentColors.PanelHyperlinkDisabledBrushKey) }); style.Triggers.Add(disabledTrigger); var enabledTrigger = new Trigger { Property = Hyperlink.IsEnabledProperty, Value = true }; enabledTrigger.Setters.Add(new Setter { Property = Hyperlink.CursorProperty, Value = Cursors.Hand }); style.Triggers.Add(enabledTrigger); return style; }
private void AddTextBoxErrResource() { Style style = new Style(typeof(TextBox)); Trigger trigger = new Trigger() { Property = Validation.HasErrorProperty, Value = true }; Setter triggerSetter = new Setter(Control.ToolTipProperty, ErrorMessage); trigger.Setters.Add(triggerSetter); style.Triggers.Add(trigger); Source.Resources.Add(typeof(TextBox), style); }
private void MultiTrigger_AddTriggerClicked(Controls.MultiTrigger sender) { if (sender.ParentMultiTrigger != null && sender.ParentValue != null && sender.ParentEvent != null) { if (sender.ParentEvent.values.Contains(sender.ParentValue)) { Controls.Event e = events.Find(x => x.ParentEvent == sender.ParentEvent); if (e != null) { int index = e.Values.ToList().FindIndex(x => x.ParentValue == sender.ParentValue); if (index >= 0) { Controls.Value v = e.Values[index]; if (v != null) { var t = new Trigger(); Controls.Trigger tr = CreateTrigger(t, sender.ParentValue, sender.ParentEvent); sender.ParentMultiTrigger.triggers.Add(t); tr.modifier_COMBO.SelectedItem = "Equal To"; sender.Triggers.Add(tr); } } } } } }
void Event_AddValueClicked(Controls.Event e) { if (e.ParentEvent != null) { var value = new Value(); e.ParentEvent.values.Add(value); var uiValue = CreateValue(value, e.ParentEvent); var t = new Trigger(); uiValue.ParentValue.triggers.Add(t); Controls.Trigger tr = CreateTrigger(t, uiValue.ParentValue, uiValue.ParentEvent); tr.modifier_COMBO.SelectedItem = "Equal To"; uiValue.Triggers.Add(tr); e.Values.Add(uiValue); } ChangeSetting(null, null, null); }
Controls.Trigger CreateTrigger(Trigger t, Value v, Event e) { var result = new Controls.Trigger(); result.ParentPage = this; result.ParentEvent = e; result.ParentValue = v; result.ParentTrigger = t; result.SettingChanged += Trigger_SettingChanged; result.RemoveClicked += Trigger_RemoveClicked; foreach (CollectedItem item in CollectedItems) { result.DataItems.Add(item.Id); } result.LinkType = t.linkType; //result.link_COMBO.Text = t.link; result.SelectedLink = t.link; //result.SelectedLink = t.link; result.modifier_COMBO.SelectedItem = t.modifier; result.value_COMBO.SelectedItem = t.value; result.Value = t.value; return result; }
static Trigger GetTriggerFromRow(Value v, DataRow row) { Trigger result = null; string adr = row["address"].ToString(); if (DataTable_Functions.TrakHound.GetLastNode(row) == "Trigger") { int eventIndex = adr.LastIndexOf("Trigger"); int slashIndex = adr.IndexOf('/', eventIndex) + 1; int separatorIndex = adr.IndexOf("||", slashIndex); if (separatorIndex > slashIndex) { string val = row["value"].ToString(); string strId = adr.Substring(separatorIndex + 2, 2); int id; if (int.TryParse(strId, out id)) { result = new Trigger(); result.id = id; result.linkType = DataTable_Functions.TrakHound.GetRowAttribute("link_type", row); if (result.linkType == null) result.linkType = "ID"; result.link = DataTable_Functions.TrakHound.GetRowAttribute("link", row); result.value = DataTable_Functions.TrakHound.GetRowAttribute("value", row); string modifier = "Equal To"; string mod = DataTable_Functions.TrakHound.GetRowAttribute("modifier", row); if (mod != null) { switch (mod.ToLower()) { case "not": modifier = "Not Equal To"; break; case "greater_than": modifier = "Greater Than"; break; case "less_than": modifier = "Less Than"; break; case "contains": modifier = "Contains"; break; case "contains_match_case": modifier = "Contains Match Case"; break; case "contains_whole_word": modifier = "Contains Whole Word"; break; case "contains_whole_word_match_case": modifier = "Contains Whole Word Match Case"; break; } } result.modifier = modifier; } } } return result; }
void Value_AddTriggerClicked(Controls.Value val) { if (val.ParentValue != null && val.ParentEvent != null) { if (val.ParentEvent.values.Contains(val.ParentValue)) { Controls.Event e = events.Find(x => x.ParentEvent == val.ParentEvent); if (e != null) { int index = e.Values.ToList().FindIndex(x => x.ParentValue == val.ParentValue); if (index >= 0) { Controls.Value v = e.Values[index]; if (v != null) { var t = new Trigger(); val.ParentValue.triggers.Add(t); Controls.Trigger tr = CreateTrigger(t, val.ParentValue, val.ParentEvent); tr.modifier_COMBO.SelectedItem = "Equal To"; val.Triggers.Add(tr); } } } } } }
private void ShowSortedItemsInGraph(List<ItemSize> SortedItemList) { bool hasBoundary = true; Brush boundaryBrush = Brushes.Black; double boundaryThickness = 0.5; Point pieCenter = new Point(PIE_RADIUS, PIE_RADIUS); Point startPoint = new Point(PIE_RADIUS, 0); //Set bitmap effect for the pie graph #pragma warning disable 0618 PieGraph.BitmapEffect = new BevelBitmapEffect(); #pragma warning restore 0618 //Move the center of the pie view to the origin of the canvas (canvas origin is located at the center of the view) ScaleTransform scale = new ScaleTransform(absScaleFactor, absScaleFactor); TransformGroup trasfm = new TransformGroup(); trasfm.Children.Add(new TranslateTransform(-PIE_RADIUS, -PIE_RADIUS)); trasfm.Children.Add(scale); PieGraph.RenderTransform = trasfm; for (int i = 0; i < SortedItemList.Count; i++) { var item = SortedItemList[i]; double angle = 360 * item.Percentage; if (angle >= 360) angle = 360 - 1e-5; RotateTransform rotate = new RotateTransform(angle, pieCenter.X, pieCenter.Y); Point endPoint = rotate.Transform(startPoint); //Draw a fan shape PathFigure fig = new PathFigure(); fig.StartPoint = pieCenter; fig.IsClosed = hasBoundary; fig.Segments.Add(new LineSegment(startPoint, hasBoundary)); fig.Segments.Add(new ArcSegment(endPoint, new Size(PIE_RADIUS, PIE_RADIUS), 0, angle > 180, SweepDirection.Clockwise, hasBoundary)); fig.Segments[0].IsSmoothJoin = fig.Segments[1].IsSmoothJoin = true; PathGeometry geo = new PathGeometry(); geo.Figures.Add(fig); //Set color and boundary line for current fan shape System.Windows.Shapes.Path fan = new System.Windows.Shapes.Path(); fan.Fill = PieColors[i % PieColors.Length]; fan.Stroke = boundaryBrush; fan.StrokeThickness = boundaryThickness; fan.Data = geo; //Add tooptip for current fan shape ToolTip tip = new ToolTip(); //A colored rectangle used as an icon of the tooltip Rectangle tipIcon = new Rectangle(); tipIcon.Width = tipIcon.Height = 40; tipIcon.Fill = fan.Fill; tipIcon.Margin = new Thickness(0, 0, 4, 0); //Tooltip message TextBox tipMsg = new TextBox(); string name = (item.IsFolder) ? "[" + item.Name + "]" : item.Name; tipMsg.Text = String.Format("{0}\n{1} Bytes\n{2}%", name, item.Size.ToString("n0"), (item.Percentage * 100).ToString("n2")); //Assembly tooltip icon and message into a panel and set it to the fan shape tooltip StackPanel tipPanel = new StackPanel(); tipPanel.Orientation = Orientation.Horizontal; tipPanel.Children.Add(tipIcon); tipPanel.Children.Add(tipMsg); tip.Content = tipPanel; fan.ToolTip = tip; //Add a trigger to current fan so that it is highlighted when mouse is over it Trigger trigger = new Trigger(); trigger.Property = System.Windows.Shapes.Path.IsMouseOverProperty; trigger.Value = true; trigger.Setters.Add(new Setter(System.Windows.Shapes.Path.OpacityProperty, 0.6)); Style style = new Style(); style.Triggers.Add(trigger); fan.Style = style; //Add current fan to the graph PieGraph.Children.Add(fan); startPoint = endPoint; } }
void SaveTrigger(Trigger t, Value v, Event e, DataTable dt, string addressPrefix) { if (t.link != null && t.modifier != null) { string adr = addressPrefix + "/Trigger"; int id = DataTable_Functions.TrakHound.GetUnusedAddressId(adr, dt); adr = adr + "||" + id.ToString("00"); t.id = id; // Save Root string attr = ""; attr += "id||" + t.id.ToString("00") + ";"; string link = t.link; List<CollectedItem> linkitems = CollectedItems.ToList(); CollectedItem dataitem = linkitems.Find(x => x.Display == link); if (dataitem != null) link = dataitem.Id; attr += "link||" + link + ";"; attr += "link_type||" + t.linkType + ";"; if (t.modifier != null) { switch (t.modifier) { case "Not Equal To": attr += "modifier||" + "not" + ";"; break; case "Greater Than": attr += "modifier||" + "greater_than" + ";"; break; case "Less Than": attr += "modifier||" + "less_than" + ";"; break; case "Contains": attr += "modifier||" + "contains" + ";"; break; case "Contains Match Case": attr += "modifier||" + "contains_match_case" + ";"; break; case "Contains Whole Word": attr += "modifier||" + "contains_whole_word" + ";"; break; case "Contains Whole Word Match Case": attr += "modifier||" + "contains_whole_word_match_case" + ";"; break; } } attr += "value||" + t.value + ";"; DataTable_Functions.UpdateTableValue(dt, "address", adr, "attributes", attr); } }
void SaveTrigger(Trigger t, Value v, Event e, DataTable dt) { string adr = "/GeneratedData/GeneratedEvents/Event||" + e.id.ToString("00"); adr += "/Value||" + v.id.ToString("00") + "/Triggers"; SaveTrigger(t, v, e, dt, adr); }
public override DependencyObject CreateTrigger(StyleSheet styleSheet, ITrigger trigger, Type targetType, DependencyObject styleResourceReferenceHolder) { if (trigger == null) { throw new ArgumentNullException(nameof(trigger)); } if (trigger is Trigger) { var propertyTrigger = trigger as Trigger; var nativeTrigger = new System.Windows.Trigger(); var dependencyProperty = dependencyService.GetBindableProperty(targetType, propertyTrigger.Property); if (dependencyProperty == null) { throw new NullReferenceException($"Property '{propertyTrigger.Property}' may not be null (targetType '{targetType.Name}')!"); } nativeTrigger.Property = dependencyProperty; nativeTrigger.Value = dependencyService.GetBindablePropertyValue(targetType, nativeTrigger.Property, propertyTrigger.Value); foreach (var styleDeclaration in propertyTrigger.StyleDeclarationBlock) { var property = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, targetType, styleDeclaration.Property); if (property == null) { continue; } try { var value = typeNameResolver.GetPropertyValue(targetType, styleResourceReferenceHolder, styleDeclaration.Value, property, styleSheet.Namespaces); if (value is string valueString) { value = TypeDescriptor.GetConverter(property.PropertyType)?.ConvertFromInvariantString(valueString) ?? value; } nativeTrigger.Setters.Add(new Setter { Property = property, Value = value }); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value} - {styleDeclaration.Property}: {styleDeclaration.Value}"": {e.Message}"); } } foreach (var action in propertyTrigger.EnterActions) { try { var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action); nativeTrigger.EnterActions.Add(nativeTriggerAction); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value}"" enter action: {e.Message}"); } } foreach (var action in propertyTrigger.ExitActions) { try { var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action); nativeTrigger.ExitActions.Add(nativeTriggerAction); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value}"" exit action: {e.Message}"); } } return(nativeTrigger); } else if (trigger is DataTrigger) { var dataTrigger = trigger as DataTrigger; var nativeTrigger = new System.Windows.DataTrigger(); var expression = "{Binding " + dataTrigger.Binding + "}"; var binding = (System.Windows.Data.BindingBase)markupExtensionParser.ProvideValue(expression, null, styleSheet.Namespaces); nativeTrigger.Binding = binding; nativeTrigger.Value = GetBasicValue(dataTrigger); foreach (var styleDeclaration in dataTrigger.StyleDeclarationBlock) { try { var property = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, targetType, styleDeclaration.Property); if (property == null) { continue; } var value = typeNameResolver.GetPropertyValue(targetType, styleResourceReferenceHolder, styleDeclaration.Value, property, styleSheet.Namespaces); if (value is string valueString) { value = TypeDescriptor.GetConverter(property.PropertyType)?.ConvertFromInvariantString(valueString) ?? value; } nativeTrigger.Setters.Add(new Setter { Property = property, Value = value }); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {styleDeclaration.Property}: {styleDeclaration.Value}"": {e.Message}"); } } foreach (var action in dataTrigger.EnterActions) { try { var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action); nativeTrigger.EnterActions.Add(nativeTriggerAction); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {action}"" enter action: {e.Message}"); } } foreach (var action in dataTrigger.ExitActions) { try { var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action); nativeTrigger.ExitActions.Add(nativeTriggerAction); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {action}"" exit action: {e.Message}"); } } return(nativeTrigger); } else if (trigger is EventTrigger) { var eventTrigger = trigger as EventTrigger; var nativeTrigger = new System.Windows.EventTrigger(); var fieldInfo = targetType.GetField(eventTrigger.Event + "Event", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy); nativeTrigger.RoutedEvent = (RoutedEvent)fieldInfo.GetValue(null); foreach (var action in eventTrigger.Actions) { try { var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action); nativeTrigger.Actions.Add(nativeTriggerAction); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in event trigger ""{eventTrigger.Event} {action.Action}"": {e.Message}"); } } return(nativeTrigger); } throw new NotSupportedException($"Trigger '{trigger.GetType().FullName}' is not supported!"); }
//default style for ToolboxItemWrapper - this one is required to enable context search in tree view control Style GetStyleForToolboxItem(Style baseStyle) { if (null == this.styleForToolboxItem) { this.styleForToolboxItem = (null == baseStyle ? new Style(typeof(TreeViewItem)) : new Style(typeof(TreeViewItem), baseStyle)); //visibility information - i need to bind TreeViewItem to it if (null != this.owner.searchBox) { MultiBinding visibilityBinding = new MultiBinding() { Converter = new ToolItemVisibilityConverter() }; Binding searchTextBinding = new Binding(); searchTextBinding.Source = this.owner.searchBox; searchTextBinding.Path = new PropertyPath(TextBox.TextProperty); searchTextBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; searchTextBinding.Mode = BindingMode.OneWay; Binding toolItemBinding = new Binding(); toolItemBinding.RelativeSource = RelativeSource.Self; toolItemBinding.Path = new PropertyPath(TreeViewItem.HeaderProperty); toolItemBinding.Mode = BindingMode.OneWay; visibilityBinding.Bindings.Add(searchTextBinding); visibilityBinding.Bindings.Add(toolItemBinding); Setter visibilitySetter = new Setter(); visibilitySetter.Property = TreeViewItem.VisibilityProperty; visibilitySetter.Value = visibilityBinding; //adding visibility setter to the style this.styleForToolboxItem.Setters.Add(visibilitySetter); } //take care of the AutomationId Binding automationIdBinding = new Binding(); automationIdBinding.RelativeSource = RelativeSource.Self; automationIdBinding.Path = new PropertyPath("Header.ToolName"); automationIdBinding.Mode = BindingMode.OneWay; Setter automationIdSetter = new Setter(); automationIdSetter.Property = AutomationProperties.AutomationIdProperty; automationIdSetter.Value = automationIdBinding; this.styleForToolboxItem.Setters.Add(automationIdSetter); //to enable smooth keyboard operation, hidden items have to be disabled in order not to receive //keyboard events - Trigger does the job Setter enableSetter = new Setter(TreeViewItem.IsEnabledProperty, false); Trigger enableTrigger = new Trigger(); enableTrigger.Property = TreeViewItem.VisibilityProperty; enableTrigger.Value = Visibility.Collapsed; enableTrigger.Setters.Add(enableSetter); //to enable drag&drop support add event setter for EventSetter mouseMoveSetter = new EventSetter(); mouseMoveSetter.Event = TreeViewItem.MouseMoveEvent; mouseMoveSetter.Handler = new MouseEventHandler(this.owner.OnToolMouseMove); this.styleForToolboxItem.Setters.Add(mouseMoveSetter); EventSetter mouseDoubleClickSetter = new EventSetter(); mouseDoubleClickSetter.Event = TreeViewItem.MouseDoubleClickEvent; mouseDoubleClickSetter.Handler = new MouseButtonEventHandler(this.owner.OnTreeViewDoubleClick); this.styleForToolboxItem.Setters.Add(mouseDoubleClickSetter); //adding trigger to the style this.styleForToolboxItem.Triggers.Add(enableTrigger); } return this.styleForToolboxItem; }
public override DependencyObject CreateTrigger(StyleSheet styleSheet, ITrigger trigger, Type targetType, DependencyObject styleResourceReferenceHolder) { if (trigger == null) { throw new ArgumentNullException(nameof(trigger)); } if (trigger is Trigger) { var propertyTrigger = trigger as Trigger; var nativeTrigger = new System.Windows.Trigger(); var dependencyProperty = dependencyService.GetBindableProperty(targetType, propertyTrigger.Property); if (dependencyProperty == null) { throw new NullReferenceException($"Property '{propertyTrigger.Property}' may not be null (targetType '{targetType.Name}')!"); } nativeTrigger.Property = dependencyProperty; nativeTrigger.Value = dependencyService.GetBindablePropertyValue(targetType, nativeTrigger.Property, propertyTrigger.Value); foreach (var styleDeclaration in propertyTrigger.StyleDeclaraionBlock) { var property = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, targetType, styleDeclaration.Property); if (property == null) { continue; } var value = typeNameResolver.GetPropertyValue(targetType, styleResourceReferenceHolder, styleDeclaration.Value, property); if (value is string valueString) { value = TypeDescriptor.GetConverter(property.PropertyType)?.ConvertFromInvariantString(valueString) ?? value; } nativeTrigger.Setters.Add(new Setter { Property = property, Value = value }); } return(nativeTrigger); } else if (trigger is DataTrigger) { var dataTrigger = trigger as DataTrigger; var nativeTrigger = new System.Windows.DataTrigger(); var expression = "{Binding " + dataTrigger.Binding + "}"; var binding = (System.Windows.Data.BindingBase)markupExtensionParser.ProvideValue(expression, null); nativeTrigger.Binding = binding; nativeTrigger.Value = GetBasicValue(dataTrigger); foreach (var styleDeclaration in dataTrigger.StyleDeclarationBlock) { var property = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, targetType, styleDeclaration.Property); if (property == null) { continue; } var value = typeNameResolver.GetPropertyValue(targetType, styleResourceReferenceHolder, styleDeclaration.Value, property); if (value is string valueString) { value = TypeDescriptor.GetConverter(property.PropertyType)?.ConvertFromInvariantString(valueString) ?? value; } nativeTrigger.Setters.Add(new Setter { Property = property, Value = value }); } return(nativeTrigger); } else if (trigger is EventTrigger) { var eventTrigger = trigger as EventTrigger; var nativeTrigger = new System.Windows.EventTrigger(); var fieldInfo = targetType.GetField(eventTrigger.Event + "Event", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy); nativeTrigger.RoutedEvent = (RoutedEvent)fieldInfo.GetValue(null); foreach (var action in eventTrigger.Actions) { var actionTypeName = typeNameResolver.ResolveFullTypeName(styleSheet.Namespaces, action.Action); var actionType = Type.GetType(actionTypeName); var triggerAction = (System.Windows.TriggerAction)Activator.CreateInstance(actionType); var parameters = action.Parameters.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .ToList(); foreach (var parameter in parameters) { var parameterName = parameter.Split(' ')[0]; object value = null; var parameterValueExpression = parameter.Substring(parameterName.Length + 1).Trim(); DependencyProperty depProp; var type = typeNameResolver.GetClrPropertyType(styleSheet.Namespaces, triggerAction, parameterName); if (typeNameResolver.IsMarkupExtension(parameterValueExpression)) { value = typeNameResolver.GetMarkupExtensionValue(styleResourceReferenceHolder, parameterValueExpression); } else if ((depProp = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, actionType, parameterName)) != null) { value = typeNameResolver.GetPropertyValue(actionType, styleResourceReferenceHolder, parameterValueExpression, depProp); if (value is DynamicResourceExtension) { var dyn = value as DynamicResourceExtension; var serviceProvider = (IServiceProvider)typeof(Application).GetProperty("ServiceProvider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Application.Current); value = dyn.ProvideValue(serviceProvider); } else if (value is StaticResourceExtension) { var dyn = value as StaticResourceExtension; var serviceProvider = (IServiceProvider)typeof(Application).GetProperty("ServiceProvider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Application.Current); value = dyn.ProvideValue(serviceProvider); } } else { value = parameterValueExpression; } if (value is string valueString) { value = TypeDescriptor.GetConverter(type)?.ConvertFromInvariantString(valueString) ?? value; } triggerAction.GetType().GetRuntimeProperty(parameterName).SetValue(triggerAction, value); } nativeTrigger.Actions.Add(triggerAction); } return(nativeTrigger); } throw new NotSupportedException($"Trigger '{trigger.GetType().FullName}' is not supported!"); }
public BuildButtonFactory() { Title = "Build Button Factory"; // Button ��ü�� ���� ControlTemplate�� ���� // ��Ʈ���� ������ ������ ���Ѵ�. ControlTemplate template = new ControlTemplate(typeof(Button)); // ������Ʈ���� ����, ������Ʈ�� ������Ƽ�� ��ȭ�� ����� �� ���� �����ϴ� Ʈ���� ���� // Border Ŭ������ ���� FrameworkElementFactory�� ���� FrameworkElementFactory factoryBorder = new FrameworkElementFactory(typeof(Border)); // ���߿� �����ϱ� ���� �̸��� ���� factoryBorder.Name = "border"; // �⺻ ������Ƽ���� ���� factoryBorder.SetValue(Border.BorderBrushProperty, Brushes.Red); // �ܰ��� ���� factoryBorder.SetValue(Border.BorderThicknessProperty, // �ܰ��� �β� new Thickness(3)); factoryBorder.SetValue(Border.BackgroundProperty, // ���� ���� SystemColors.ControlLightBrush); // ContentPresenter Ŭ������ ���� FrameworkElementFactory�� ���� FrameworkElementFactory factoryContent = new FrameworkElementFactory(typeof(ContentPresenter)); // ���߿� �����ϱ� ���� �̸��� ���� factoryContent.Name = "content"; // �� ���� ContentPresenter ������Ƽ�� Button ������Ƽ�� ���ε� factoryContent.SetValue(ContentPresenter.ContentProperty, new TemplateBindingExtension(Button.ContentProperty)); // ��ư�� Padding�� ����Ʈ�� Margin��! factoryContent.SetValue(ContentPresenter.MarginProperty, new TemplateBindingExtension(Button.PaddingProperty)); // ContentPresenter�� Border�� �ڽ����� ���� factoryBorder.AppendChild(factoryContent); // Border�� ���־� Ʈ���� ��Ʈ ������Ʈ�� ���� template.VisualTree = factoryBorder; // IsMouseOver�� true�� �ɶ��� Trigger�� ���� // Trigger - ���Ǻ� �۾��� �����Ѵ�. Trigger trig = new Trigger(); trig.Property = UIElement.IsMouseOverProperty; trig.Value = true; // �� Ʈ���ſ� ������ Setter�� ���� // "Border" ������Ʈ�� CornerRadius ������Ƽ�� ���� Setter set = new Setter(); set.Property = Border.CornerRadiusProperty; set.Value = new CornerRadius(24); set.TargetName = "border"; // �տ��� ���� �̸��� ����( Trigger �۾��� �Ҷ��� Ÿ���� �� ) // Trigger�� Setters �÷��ǿ� Setter�� �߰� trig.Setters.Add(set); // ����� ������� FontStyle�� �����Ű�� Setter�� ���� // (��ư�� ������Ƽ�̹Ƿ� TargetName�� ���ʿ���) set = new Setter(); set.Property = Control.FontStyleProperty; set.Value = FontStyles.Italic; // ���� ���� �������, �� Setter�� Ʈ������ Setter �÷��� trig.Setters.Add(set); // Ʈ���Ÿ� ���ø��� �߰� template.Triggers.Add(trig); // ����� ������� IsPressed�� ���� Ʈ���Ÿ� ���� trig = new Trigger(); trig.Property = Button.IsPressedProperty; trig.Value = true; set = new Setter(); set.Property = Border.BackgroundProperty; set.Value = SystemColors.ControlDarkBrush; set.TargetName = "border"; // Trigger�� Setters �÷��ǿ� Setter�� �߰� trig.Setters.Add(set); // Ʈ���Ÿ� ���ø��� �߰� template.Triggers.Add(trig); // ���������� Button�� ���� Button btn = new Button(); // ���ø� ���� btn.Template = template; // ��Ÿ ������Ƽ ���� btn.Content = "Button with Custom Template"; btn.Padding = new Thickness(20); btn.FontSize = 48; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.VerticalAlignment = VerticalAlignment.Center; btn.Click += ButtonOnClick; Content = btn; }
/// <summary> /// When overridden in a derived class, gets an editing element that is bound to the column's <see cref="P:System.Windows.Controls.DataGridBoundColumn.Binding"/> property value. /// </summary> /// <param name="cell">The cell that will contain the generated element.</param> /// <param name="dataItem">The data item represented by the row that contains the intended cell.</param> /// <returns> /// A new editing element that is bound to the column's <see cref="P:System.Windows.Controls.DataGridBoundColumn.Binding"/> property value. /// </returns> protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { #if !SILVERLIGHT _isEditing = false; #endif if(!string.IsNullOrEmpty(Field)) { var codedValueSources = Utilities.DynamicCodedValueSource.GetCodedValueSources(LookupField, FieldInfo, dataItem, DynamicCodedValueSource, nullableSources); if (codedValueSources != null) { ComboBox box = new ComboBox { Margin = new Thickness(4.0), VerticalAlignment = VerticalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, DisplayMemberPath = "DisplayName" }; if (!string.IsNullOrEmpty(LookupField) && DynamicCodedValueSource != null) { // Item Source Binding lookupConverter.LookupField = this.LookupField; lookupConverter.Field = this.FieldInfo; lookupConverter.NullableSources = this.nullableSources; Binding binding = new Binding(); binding.Mode = BindingMode.OneWay; binding.Converter = lookupConverter; binding.ConverterParameter = DynamicCodedValueSource; box.SetBinding(ComboBox.ItemsSourceProperty, binding); // Selected Item Binding selectedConverter.Field = Field; selectedConverter.LookupField = LookupField; selectedConverter.NullableSources = this.nullableSources; Binding selectedBinding = new Binding(); selectedBinding.Mode = BindingMode.OneWay; selectedBinding.Converter = selectedConverter; selectedBinding.ConverterParameter = this.DynamicCodedValueSource; box.SetBinding(ComboBox.SelectedItemProperty, selectedBinding); box.SelectionChanged += box_SelectionChanged; } return box; } else if(FieldInfo.Type == Client.Field.FieldType.Date) { DateTimePicker dtp = new DateTimePicker { Margin = new Thickness(4.0), VerticalAlignment = VerticalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, DateTimeFormat = this.DateTimeFormat, DateTimeKind = this.DateTimeKind, Language = cell.Language }; Binding selectedBinding = #if SILVERLIGHT new Binding(Field); #else new Binding("Attributes["+Field+"]"); if (FieldDomainUtils.IsDynamicDomain(FieldInfo, LayerInfo)) { selectedBinding.ValidationRules.Add(new DynamicRangeDomainValidationRule() { ValidationStep = ValidationStep.ConvertedProposedValue, Field = FieldInfo, LayerInfo = LayerInfo, Graphic = dataItem as Graphic }); } #endif selectedBinding.Mode = BindingMode.TwoWay; selectedBinding.ValidatesOnExceptions = true; selectedBinding.NotifyOnValidationError = true; dtp.SetBinding(DateTimePicker.SelectedDateProperty, selectedBinding); return dtp; } else { TextBox box = new TextBox { Margin = new Thickness(4.0), VerticalAlignment = VerticalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, }; box.MaxLength = Field.Length; Binding binding = #if SILVERLIGHT new Binding(Field); binding.Mode = BindingMode.TwoWay; binding.ValidatesOnExceptions = true; binding.NotifyOnValidationError = true; binding.Converter = emptyStringToNullConverter; #else new Binding("Attributes["+Field+"]"); binding.Mode = BindingMode.TwoWay; stringToPrimitiveTypeConverter.FieldType = FieldInfo.Type; binding.Converter = stringToPrimitiveTypeConverter; // Validates that the value entered into the text box can be // converted to the corrected field type without error. // if value cannot be converted to the correct type validation // error will be triggered based on binding trigger below. binding.ValidationRules.Add(new FeatureValidationRule() { ValidationStep = ValidationStep.ConvertedProposedValue, FieldType = FieldInfo.Type, Nullable = FieldInfo.Nullable }); if (FieldDomainUtils.IsDynamicDomain(FieldInfo, LayerInfo)) { binding.ValidationRules.Add(new DynamicRangeDomainValidationRule() { ValidationStep = ValidationStep.ConvertedProposedValue, Field = FieldInfo, LayerInfo = LayerInfo, Graphic = dataItem as Graphic }); } // Build a data trigger to show the validation error i.e. red outline around textbox // with message content in tooltip. var setterBinding = new Binding("(Validation.Errors)[0].ErrorContent"); setterBinding.RelativeSource = RelativeSource.Self; var setter = new Setter(); setter.Property = TextBox.ToolTipProperty; setter.Value = setterBinding; var trigger = new Trigger(); trigger.Property = Validation.HasErrorProperty; trigger.Value = true; trigger.Setters.Add(setter); var style = new Style(typeof(TextBox)); style.Triggers.Add(trigger); box.Style = style; #endif box.SetBinding(TextBox.TextProperty, binding); return box; } } return new TextBlock(); // Should never reach this line. }
public override DependencyObject CreateTrigger(StyleSheet styleSheet, ITrigger trigger, Type targetType, DependencyObject styleResourceReferenceHolder) { if (trigger == null) { throw new ArgumentNullException(nameof(trigger)); } if (trigger is Trigger) { var propertyTrigger = trigger as Trigger; var nativeTrigger = new System.Windows.Trigger(); var dependencyProperty = dependencyService.GetDependencyProperty(targetType, propertyTrigger.Property); if (dependencyProperty == null) { throw new NullReferenceException($"Property '{propertyTrigger.Property}' may not be null (targetType '{targetType.Name}')!"); } nativeTrigger.Property = dependencyProperty; nativeTrigger.Value = dependencyService.GetDependencyPropertyValue(targetType, nativeTrigger.Property.Name, nativeTrigger.Property, propertyTrigger.Value); foreach (var styleDeclaration in propertyTrigger.StyleDeclarationBlock) { var propertyInfo = typeNameResolver.GetDependencyPropertyInfo(styleSheet.Namespaces, targetType, styleDeclaration.Property); if (propertyInfo == null) { continue; } try { var value = typeNameResolver.GetPropertyValue(propertyInfo.DeclaringType, styleResourceReferenceHolder, propertyInfo.Name, styleDeclaration.Value, propertyInfo.Property, styleSheet.Namespaces); if (value == null) { } nativeTrigger.Setters.Add(new Setter { Property = propertyInfo.Property, Value = value }); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value} - {styleDeclaration.Property}: {styleDeclaration.Value}"": {e.Message}"); } } foreach (var action in propertyTrigger.EnterActions) { try { var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action); nativeTrigger.EnterActions.Add(nativeTriggerAction); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value}"" enter action: {e.Message}"); } } foreach (var action in propertyTrigger.ExitActions) { try { var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action); nativeTrigger.ExitActions.Add(nativeTriggerAction); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value}"" exit action: {e.Message}"); } } var serialized = SerializeObject(nativeTrigger); //serialized = $"pre XamlWriter.Save({nativeTrigger.GetType().Name})".Measure(() => XamlWriter.Save(nativeTrigger)); Css.SetSerializedTrigger(nativeTrigger, serialized); return(nativeTrigger); } else if (trigger is DataTrigger) { var dataTrigger = trigger as DataTrigger; var nativeTrigger = new System.Windows.DataTrigger(); string expression = null; if (typeNameResolver.IsMarkupExtension(dataTrigger.Binding)) { expression = typeNameResolver.CreateMarkupExtensionExpression(dataTrigger.Binding); } else { expression = "{Binding " + dataTrigger.Binding + "}"; } var binding = (System.Windows.Data.BindingBase)markupExtensionParser.ProvideValue(expression, null, styleSheet.Namespaces); nativeTrigger.Binding = binding; nativeTrigger.Value = GetBasicValue(dataTrigger); foreach (var styleDeclaration in dataTrigger.StyleDeclarationBlock) { try { var propertyInfo = typeNameResolver.GetDependencyPropertyInfo(styleSheet.Namespaces, targetType, styleDeclaration.Property); if (propertyInfo == null) { continue; } var value = typeNameResolver.GetPropertyValue(propertyInfo.DeclaringType, styleResourceReferenceHolder, propertyInfo.Name, styleDeclaration.Value, propertyInfo.Property, styleSheet.Namespaces); if (value == null) { } nativeTrigger.Setters.Add(new Setter { Property = propertyInfo.Property, Value = value }); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {styleDeclaration.Property}: {styleDeclaration.Value}"": {e.Message}"); } } foreach (var action in dataTrigger.EnterActions) { try { System.Windows.TriggerAction nativeTriggerAction = null; nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action); nativeTrigger.EnterActions.Add(nativeTriggerAction); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {action}"" enter action: {e.Message}"); } } foreach (var action in dataTrigger.ExitActions) { try { var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action); nativeTrigger.ExitActions.Add(nativeTriggerAction); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {action}"" exit action: {e.Message}"); } } var serialized = SerializeObject(nativeTrigger); //serialized = $"pre XamlWriter.Save({nativeTrigger.GetType().Name})".Measure(() => XamlWriter.Save(nativeTrigger)); Css.SetSerializedTrigger(nativeTrigger, serialized); return(nativeTrigger); } else if (trigger is EventTrigger) { var eventTrigger = trigger as EventTrigger; var nativeTrigger = new System.Windows.EventTrigger(); nativeTrigger.RoutedEvent = (RoutedEvent)TypeHelpers.GetFieldValue(targetType, eventTrigger.Event + "Event"); foreach (var action in eventTrigger.Actions) { try { var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action); nativeTrigger.Actions.Add(nativeTriggerAction); } catch (Exception e) { styleSheet.Errors.Add($@"ERROR in event trigger ""{eventTrigger.Event} {action.Action}"": {e.Message}"); } } var serialized = SerializeObject(nativeTrigger); //serialized = $"pre XamlWriter.Save({nativeTrigger.GetType().Name})".Measure(() => XamlWriter.Save(nativeTrigger)); Css.SetSerializedTrigger(nativeTrigger, serialized); return(nativeTrigger); } throw new NotSupportedException($"Trigger '{trigger.GetType().FullName}' is not supported!"); }
void Fire(Trigger next) { Debug.WriteLine("Firing {0} ({1})", next, GetHashCode()); machine.Fire(next); }
private void Value_AddMultiTriggerClicked(Controls.Value val) { if (val.ParentValue != null && val.ParentEvent != null) { if (val.ParentEvent.values.Contains(val.ParentValue)) { Controls.Event e = events.Find(x => x.ParentEvent == val.ParentEvent); if (e != null) { int index = e.Values.ToList().FindIndex(x => x.ParentValue == val.ParentValue); if (index >= 0) { Controls.Value v = e.Values[index]; if (v != null) { var multitrigger = new MultiTrigger(); val.ParentValue.triggers.Add(multitrigger); Controls.MultiTrigger uiMultiTrigger = CreateMultiTrigger(multitrigger, val.ParentValue, val.ParentEvent); var trigger = new Trigger(); multitrigger.triggers.Add(trigger); Controls.Trigger uiTrigger = CreateTrigger(trigger, uiMultiTrigger.ParentValue, uiMultiTrigger.ParentEvent); uiTrigger.modifier_COMBO.SelectedItem = "Equal To"; uiMultiTrigger.Triggers.Add(uiTrigger); val.Triggers.Add(uiMultiTrigger); } } } } } }