Example #1
0
        void IStyleConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 3:
            {
                EventSetter item = new EventSetter {
                    Event   = UIElement.MouseEnterEvent,
                    Handler = new MouseEventHandler(this.lbItemMouseEnter)
                };
                ((Style)target).Setters.Add(item);
                item = new EventSetter {
                    Event   = UIElement.KeyDownEvent,
                    Handler = new KeyEventHandler(this.lbItemKeyDown)
                };
                ((Style)target).Setters.Add(item);
                return;
            }

            case 4:
                ((Image)target).MouseDown += new MouseButtonEventHandler(this.btnPlay_MouseDown);
                return;

            case 5:
                ((Image)target).MouseDown += new MouseButtonEventHandler(this.btnInfo_MouseDown);
                return;
            }
        }
        private void CreateSettingsStyle()
        {
            settingsStyle = new Style();
            Storyboard  anim = (Storyboard)FindResource("captionLabelAnimation");
            EventSetter mouseEnterEventSetter = new EventSetter(UIElement.MouseEnterEvent, new MouseEventHandler(delegate(object sender, MouseEventArgs e)
            {
                if ((sender != null) && (sender is FrameworkElement))
                {
                    captionTextBlock.Text = (string)((FrameworkElement)sender).ToolTip;
                    anim.Begin();
                }
            }));
            EventSetter mouseLeaveEventSetter = new EventSetter(UIElement.MouseLeaveEvent, new MouseEventHandler(delegate(object sender, MouseEventArgs e)
            {
                captionTextBlock.Text = "";
            }));

            settingsStyle.Setters.Add(mouseEnterEventSetter);
            settingsStyle.Setters.Add(mouseLeaveEventSetter);

            Setter tooltipDisableSetter = new Setter(ToolTipService.IsEnabledProperty, false);

            settingsStyle.Setters.Add(tooltipDisableSetter);

            Thickness margin       = new Thickness(30, 5, 0, 10);
            Setter    marginSetter = new Setter(FrameworkElement.MarginProperty, margin);

            settingsStyle.Setters.Add(marginSetter);
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            Button btnForeground = (Button)GetTemplateChild("btnForeground");
            Button btnBackground = (Button)GetTemplateChild("btnBackground");

            listBox = (ListBox)GetTemplateChild("PatternListBox");

            if (solidColorListDoubleClickEventSetter == null)
            {
                solidColorListDoubleClickEventSetter = new EventSetter(ListBoxItem.MouseDoubleClickEvent, new MouseButtonEventHandler((s, e) => OnSelectedItemDoubleClick(s, e)));
            }

            if (listBox.ItemContainerStyle == null)
            {
                listBox.ItemContainerStyle = new Style(typeof(ListBoxItem));
                listBox.ItemContainerStyle.Setters.Add(solidColorListDoubleClickEventSetter);
                listBox.ItemContainerStyle.Setters.Add(new Setter(ListBoxItem.MarginProperty, new Thickness(2)));
            }

            btnForeground.Click -= new RoutedEventHandler(btnForeground_Click);
            btnBackground.Click -= new RoutedEventHandler(btnForeground_Click);

            btnForeground.Click += new RoutedEventHandler(btnForeground_Click);
            btnBackground.Click += new RoutedEventHandler(btnBackground_Click);
        }
Example #4
0
        public MMListView()
        {
            Style       itemStyle   = new Style(typeof(ListViewItem));
            EventSetter eventSetter = new EventSetter(MouseDoubleClickEvent, new MouseButtonEventHandler(ItemMouseDoubleClick));

            itemStyle.Setters.Add(eventSetter);
            ItemContainerStyle = itemStyle;
        }
 public BaseDragAndDropContainerItemBehavior()
 {
     _previewMouseLeftButtonEventSetter = new EventSetter(UIElement.PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(OnPreviewMouseLeftButtonDown));
     _previewMouseMoveEventSetter       = new EventSetter(UIElement.PreviewMouseMoveEvent, new MouseEventHandler(OnPreviewMouseMove));
     _dragEnterEventSetter = new EventSetter(UIElement.DragEnterEvent, new DragEventHandler(OnDragEnter));
     _dragLeaveEventSetter = new EventSetter(UIElement.DragLeaveEvent, new DragEventHandler(OnDragLeave));
     _dropEventSetter      = new EventSetter(UIElement.DropEvent, new DragEventHandler(OnDrop));
     _allowDropSetter      = new Setter(UIElement.AllowDropProperty, true);
 }
