Ejemplo n.º 1
0
        /// <summary>
        /// SizeChanged イベント
        /// </summary>
        /// <param name="sender">対象</param>
        /// <param name="e">イベント情報</param>
        private static void Label_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var label = sender as Label;

            if (label == null)
            {
                // 対応するエレメントが許容する型ではない場合は中断
                return;
            }

            if (!GetIsEnabled(label))
            {
                return;
            }

            var formattedText = BehaviorUtil.GetFormattedText(label);

            if (label.ActualWidth < formattedText.Width + label.Padding.Left + label.Padding.Right)
            {
                label.ToolTip = label.Content;
            }
            else
            {
                label.ToolTip = null;
            }
        }
        /// <summary>
        /// MaxLinesプロパティが変更された際の処理
        /// </summary>
        private static void OnSetMaxLinesCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var textblock = target as TextBlock;

            if (textblock == null)
            {
                return;
            }
            if (textblock.TextWrapping == TextWrapping.NoWrap)
            {
                // 改行設定
                textblock.TextWrapping = TextWrapping.Wrap;
            }
            if (textblock.TextTrimming == TextTrimming.None)
            {
                // 省略文字設定
                textblock.TextTrimming = TextTrimming.CharacterEllipsis;
            }

            BehaviorUtil.SetEventHandler(textblock,
                                         (block) => block.TargetUpdated += TextBlock_TargetUpdated,
                                         (block) => block.TargetUpdated -= TextBlock_TargetUpdated
                                         );

            BehaviorUtil.Loaded(textblock, TextBlock_Loaded);
        }
Ejemplo n.º 3
0
        private static void Control_Loaded(object sender, RoutedEventArgs e)
        {
            var control = sender as Control;

            if (control == null)
            {
                // 対応するエレメントが許容する型ではない場合は中断
                return;
            }

            var tooltip = GetToolTip(control);

            if (tooltip == null)
            {
                return;
            }

            if (tooltip is FrameworkElement)
            {
                var formattedText = BehaviorUtil.GetFormattedText((FrameworkElement)tooltip);

                if (!string.IsNullOrEmpty(formattedText.Text))
                {
                    control.ToolTip = tooltip;
                }
            }
            else if (tooltip is string && !string.IsNullOrEmpty((string)tooltip))
            {
                control.ToolTip = tooltip;
            }
            else
            {
                control.ToolTip = tooltip;
            }
        }
Ejemplo n.º 4
0
        private static void Refresh(object sender)
        {
            var sv  = sender as ScrollViewer;
            var hfe = GetColumnHeader(sv);
            var hsv = BehaviorUtil.GetScrollViewer(hfe);
            var rfe = GetRowHeader(sv);
            var rsv = BehaviorUtil.GetScrollViewer(rfe);
            var hfo = GetColumnFooter(sv);
            var rfo = GetRowFooter(sv);

            if (hsv != null)
            {
                hsv.ScrollToHorizontalOffset(sv.HorizontalOffset);
            }
            if (rsv != null)
            {
                rsv.ScrollToVerticalOffset(sv.VerticalOffset);
            }
            if (hfo != null)
            {
                hfo.Width = GetScrollWidth(sv);
            }
            if (rfo != null)
            {
                rfo.Height = GetScrollHeight(sv);
            }
        }
 private static void OnSetIsEnabledCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
 {
     if (!WpfUtil.IsDesignMode())
     {
         // Window読込時イベント
         BehaviorUtil.Loaded(sender as Window, Window_Loaded);
     }
 }
        /// <summary>
        /// Commandプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetCommandCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            ComboBox control = target as ComboBox;

            BehaviorUtil.SetEventHandler(control,
                                         (fe) => fe.SelectionChanged += ComboBox_SelectionChanged,
                                         (fe) => fe.SelectionChanged -= ComboBox_SelectionChanged
                                         );
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Disposableプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetDisposableCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var win = target as Window;

            BehaviorUtil.SetEventHandler(win,
                                         (fe) => fe.Closed += Window_Closed,
                                         (fe) => fe.Closed -= Window_Closed
                                         );
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Commandプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetCommandCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var control = target as FrameworkElement;

            BehaviorUtil.SetEventHandler(control,
                                         (fe) => fe.MouseLeftButtonDown += FrameworkElement_MouseLeftButtonDown,
                                         (fe) => fe.MouseLeftButtonDown -= FrameworkElement_MouseLeftButtonDown
                                         );
        }
