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

Data Binding RadDiagramShape

2 Answers 90 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Yuet Chung
Top achievements
Rank 1
Yuet Chung asked on 12 Jan 2013, 03:18 PM
Hi,

I am new to Telerik and Silverlight development, I want to know if it is possible to use data binding on the field "Geometry" in xaml?
i.e. something like Geometry="{Binding ShapeType}", in the code behind that can return the different enums defined in different namespace?

Thanks

2 Answers, 1 is accepted

Sort by
0
Francois Vanderseypen
Top achievements
Rank 2
answered on 12 Jan 2013, 03:43 PM
It depends a bit on what the broader context is, are you using MVVM, do you have geometries in some other assembly...?

The most basic example would be the following. You set somewhere in XAML or in code the DataContext of the shape (or of some object in the hierarchy of the shape, this could be the RadDiagram instance itself, or like below the embracing Window) and then databind to a property which returns some geometry.

public Geometry MyGeometry
{
    get
    {
        return ShapeFactory.CommonGeometries[CommonShapeType.CloudShape];
    }
}
public MainWindow()
{
    InitializeComponent();
    this.DataContext = this;
}

then in XAML you can do something like

<telerik:RadDiagramShape Geometry="{Binding MyGeometry}" />

Note that if you want custom geometry you can use Blend or even a standard SVG editor to create some geometry in string format (stuff like "m99,138l135,-48l94,93l-96,114l-32,-106l-128,46l27,-99z") and then use the GeometryParser to return the Geometry;

GeometryParser.GetGeometry("m99,138l135,-48l94,93l-96,114l-32,-106l-128,46l27,-99z")

If you want to use an enum type then you can databind as well but you'll need a value converter and plug it into the XAML syntax. 

Hope this helps, Fr.

0
Yuet Chung
Top achievements
Rank 1
answered on 12 Jan 2013, 04:22 PM
Actually, that's all I need, thanks :)
Tags
Diagram
Asked by
Yuet Chung
Top achievements
Rank 1
Answers by
Francois Vanderseypen
Top achievements
Rank 2
Yuet Chung
Top achievements
Rank 1
Share this question
or