Example #6
0
 void IStyleConnector.Connect(int connectionId, object target)
 {
     if (connectionId == 11)
     {
         EventSetter eventSetter = new EventSetter();
         eventSetter.Event   = Control.MouseDoubleClickEvent;
         eventSetter.Handler = new MouseButtonEventHandler(this.Row_DoubleClick);
         ((Style)target).Setters.Add(eventSetter);
     }
 }
Example #7
0
        public DataGridExtended() : base()
        {
            var columnStyle = new Style {
                TargetType = typeof(DataGridColumnHeader)
            };
            var eventSetter = new EventSetter(MouseRightButtonDownEvent, new MouseButtonEventHandler(HeaderClick));

            columnStyle.Setters.Add(eventSetter);
            ColumnHeaderStyle = columnStyle;
        }
 void IStyleConnector.Connect(int connectionId, object target)
 {
     if (connectionId == 1)
     {
         EventSetter eventSetter = new EventSetter();
         eventSetter.Event   = FrameworkElement.RequestBringIntoViewEvent;
         eventSetter.Handler = new RequestBringIntoViewEventHandler(a);
         ((Style)target).Setters.Add(eventSetter);
     }
 }
Example #9
0
 void IStyleConnector.Connect(int connectionId, object target)
 {
     if (connectionId == 0x19)
     {
         EventSetter item = new EventSetter {
             Event   = Control.MouseDoubleClickEvent,
             Handler = new MouseButtonEventHandler(this.Row_MouseDoubleClick)
         };
         ((Style)target).Setters.Add(item);
     }
 }
 void IStyleConnector.Connect(int connectionId, object target)
 {
     if (connectionId == 1)
     {
         var item = new EventSetter {
             Event   = MouseDownEvent,
             Handler = new MouseButtonEventHandler(ImageClicked)
         };
         ((Style)target).Setters.Add(item);
     }
 }
Example #11
0
        public DataGridEx() : base()
        {
            // Create event for right click on headers
            var style = new Style {
                TargetType = typeof(DataGridColumnHeader)
            };
            var eventSetter = new EventSetter(MouseRightButtonDownEvent, new MouseButtonEventHandler(HeaderClick));

            style.Setters.Add(eventSetter);
            ColumnHeaderStyle = style;
        }
Example #12
0
        void IStyleConnector.Connect(int connectionId, object target)
        {
            if (connectionId != 2)
            {
                return;
            }
            EventSetter eventSetter = new EventSetter();

            eventSetter.Event   = Hyperlink.RequestNavigateEvent;
            eventSetter.Handler = new RequestNavigateEventHandler(this.Hyperlink_RequestNavigate);
            ((Style)target).Setters.Add(eventSetter);
        }
Example #13
0
        private void InitializeSolidColorListDoubleClickEvent()
        {
            if (solidColorListDoubleClickEventSetter == null)
            {
                solidColorListDoubleClickEventSetter = new EventSetter(ListBoxItem.MouseDoubleClickEvent, new MouseButtonEventHandler((s, e) => OnSelectedItemDoubleClick(s, e)));
            }

            if (solidColorList.ItemContainerStyle == null)
            {
                solidColorList.ItemContainerStyle = new Style(typeof(ListBoxItem));
                solidColorList.ItemContainerStyle.Setters.Add(solidColorListDoubleClickEventSetter);
            }
        }
Example #14
0
        public static IObservable <Tuple <object, T> > RegisterEventSetter <T>(this Style style, RoutedEvent routedEvent, Func <EventHandler <T>, Delegate> eventHandlerCreator)
            where T : EventArgs
        {
            return(Observable.Create <Tuple <object, T> >(o =>
            {
                var handler = eventHandlerCreator((sender, args) => o.OnNext(Tuple.Create(sender, args)));
                var eventSetter = new EventSetter(routedEvent, handler);

                style.Setters.Add(eventSetter);

                // We can't remove the setter anymore as the setter collection gets sealed
                return () => { };
            }));
        }