Ejemplo n.º 9
0
        /// <summary>
        /// ScrollViewerの処理
        /// </summary>
        /// <param name="action">スクロール移動処理</param>
        private static void OnScrollCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e, Action <ScrollViewer> action)
        {
            var sv = BehaviorUtil.GetScrollViewer(sender);

            if (sv != null)
            {
                action(sv);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Commandプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetCommandCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            Control control = target as Control;

            BehaviorUtil.SetEventHandler(control,
                                         (fe) => fe.KeyDown += Control_KeyDown,
                                         (fe) => fe.KeyDown -= Control_KeyDown
                                         );
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Commandプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetCommandCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var win = target as Window;

            BehaviorUtil.SetEventHandler(win,
                                         (fe) => fe.Closing += Window_Closing,
                                         (fe) => fe.Closing -= Window_Closing
                                         );
        }
        /// <summary>
        /// Targetプロパティ変更時イベント (イベントを設定します)
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetTargetCallback(DependencyObject dp, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement element = dp as FrameworkElement;

            BehaviorUtil.SetEventHandler(element,
                                         (fe) => fe.PreviewKeyDown += FrameworkElement_PreviewKeyDown,
                                         (fe) => fe.PreviewKeyDown -= FrameworkElement_PreviewKeyDown
                                         );
        }
        /// <summary>
        /// Valueプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetFormatCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var textbox = target as TextBox;
            var value   = WpfUtil.GetIsNotNull(GetValue(textbox), textbox.Text, "0");

            BehaviorUtil.Loaded(textbox,
                                (sender, tmp) => SetText(textbox, double.Parse(value))
                                );
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Focusableプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetFocusableCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var control = target as FrameworkElement;

            BehaviorUtil.SetEventHandler(control,
                                         (fe) => fe.IsKeyboardFocusWithinChanged += Control_IsKeyboardFocusWithinChanged,
                                         (fe) => fe.IsKeyboardFocusWithinChanged -= Control_IsKeyboardFocusWithinChanged
                                         );
        }
Ejemplo n.º 15
0
        /// <summary>
        /// コマンドプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetCommandCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var obj = target as DependencyObject;

            if (obj != null)
            {
                BehaviorUtil.Loaded(target as FrameworkElement, UserControl_Loaded);
            }
        }
        /// <summary>
        /// Commandプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetCommandCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var control = target as Control;

            BehaviorUtil.SetEventHandler(control,
                                         (fe) => fe.MouseDoubleClick += Control_MouseDoubleClick,
                                         (fe) => fe.MouseDoubleClick -= Control_MouseDoubleClick
                                         );
        }
        private static void OnSetIsEnabledCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var element = sender as ListView;

            // 基本的にListView.SizeChangedイベントで列幅を変更する。
            BehaviorUtil.SetEventHandler(element,
                                         fe => fe.SelectionChanged += ListView_SelectionChanged,
                                         fe => fe.SelectionChanged -= ListView_SelectionChanged
                                         );
        }
        private static void OnSetListViewCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var element = sender as Button;

            // 基本的にListView.SizeChangedイベントで列幅を変更する。
            BehaviorUtil.SetEventHandler(element,
                                         fe => fe.Click += Button_Click,
                                         fe => fe.Click -= Button_Click
                                         );
        }
        private static void OnSetIsEnabledCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var element = sender as ListBox;

            // PreviewKeyDownイベント時、選択を解除するキー入力をキャンセルする。
            BehaviorUtil.SetEventHandler(element,
                                         fe => fe.PreviewKeyDown += ListView_PreviewKeyDown,
                                         fe => fe.PreviewKeyDown -= ListView_PreviewKeyDown
                                         );
        }
Ejemplo n.º 20
0
        private static void OnSetIsEnabledCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var element = sender as FrameworkElement;

            // PreviewKeyDownイベント時、選択を解除するキー入力をキャンセルする。
            BehaviorUtil.SetEventHandler(element,
                                         fe => fe.MouseLeftButtonDown += FrameworkElement_MouseLeftButtonDown,
                                         fe => fe.MouseLeftButtonDown -= FrameworkElement_MouseLeftButtonDown
                                         );
        }
