Data Binding RadDiagramShape

3 posts, 0 answers
  1. Yuet Chung
    Yuet Chung avatar
    2 posts
    Member since:
    Oct 2012

    Posted 12 Jan 2013 Link to this post

    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. Francois Vanderseypen
    Francois Vanderseypen avatar
    46 posts
    Member since:
    Oct 2009

    Posted 12 Jan 2013 Link to this post

    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.

  3. DevCraft banner
  4. Yuet Chung
    Yuet Chung avatar
    2 posts
    Member since:
    Oct 2012

    Posted 12 Jan 2013 Link to this post

    Actually, that's all I need, thanks :)
Back to Top