Example #15
0
        protected override void OnAttach()
        {
            this.AssociatedObject.ItemContainerStyle = new Func <Style>(() =>
            {
                var style = new Style(typeof(ListViewItem))
                {
                    BasedOn = (Style)Application.Current.FindResource(typeof(ListViewItem))
                };

                var mouseDoubleClickEventTrigger = new EventSetter(ListViewItem.MouseDoubleClickEvent,
                                                                   new MouseButtonEventHandler((s, e) =>
                {
                    var sender  = (s as ListViewItem).DataContext;
                    var command = ListViewProperties.GetCommand(this.AssociatedObject);
                    if (command != null && command.CanExecute(sender))
                    {
                        command.Execute(sender);
                    }

                    (e as MouseButtonEventArgs).Handled = true;
                }));

                var mouseKeyUpEventTrigger = new EventSetter(ListViewItem.KeyDownEvent,
                                                             new KeyEventHandler((s, e) =>
                {
                    var args = e as KeyEventArgs;

                    if (args.Key == Key.Enter && args.SystemKey == Key.None)
                    {
                        var sender  = (s as ListViewItem).DataContext;
                        var command = ListViewProperties.GetCommand(this.AssociatedObject);
                        if (command != null && command.CanExecute(sender))
                        {
                            command.Execute(sender);
                        }

                        args.Handled = true;
                    }
                }));

                style.Setters.Add(mouseDoubleClickEventTrigger);
                style.Setters.Add(mouseKeyUpEventTrigger);

                return(style);
            })();
            this.AssociatedObject.SelectionChanged += AssociatedObject_SelectionChanged;
            this.SetBinding(ListViewBehaviour.ViewProperty, this.AssociatedObject, new PropertyPath("View"), BindingMode.OneWay);
        }
Example #16
0
        private static void ModifySingleClickEdit(DataGridColumn owner, bool subcribe)
        {
            ModuleProc PROC = new ModuleProc("", "ModifySingleClickEdit");

            try
            {
                EventSetter setter = new EventSetter();
                setter.Event   = DataGridCell.PreviewMouseLeftButtonDownEvent;
                setter.Handler = new MouseButtonEventHandler(OnGridSingleClickEdit);
                Style cellStyle = new Style();
                cellStyle.Setters.Add(setter);
                owner.CellStyle = cellStyle;
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
        }
        /// <summary>
        ///     Convert a string like "Button.Click" into the corresponding RoutedEvent
        /// </summary>
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext,
                                           CultureInfo cultureInfo,
                                           object source)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (s_ServiceProviderContextType == null)
            {
                // get typeof(MS.Internal.Xaml.ServiceProviderContext) via reflection
                Assembly a = typeof(IRootObjectProvider).Assembly;
                s_ServiceProviderContextType = a.GetType("MS.Internal.Xaml.ServiceProviderContext");
            }
            if (typeDescriptorContext.GetType() != s_ServiceProviderContextType)
            {
                // if the caller is not the XAML parser, don't answer.   This avoids
                // returning an arbitrary delegate to a (possibly malicious) caller.
                // See Dev11 629384.
                throw new ArgumentException(SR.Get(SRID.TextRange_InvalidParameterValue), "typeDescriptorContext");
            }
            IRootObjectProvider rootProvider = typeDescriptorContext.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;

            if (rootProvider != null && source is String)
            {
                IProvideValueTarget ipvt = typeDescriptorContext.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
                if (ipvt != null)
                {
                    EventSetter setter = ipvt.TargetObject as EventSetter;
                    string      handlerName;
                    if (setter != null && (handlerName = source as string) != null)
                    {
                        handlerName = handlerName.Trim();
                        return(Delegate.CreateDelegate(setter.Event.HandlerType, rootProvider.RootObject, handlerName));
                    }
                }
            }

            throw GetConvertFromException(source);
        }
Example #18
0
        private void OnRowColorizerChanged()
        {
            if (IsInitialized)
            {
                var bind = new Binding()
                {
                    RelativeSource = RelativeSource.Self,
                    Converter      = RowColorizer
                };

                var style = new Style(typeof(ListViewItem));
                style.Setters.Add(new Setter(ListViewItem.BackgroundProperty, bind));

                var sett = new EventSetter(ListViewItem.MouseDoubleClickEvent, new MouseButtonEventHandler(OnListItemMouseDoubleClick));
                style.Setters.Add(sett);

                Resources[typeof(ListViewItem)] = style;
            }
        }