Ejemplo n.º 21
0
        /// <summary>
        /// IsEnabledプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetIsEnableCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var label = target as Label;

            BehaviorUtil.SetEventHandler(label,
                                         (fe) => fe.SizeChanged += Label_SizeChanged,
                                         (fe) => fe.SizeChanged -= Label_SizeChanged
                                         );

            BehaviorUtil.Loaded(label, Label_Loaded);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// IsEnabledプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetIsEnabledCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var control = target as TextBox;

            BehaviorUtil.SetEventHandler(control,
                                         (fe) => fe.GotFocus += TextBox_GotFocus,
                                         (fe) => fe.GotFocus -= TextBox_GotFocus
                                         );
            BehaviorUtil.SetEventHandler(control,
                                         (fe) => fe.PreviewMouseLeftButtonDown += TextBox_PreviewMouseLeftButtonDown,
                                         (fe) => fe.PreviewMouseLeftButtonDown -= TextBox_PreviewMouseLeftButtonDown
                                         );
        }
        private static void OnSetIsEnabledCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var element = sender as FrameworkElement;

            BehaviorUtil.SetEventHandler(element,
                                         fe => fe.MouseEnter += FrameworkElement_MouseEnter,
                                         fe => fe.MouseEnter -= FrameworkElement_MouseEnter
                                         );
            BehaviorUtil.SetEventHandler(element,
                                         fe => fe.MouseLeave += FrameworkElement_MouseLeave,
                                         fe => fe.MouseLeave -= FrameworkElement_MouseLeave
                                         );
        }
        private static void OnSetIsEnabledCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var element = sender as ListView;

            // 基本的にListView.SizeChangedイベントで列幅を変更する。
            BehaviorUtil.SetEventHandler(element,
                                         fe => fe.SizeChanged += ListView_SizeChanged,
                                         fe => fe.SizeChanged -= ListView_SizeChanged
                                         );

            // 初期表示時にSizeChangedイベントが発生しなかったのでコントロール読込後に1回だけ手動で実行する。
            BehaviorUtil.Loaded(element,
                                (listview, tmp) => ListView_SizeChanged(listview, null)
                                );
        }
        /// <summary>
        /// Valueプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetValueCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var textbox = target as TextBox;

            BehaviorUtil.SetEventHandler(textbox,
                                         (fe) => fe.GotFocus += TextBox_GotFocus,
                                         (fe) => fe.GotFocus -= TextBox_GotFocus
                                         );
            BehaviorUtil.SetEventHandler(textbox,
                                         (fe) => fe.LostFocus += TextBox_LostFocus,
                                         (fe) => fe.LostFocus -= TextBox_LostFocus
                                         );

            BehaviorUtil.Loaded(textbox,
                                (sender, tmp) => SetText(textbox, (double)e.NewValue)
                                );
        }
Ejemplo n.º 26
0
        /// <summary>
        /// ヘッダプロパティが変更された際の処理
        /// </summary>
        /// <param name="sender">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnHeaderCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var viewer = BehaviorUtil.GetScrollViewer(sender as FrameworkElement);

            BehaviorUtil.SetEventHandler(viewer,
                                         (sv) => sv.ScrollChanged += ScrollViewer_ScrollChanged,
                                         (sv) => sv.ScrollChanged -= ScrollViewer_ScrollChanged
                                         );

            var target = e.NewValue as FrameworkElement;

            BehaviorUtil.SetEventHandler(target,
                                         (sv) => sv.PreviewMouseWheel += FrameworkElement_MouseWheel,
                                         (sv) => sv.PreviewMouseWheel -= FrameworkElement_MouseWheel
                                         );

            BehaviorUtil.Loaded(viewer, ScrollViewer_Loaded);
        }
        /// <summary>
        /// Password プロパティ変更時イベント
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetPasswordCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var passwordbox = sender as PasswordBox;

            if (passwordbox == null)
            {
                return;
            }

            BehaviorUtil.SetEventHandler(passwordbox,
                                         (fe) => fe.PasswordChanged += PasswordBox_PasswordChanged,
                                         (fe) => fe.PasswordChanged -= PasswordBox_PasswordChanged
                                         );

            var newv = e.NewValue as string;
            var oldv = passwordbox.Password;

            if (newv != oldv)
            {
                // 新旧で異なる値ならパスワードボックスに通知
                passwordbox.Password = newv;
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// ToolTipプロパティが変更された際の処理
        /// </summary>
        /// <param name="target">対象</param>
        /// <param name="e">イベント情報</param>
        private static void OnSetToolTipCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var control = target as Control;

            BehaviorUtil.Loaded(control, Control_Loaded);
        }
        /// <summary>
        /// TextBlockの文字をFormattedText化して、その高さを取得します。
        /// </summary>
        /// <param name="block">オブジェクト</param>
        private static double GetFormattedTextHeight(TextBlock block)
        {
            var formatted = BehaviorUtil.GetFormattedText(block, "1");

            return(formatted.Height);
        }