Hi,
In the documentation of Shape Tool https://docs.telerik.com/devtools/wpf/controls/radimageeditor/tools/shape-tool it says that: "The Shape Tool provides an options to easily customize your shape – you can choose if the shape will be filled with some color or it will consist only of borders, which color and thickness also depends on your preferences. You could take advantage of the LockRatio property, which will ensure that the proportions of the shape will be always the same when resizing.".
But I don't have these options in my ShapeTool() or in my RectangleShape() object (I execute tool commands by code).
Where can I set a border color and a thickness in rectangle shapes and the same for a custom shape tool by code? (I don't use the option panel displayed on right).
Version of my telerik controls: 2019.2.510.45
Thanks in advance for your reply.
5 Answers, 1 is accepted
Hello Fabien,
There is no public API for the properties mentioned in the article. The paragraph you are referring to is describing the options available via the settings UI.
To achieve your requirement, you can create a custom ShapeTool, expose the properties you want to set in code (fill and border) and then apply them to the corresponding element. Here is an example in code:
public class CustomShapeTool : ShapeTool
{
private ShapeToolSettings settingsUI;
private Color fillColor;
private Color strokeColor;
private double strokeSize;
public Color FillColor
{
get { return fillColor; }
set
{
fillColor = value;
this.settingsUI.FillColor = fillColor;
}
}
public Color StrokeColor
{
get { return strokeColor; }
set
{
strokeColor = value;
this.settingsUI.StrokeColor = strokeColor;
}
}
public double StrokeSize
{
get { return strokeSize; }
set
{
strokeSize = value;
this.settingsUI.StrokeSize = strokeSize;
}
}
public CustomShapeTool() : base()
{
var settingsUIFieldInfo = typeof(ShapeTool).GetField("settingsUI", BindingFlags.NonPublic | BindingFlags.Instance);
this.settingsUI = (ShapeToolSettings)settingsUIFieldInfo.GetValue(this);
}
}
Regards,
Martin Ivanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Thanks for your reply!
That works fine!
I do the same for a DrawTextTool but my text not match with the color passed in parameter:
public
class
CustomDrawTextTool : DrawTextTool
{
private
DrawTextToolSettings settingsUI;
private
Color textColor;
public
Color TextColor
{
get
{
return
textColor; }
set
{
textColor = value;
settingsUI.TextColor = textColor;
}
}
private
double
fontSize;
public
double
FontSize
{
get
{
return
fontSize; }
set
{
fontSize = value;
settingsUI.TextFontSize = fontSize;
}
}
private
string
text;
public
string
Text
{
get
{
return
text; }
set
{
text = value;
settingsUI.Text = text;
}
}
public
CustomDrawTextTool() :
base
()
{
var settingsUIFieldInfo =
typeof
(DrawTextTool).GetField(
"settingsUI"
, BindingFlags.NonPublic | BindingFlags.Instance);
this
.settingsUI = (DrawTextToolSettings)settingsUIFieldInfo.GetValue(
this
);
}
}
My code when I click on a button (like the ShapeTool):
CustomDrawTextTool textTool =
new
CustomDrawTextTool
{
FontSize = ImageControlConfig.PenSize,
TextColor = ImageControlConfig.PenColor,
Text =
"my Text"
};
ImageEditor.Commands.ExecuteTool.Execute(textTool);
What I missed?
Thanks.
Best regards.
Hello Fabien,
The different tools in the image editor control communicate differently with the corresponding UI, so the approach should also be changed. In the DrawTextTool, you can use the following method:
public class CustomDrawTextTool : DrawTextTool
{
private DrawTextToolSettings settingsUI;
public Color TextColor { get; set; }
public double FontSize { get; set; }
public string Text { get; set; }
public CustomDrawTextTool() : base()
{
var settingsUIFieldInfo = typeof(DrawTextTool).GetField("settingsUI", BindingFlags.NonPublic | BindingFlags.Instance);
this.settingsUI = (DrawTextToolSettings)settingsUIFieldInfo.GetValue(this);
}
public override void ResetSettings()
{
base.ResetSettings();
if (this.settingsUI != null)
{
this.settingsUI.TextColor = this.TextColor;
this.settingsUI.TextFontSize = this.FontSize;
this.settingsUI.Text = this.Text;
var applyMethodInfo = typeof(DrawTextTool).GetMethod("ApplySettings", BindingFlags.Instance | BindingFlags.NonPublic);
applyMethodInfo.Invoke(this, null);
}
}
}
Regards,
Martin Ivanov
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).
Thanks a lot again. That works perfectly!