Example #19
0
            private static Style BuildWindowStyle(Action action)
            {
                Style style = new Style(typeof(Notification));

                if (action != null)
                {
                    var handler = new MouseButtonEventHandler((s, e) => action());
                    var leftMouseDoubleClick = new EventSetter(MouseDoubleClickEvent, handler);

                    style.Setters.Add(leftMouseDoubleClick);
                }

#if DEBUG
                style.Setters.Add(new Setter(BackgroundProperty, Brushes.DarkGoldenrod));
#else
                style.Setters.Add(new Setter(BackgroundProperty, Brushes.Black));
#endif
                style.Setters.Add(new Setter(ForegroundProperty, Brushes.Transparent));

                style.Setters.Add(new Setter(TopmostProperty, true));
                style.Setters.Add(new Setter(FocusableProperty, false));
                style.Setters.Add(new Setter(ShowInTaskbarProperty, false));
                style.Setters.Add(new Setter(ShowActivatedProperty, false));
                style.Setters.Add(new Setter(IsTabStopProperty, false));
                style.Setters.Add(new Setter(ResizeModeProperty, ResizeMode.NoResize));
                style.Setters.Add(new Setter(WindowStyleProperty, WindowStyle.None));
                style.Setters.Add(new Setter(BorderThicknessProperty, new Thickness(0d)));

                double desiredWidth = 475d;

                double top  = SystemParameters.WorkArea.Top + 50d;
                double left = SystemParameters.WorkArea.Right - desiredWidth - 100d;

                style.Setters.Add(new Setter(TopProperty, top));
                style.Setters.Add(new Setter(LeftProperty, left));

                style.Setters.Add(new Setter(SizeToContentProperty, SizeToContent.Height));
                style.Setters.Add(new Setter(WidthProperty, desiredWidth));

                return(style);
            }
Example #20
0
        void IStyleConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 4:
                ((TextBox)target).KeyDown += this.OnKeyDownHandlerComment;
                break;

            case 5:
                ((Button)target).Click += this.delete_this_bot;
                break;

            case 6:
            {
                EventSetter eventSetter = new EventSetter();
                eventSetter.Event   = Control.MouseDoubleClickEvent;
                eventSetter.Handler = new MouseButtonEventHandler(this.Row_DoubleClick);
                ((Style)target).Setters.Add(eventSetter);
                break;
            }
            }
        }
Example #21
0
        private static void OnTakeCardEventResourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var deck = (CardContainer)d;

            if (deck == null)
            {
                return;
            }

            var resource = (EventResource)d.GetValue(TakeCardEventResourceProperty);

            if (resource == null)
            {
                return;
            }

            var style  = new Style(resource.TargetType);
            var setter = new EventSetter(resource.Event, TakeCardEventHandler);

            style.Setters.Add(setter);
            deck.Resources.Add(resource.TargetType, style);
        }
