How to set predifined values in the tool set

4 posts, 0 answers
  1. Frank
    Frank avatar
    28 posts
    Member since:
    May 2006

    Posted 14 Jan 2019 Link to this post

    Hi,

    I want to save selections like shape border thickness as settings so when the user work with the tool again the last selected thickness should be selected instead of the default value.

    How do I approach and solve this?

     

    Best regards

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1053 posts

    Posted 17 Jan 2019 Link to this post

    Hello Frank,

    What I can suggest to achieve the desired result would be to define your own custom ShapeTool and provide it with a custom ShapeToolSettings control.

    public class CustomShapeToolSettings : ShapeToolSettings
    {
        public CustomShapeToolSettings(double strokeSize) : base()
        {
            this.StrokeSize = strokeSize;
        }
    }
     
    public class CustomShapeTool : ShapeTool
    {
        private double strokeSize;
        public double StrokeSize
        {
            get { return this.strokeSize; }
            set
            {
                this.strokeSize = value;
                this.settingsUI.StrokeSize = value;
            }
        }
     
        private readonly CustomShapeToolSettings settingsUI;
     
        public CustomShapeTool()
        {
            this.settingsUI = new CustomShapeToolSettings(this.StrokeSize);
        }
     
        public override UIElement GetSettingsUI()
        {
            return this.settingsUI;
        }
    }

    You can the use this custom tool and set its StrokeSize manually.

    <telerik:ImageToolItem ImageKey="Shape" telerik:LocalizationManager.ResourceKey="ImageEditor_Shape" Command="commands:ImageEditorRoutedCommands.ExecuteTool">
        <telerik:ImageToolItem.CommandParameter>
            <local:CustomShapeTool StrokeSize="5">
                <local:CustomShapeTool.Shapes>
                    <myShapes:TelerikLogo />
                    <shapes:RectangleShape />
                    <shapes:EllipseShape />
                    <shapes:LineShape />
                </local:CustomShapeTool.Shapes>
            </local:CustomShapeTool>
        </telerik:ImageToolItem.CommandParameter>
    </telerik:ImageToolItem>

    You can then choose how to persist the StrokeSize property depending on your setup. A possible option would be the PersistenceFramework.

    Please let me know whether this helps you in achieving your goal.

    Regards,
    Dilyan Traykov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Frank
    Frank avatar
    28 posts
    Member since:
    May 2006

    Posted 28 Aug 2019 in reply to Dilyan Traykov Link to this post



    <telerik:ImageToolItem ImageKey="Shape" telerik:LocalizationManager.ResourceKey="ImageEditor_Shape" Command="commands:ImageEditorRoutedCommands.ExecuteTool">
        <telerik:ImageToolItem.CommandParameter>
            <local:CustomShapeTool StrokeSize="5">
                <local:CustomShapeTool.Shapes>
                    <myShapes:TelerikLogo />
                    <shapes:RectangleShape />
                    <shapes:EllipseShape />
                    <shapes:LineShape />
                </local:CustomShapeTool.Shapes>
            </local:CustomShapeTool>
        </telerik:ImageToolItem.CommandParameter>
    </telerik:ImageToolItem>

    With this code it is possible for me to set the strokesize manually but the combobox with the shapes (rectangle, ellipse,...) is empty now. I can't select any shape.

    This is my Code:

     

    <telerik:ImageToolItem ImageKey="Shape" Command="commands:ImageEditorRoutedCommands.ExecuteTool"  telerik:LocalizationManager.ResourceKey="ImageEditor_Shape">
                            <telerik:ImageToolItem.CommandParameter>
                                <CusShapes:MyShapeTool x:Name="shapeTool">
                                    <CusShapes:MyShapeTool.Shapes>
                                        <shapes:RectangleShape/>
                                        <shapes:EllipseShape />
                                        <shapes:LineShape/>
                                    </CusShapes:MyShapeTool.Shapes>
                                </CusShapes:MyShapeTool>
                            </telerik:ImageToolItem.CommandParameter>
                        </telerik:ImageToolItem>

  4. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1053 posts

    Posted 30 Aug 2019 Link to this post

    Hi Frank,

    Please excuse me for overlooking this.

    You will need to add one more line to the CustomShapeTool constructor for everything to work as expected:

            public CustomShapeTool()
            {
                this.settingsUI = new CustomShapeToolSettings(this.StrokeSize);
                this.GetType().BaseType.GetField("settingsUI", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(this, this.settingsUI);
            }
    Please let me know if this provides the desired result.

    Regards,
    Dilyan Traykov
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top