当前位置: 首页>>代码示例>>C#>>正文


C# Canvas.ReleaseMouseCapture方法代码示例

本文整理汇总了C#中System.Windows.Controls.Canvas.ReleaseMouseCapture方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.ReleaseMouseCapture方法的具体用法?C# Canvas.ReleaseMouseCapture怎么用?C# Canvas.ReleaseMouseCapture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Canvas的用法示例。


在下文中一共展示了Canvas.ReleaseMouseCapture方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnApplyTemplate

        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or internal processes call <see cref="M:System.Windows.FrameworkElement.ApplyTemplate"/>.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _gradientCanvas = Template.FindName("PART_GradientCanvas", this) as Canvas;
            _gradientSelector = Template.FindName("PART_GradientSelector", this) as FrameworkElement;
            _colorSpectrumSlider = Template.FindName("PART_ColorSpectrumSlider", this) as ColorSpectrumSlider;
            _tbA = Template.FindName("PART_TextBoxA", this) as TextBox;
            _tbR = Template.FindName("PART_TextBoxR", this) as TextBox;
            _tbG = Template.FindName("PART_TextBoxG", this) as TextBox;
            _tbB = Template.FindName("PART_TextBoxB", this) as TextBox;
            _tbHexString = Template.FindName("PART_TextBoxHexString", this) as TextBox;

            if (_gradientCanvas != null)
            {
                _gradientCanvas.PreviewMouseLeftButtonDown += (o, e) =>
                {
                    var p = e.GetPosition(_gradientCanvas);
                    UpdateColorByPosition(p);
                    _gradientCanvas.CaptureMouse();
                    e.Handled = true;
                };
                _gradientCanvas.MouseMove += (o, e) =>
                {
                    if (_gradientCanvas.IsMouseCaptured && e.LeftButton == MouseButtonState.Pressed)
                    {
                        var position = e.GetPosition(_gradientCanvas);
                        UpdateColorByPosition(position);
                    }
                };
                _gradientCanvas.MouseLeftButtonUp += (o, e) =>
                {
                    _gradientCanvas.ReleaseMouseCapture();
                };
                _gradientCanvas.SizeChanged += (o, e) =>
                {
                    var hslColor = _lastPreciseColor ?? HslColor.FromArgb(Color);
                    hslColor.H = _colorSpectrumSlider.Value;
                    UpdateColor(hslColor.ToArgb(), hslColor);
                };
            }
            if (_colorSpectrumSlider != null)
            {
                _colorSpectrumSlider.ValueChanged += (o, e) =>
                {
                    var hslColor = _lastPreciseColor ?? HslColor.FromArgb(Color);
                    hslColor.H = _colorSpectrumSlider.Value;
                    UpdateColor(hslColor.ToArgb(), hslColor);
                };
            }

            UpdateColor(Color, null);
        }
开发者ID:alexguo88,项目名称:WpfExtensions,代码行数:56,代码来源:ColorPicker.cs


注:本文中的System.Windows.Controls.Canvas.ReleaseMouseCapture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。