Example #22
0
        void IStyleConnector.Connect(int connectionId, object target)
        {
            EventSetter setter;

            switch (connectionId)
            {
            case 2:
                setter = new EventSetter {
                    Event   = System.Windows.Controls.Control.MouseDoubleClickEvent,
                    Handler = new MouseButtonEventHandler(this.lviDoubleClick)
                };
                ((Style)target).Setters.Add(setter);
                return;

            case 3:
                setter = new EventSetter {
                    Event   = System.Windows.Controls.Control.MouseDoubleClickEvent,
                    Handler = new MouseButtonEventHandler(this.lviDoubleClick)
                };
                ((Style)target).Setters.Add(setter);
                return;
            }
        }
        /// <summary>Converts the specified string to a new <see cref="T:System.Delegate" /> for the event handler.</summary>
        /// <param name="typeDescriptorContext">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
        /// <param name="cultureInfo">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture. </param>
        /// <param name="source">The source string to convert.</param>
        /// <returns>A new <see cref="T:System.Delegate" /> that represents the referenced event handler.</returns>
        /// <exception cref="T:System.NotSupportedException">The necessary services are not available.-or-Could not perform the specific conversion.</exception>
        /// <exception cref="T:System.ArgumentNullException">
        ///         <paramref name="typeDescriptorContext" /> or <paramref name="source" /> are <see langword="null" />.</exception>
        // Token: 0x06001D03 RID: 7427 RVA: 0x00087740 File Offset: 0x00085940
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (EventSetterHandlerConverter.s_ServiceProviderContextType == null)
            {
                Assembly assembly = typeof(IRootObjectProvider).Assembly;
                EventSetterHandlerConverter.s_ServiceProviderContextType = assembly.GetType("MS.Internal.Xaml.ServiceProviderContext");
            }
            if (typeDescriptorContext.GetType() != EventSetterHandlerConverter.s_ServiceProviderContextType)
            {
                throw new ArgumentException(SR.Get("TextRange_InvalidParameterValue"), "typeDescriptorContext");
            }
            IRootObjectProvider rootObjectProvider = typeDescriptorContext.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;

            if (rootObjectProvider != null && source is string)
            {
                IProvideValueTarget provideValueTarget = typeDescriptorContext.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
                if (provideValueTarget != null)
                {
                    EventSetter eventSetter = provideValueTarget.TargetObject as EventSetter;
                    string      text;
                    if (eventSetter != null && (text = (source as string)) != null)
                    {
                        text = text.Trim();
                        return(Delegate.CreateDelegate(eventSetter.Event.HandlerType, rootObjectProvider.RootObject, text));
                    }
                }
            }
            throw base.GetConvertFromException(source);
        }
Example #24
0
        public override Style SelectStyle(object item, DependencyObject container)
        {
            Style st = new Style();

            st.TargetType = typeof(DataGridRow);
            Setter backGroundSetter = new Setter();

            backGroundSetter.Property = DataGridRow.BackgroundProperty;
            Setter textColorSetter = new Setter();

            textColorSetter.Property = DataGridRow.ForegroundProperty;
            DataGrid listView =
                ItemsControl.ItemsControlFromItemContainer(container)
                as DataGrid;
            int index =
                listView.ItemContainerGenerator.IndexFromContainer(container);

            if (index % 2 == 0)
            {
                backGroundSetter.Value = Brushes.DeepSkyBlue;
            }
            else
            {
                backGroundSetter.Value = Brushes.LightBlue;
            }
            textColorSetter.Value = Brushes.Black;
            st.Setters.Add(backGroundSetter);
            st.Setters.Add(textColorSetter);

            EventSetter eventSetter = new EventSetter();

            eventSetter.Event   = DataGridRow.MouseDoubleClickEvent;
            eventSetter.Handler = DoubleClickHandler;
            st.Setters.Add(eventSetter);
            return(st);
        }
Example #25
0
 public TreeViewSelectionBehavior()
 {
     _treeViewItemEventSetter = new EventSetter(
         FrameworkElement.LoadedEvent,
         new RoutedEventHandler(OnTreeViewItemLoaded));
 }
        private void SetReqHelpersColumns()
        {
            ReqHelperTop.Columns.Clear();
            ReqHelperBottom.Columns.Clear();

            ReqTopHelperData[0].Clear();
            ReqBottomHelperData[0].Clear();

            int actualBrush = 0;

            foreach (var column in RequirementsDataGrid.Columns.OrderBy(x => x.DisplayIndex))
            {
                ReqHelperTop.Columns.Add(new DataGridTextColumn
                {
                    Header     = column.Header,
                    Width      = column.ActualWidth,
                    IsReadOnly = true
                });

                ReqHelperBottom.Columns.Add(new DataGridTextColumn
                {
                    Header     = column.Header,
                    Width      = column.ActualWidth,
                    IsReadOnly = true
                });

                if (!int.TryParse(column.Header.ToString(), out _))
                {
                    continue;
                }

                var columnValue = column.Header.ToString();


                ReqTopHelperData[0].Add(columnValue, false);
                ReqBottomHelperData[0].Add(columnValue, false);


                var dataTrigger = new DataTrigger()
                {
                    Binding = new Binding("[" + column.Header + "]"),
                    Value   = "true"
                };
                dataTrigger.Setters.Add(new Setter()
                {
                    Property = BorderBrushProperty,
                    Value    = Brushes.Black
                });
                dataTrigger.Setters.Add(new Setter()
                {
                    Property = BackgroundProperty,
                    Value    = brushes[actualBrush++ % brushes.Length]
                });

                var eventTrigger = new EventSetter()
                {
                    Event   = PreviewMouseLeftButtonDownEvent,
                    Handler = new MouseButtonEventHandler(Helper_LeftClickEvent)
                };

                ReqHelperTop.Columns.Last().CellStyle = new Style();
                ReqHelperTop.Columns.Last().CellStyle.Triggers.Add(dataTrigger);
                ReqHelperTop.Columns.Last().CellStyle.Setters.Add(eventTrigger);

                ReqHelperBottom.Columns.Last().CellStyle = new Style();
                ReqHelperBottom.Columns.Last().CellStyle.Triggers.Add(dataTrigger);
                ReqHelperBottom.Columns.Last().CellStyle.Setters.Add(eventTrigger);
            }
        }
