Skip to content

Commit 337d101

Browse files
Merge pull request #2940 from telerik/new-kb-change-shape-colors-raddiagram-wpf-d9f4df10b9b246ab990c6d55c358b786
Added new kb article change-shape-colors-raddiagram-wpf
2 parents 991e9f1 + acae187 commit 337d101

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Change the Colors of the Shape Dropped from RadDiagram Toolbox
3+
description: How to modify the brush of the drag/dropped shape added from the RadDiagram Toolbox to the RadDiagram canvas in a WPF application.
4+
type: how-to
5+
page_title: Modify the Color of the Shape Dragged from RadDiagramToolbox
6+
slug: change-shape-colors-raddiagram-wpf
7+
tags: radDiagram, wpf, shape, color, toolbox, brush
8+
res_type: kb
9+
ticketid: 1627931
10+
---
11+
12+
## Environment
13+
14+
| Product | Version |
15+
| --- | --- |
16+
| RadDiagram for WPF | 2023.2.606 |
17+
18+
## Description
19+
20+
How to change the background and border brush a shape dragged from the RadDiagramToolBox, when the shape get dropped onto the RadDiagram surface.
21+
22+
## Solution
23+
24+
You can subscribe to the `SerializationService.Default.ItemSerializing` event. In the event handler, you can update the "Background" and "BorderBrush" settings of the `SerializationInfo` object.
25+
26+
#### __[C#]__
27+
{{region change-shape-colors-raddiagram-wpf-0}}
28+
public MainWindow()
29+
{
30+
InitializeComponent();
31+
SerializationService.Default.ItemSerializing += Default_ItemSerializing;
32+
}
33+
34+
private void Default_ItemSerializing(object sender, SerializationEventArgs<IDiagramItem> e)
35+
{
36+
var shape = e.Entity as RadDiagramShape;
37+
if (shape != null && shape.ParentOfType<RadDiagramToolbox>() != null)
38+
{
39+
e.SerializationInfo["Background"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8EC251"));
40+
e.SerializationInfo["BorderBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8EC251"));
41+
}
42+
}
43+
{{endregion}}
44+
45+
In case you need to change also the colors of the shape when displayed inside the RadDiagramToolBox, then you can add an implicit style in the `RadDiagramToolBox.Resources` tag and target the `RadDiagramShape` controls.
46+
47+
#### __[XAML]__
48+
{{region change-shape-colors-raddiagram-wpf-1}}
49+
<telerik:RadDiagramToolbox.Resources>
50+
<Style TargetType="telerik:RadDiagramShape">
51+
<Setter Property="Background" Value="#8EC251" />
52+
<Setter Property="BorderBrush" Value="#8EC251" />
53+
</Style>
54+
</telerik:RadDiagramToolbox.Resources>
55+
{{endregion}}
56+

0 commit comments

Comments
 (0)