コード例 #1
0
        private static Style GetDefaultStyle()
        {
            Style           style           = new Style(typeof(MultiSliderThumb));
            ControlTemplate controlTemplate = new ControlTemplate(typeof(MultiSliderThumb));

            style.Setters.Add((SetterBase) new Setter(Control.TemplateProperty, (object)controlTemplate));
            Brush brush = MultiSliderThumb.MakeCheckerboardBrush(MultiSliderThumb.checkerboardSize);

            style.Setters.Add((SetterBase) new Setter(Control.BackgroundProperty, (object)brush));
            FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(Canvas), "mainCanvas");

            controlTemplate.VisualTree = frameworkElementFactory;
            GeometryConverter       geometryConverter = new GeometryConverter();
            FrameworkElementFactory child1            = new FrameworkElementFactory(typeof(Path), "outerPath");

            child1.SetValue(Shape.FillProperty, (object)Brushes.White);
            child1.SetValue(Shape.StrokeProperty, (object)Brushes.Black);
            child1.SetValue(Shape.StrokeThicknessProperty, (object)1.0);
            child1.SetValue(Shape.StrokeLineJoinProperty, (object)PenLineJoin.Round);
            child1.SetValue(Path.DataProperty, geometryConverter.ConvertFromInvariantString("M 0 8 L 8 0 L 16 8 L 16 20 L 0 20 Z"));
            child1.SetValue(Canvas.TopProperty, (object)12.0);
            child1.SetValue(Canvas.LeftProperty, (object)-8.0);
            frameworkElementFactory.AppendChild(child1);
            FrameworkElementFactory child2 = new FrameworkElementFactory(typeof(Path), "innerPath");

            child2.SetValue(Shape.FillProperty, (object)Brushes.Black);
            child2.SetValue(Shape.StrokeProperty, (object)Brushes.Black);
            child2.SetValue(UIElement.VisibilityProperty, (object)Visibility.Hidden);
            child2.SetValue(Shape.StrokeThicknessProperty, (object)1.0);
            child2.SetValue(Shape.StrokeLineJoinProperty, (object)PenLineJoin.Round);
            child2.SetValue(Path.DataProperty, geometryConverter.ConvertFromInvariantString("M 3 0 L 6 3 L 0 3 Z"));
            child2.SetValue(Canvas.TopProperty, (object)15.0);
            child2.SetValue(Canvas.LeftProperty, (object)-3.0);
            frameworkElementFactory.AppendChild(child2);
            FrameworkElementFactory child3 = new FrameworkElementFactory(typeof(Rectangle), "innerRectangle");

            child3.SetValue(Shape.FillProperty, (object)new TemplateBindingExtension(Control.ForegroundProperty));
            child3.SetValue(Shape.FillProperty, (object)Brushes.Blue);
            child3.SetValue(Shape.StrokeProperty, (object)Brushes.Black);
            child3.SetValue(Shape.StrokeThicknessProperty, (object)0.25);
            child3.SetValue(Shape.StrokeLineJoinProperty, (object)PenLineJoin.Round);
            child3.SetValue(FrameworkElement.WidthProperty, (object)12.0);
            child3.SetValue(FrameworkElement.HeightProperty, (object)8.0);
            child3.SetValue(Canvas.TopProperty, (object)21.0);
            child3.SetValue(Canvas.LeftProperty, (object)-6.0);
            frameworkElementFactory.AppendChild(child3);
            Trigger trigger = new Trigger();

            trigger.Property = Selector.IsSelectedProperty;
            trigger.Value    = (object)true;
            trigger.Setters.Add((SetterBase) new Setter(UIElement.VisibilityProperty, (object)Visibility.Visible, "innerPath"));
            trigger.Setters.Add((SetterBase) new Setter(Shape.StrokeThicknessProperty, (object)2.0, "outerPath"));
            controlTemplate.Triggers.Add((TriggerBase)trigger);
            return(style);
        }
コード例 #2
0
        private static Style GetDefaultStyle()
        {
            Style           style           = new Style(typeof(MultiSlider));
            ControlTemplate controlTemplate = new ControlTemplate(typeof(MultiSlider));

            style.Setters.Add((SetterBase) new Setter(Control.TemplateProperty, (object)controlTemplate));
            Brush brush = MultiSliderThumb.MakeCheckerboardBrush(MultiSlider.checkerboardSize);

            style.Setters.Add((SetterBase) new Setter(Control.BackgroundProperty, (object)brush));
            FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(Grid), "mainGrid");

            frameworkElementFactory.SetValue(UIElement.ClipToBoundsProperty, (object)false);
            frameworkElementFactory.SetValue(FrameworkElement.WidthProperty, (object)new TemplateBindingExtension(FrameworkElement.WidthProperty));
            frameworkElementFactory.SetValue(FrameworkElement.HeightProperty, (object)new TemplateBindingExtension(FrameworkElement.HeightProperty));
            controlTemplate.VisualTree = frameworkElementFactory;
            FrameworkElementFactory child1 = new FrameworkElementFactory(typeof(Border), "mainBorder");

            child1.SetValue(Border.BackgroundProperty, (object)new TemplateBindingExtension(Control.BackgroundProperty));
            child1.SetValue(Border.BorderBrushProperty, (object)new TemplateBindingExtension(Control.BorderBrushProperty));
            child1.SetValue(Border.BorderThicknessProperty, (object)new TemplateBindingExtension(Control.BorderThicknessProperty));
            frameworkElementFactory.AppendChild(child1);
            FrameworkElementFactory child2 = new FrameworkElementFactory(typeof(Border), "fillBorder");

            child2.SetValue(Border.BackgroundProperty, (object)new TemplateBindingExtension(Control.ForegroundProperty));
            child2.SetValue(Border.BorderBrushProperty, (object)Brushes.Transparent);
            child2.SetValue(Border.BorderThicknessProperty, (object)new TemplateBindingExtension(Control.BorderThicknessProperty));
            frameworkElementFactory.AppendChild(child2);
            FrameworkElementFactory child3 = new FrameworkElementFactory(typeof(Canvas), "itemsCanvas");

            child3.SetValue(UIElement.ClipToBoundsProperty, (object)false);
            child3.SetValue(Panel.IsItemsHostProperty, (object)true);
            frameworkElementFactory.AppendChild(child3);
            Trigger trigger = new Trigger();

            trigger.Property = UIElement.IsEnabledProperty;
            trigger.Value    = (object)false;
            trigger.Setters.Add((SetterBase) new Setter(UIElement.OpacityProperty, (object)0.5));
            style.Triggers.Add((TriggerBase)trigger);
            return(style);
        }