Example #27
0
        //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);
        }
Example #28
0
        /// <summary>
        /// コントロールがLoadされてテンプレートが適用されたときに呼び出されるハンドラ
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            // 以下の2つのイベントはボタン押下でカレンダー開く→ボタン押下としたときに
            // MouseDownでカレンダーが閉じられ、MouseUpで再度カレンダーが開いてしまう問題に対応
            this.PartsPopup.Opened += this.Popup_Opened;
            this.PartsPopup.Closed += this.Popup_Closed;

            // カレンダーの日付のダブルクリックで選択・カレンダーを閉じる操作を行うためにハンドラを登録
            var ee    = new EventSetter(MouseDoubleClickEvent, new MouseButtonEventHandler(this.CalenderDayButton_MouseDoubleClick));
            var style = this.PartsCalender.CalendarDayButtonStyle;

            if (style == null)
            {
                style = new Style()
                {
                    TargetType = typeof(CalendarDayButton)
                };
            }
            style.Setters.Add(ee);
            this.PartsCalender.CalendarDayButtonStyle = style;

            // 日付テキストボックスのIsReadOnlyとカレンダーを起動するためのボタンのIsEnabledを連動させる
            this.PartsButton.IsEnabled = !this.IsReadOnly;

            // TextプロパティへのBindingが定義されている場合は、デフォルトの表示書式などを定義する
            // UpdateSourceTriggerやNotifyOnValidationErrorなど、基盤側で必要な定義も設定する
            var expression = BindingOperations.GetBindingExpression(this, TextProperty);

            if (expression.IsEmpty())
            {
                return;
            }

            var binding = BindingOperations.GetBinding(this, TextProperty);

            if (binding.IsEmpty())
            {
                // bindingが定義されていない場合は処理しない
                return;
            }

            var newBinding = new Binding(binding.Path.Path)
            {
                Mode = binding.Mode,
                NotifyOnValidationError = true,
                UpdateSourceTrigger     = UpdateSourceTrigger.Explicit,
                ConverterCulture        = CultureInfo.CurrentCulture,
            };

            var displayFormat = string.Empty;
            var x             = this.DataContext?.GetType().GetProperty(expression.ParentBinding?.Path.Path);

            //switch (x.PropertyType)
            //{
            //    case Type intType when intType == typeof(Date):
            //        displayFormat = expression.ParentBinding.StringFormat;
            //        if (displayFormat.IsEmpty())
            //        {
            //            displayFormat = "yyyy/MM/dd";
            //        }
            //        newBinding.Converter = new StringToDateConverter();
            //        newBinding.ValidationRules.Add(new DateValidationRule());
            //        break;

            //    default:
            //        break;
            //}
            if (x.PropertyType == typeof(Date))
            {
                displayFormat = expression.ParentBinding.StringFormat;
                if (displayFormat.IsEmpty())
                {
                    displayFormat = "yyyy/MM/dd";
                }
                newBinding.Converter = new StringToDateConverter();
                newBinding.ValidationRules.Add(new DateValidationRule());
            }
            newBinding.ConverterParameter = displayFormat;
            newBinding.StringFormat       = displayFormat;
            BindingOperations.ClearBinding(this, TextProperty);
            BindingOperations.SetBinding(this, TextProperty, newBinding);
        }