This is a migrated thread and some comments may be shown as answers.

How to set predifined values in the tool set

3 Answers 88 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 14 Jan 2019, 03:00 PM

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

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 17 Jan 2019, 12:01 PM
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.
0
Frank
Top achievements
Rank 1
answered on 28 Aug 2019, 05:09 AM
[quote]

<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>

[/quote]

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>

0
Dilyan Traykov
Telerik team
answered on 30 Aug 2019, 11:36 AM

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.
Tags
ImageEditor
Asked by
Frank
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Frank
Top achievements
Rank 1
Share this question
or