DataBinding in CustomShape.cs

6 posts, 0 answers
  1. Michael
    Michael avatar
    16 posts
    Member since:
    Dec 2011

    Posted 22 Mar 2013 Link to this post

    Hi,

    I am trying to create something similar to the Financial Dashboard with custom shapes that contain data . I have successfully created the shape just need to know how to bind data from sql.
    In the Generic.xaml file I have placed 2 Label controls inside the ControlTemplate
     <ControlTemplate TargetType="local:CustomShape">
        

    <sdk:Label Name="lblProp" Grid.Row="0" Grid.Column="1" Height="30" Content="" FontSize="14" Margin="5 -10 0 0" FontFamily="Segoe WP" />

    <sdk:Label x:Name="lblPropAddress" Grid.Row="1" Grid.Column="1" Content="" FontSize="12" Margin="5 0 0 0" FontFamily="Segoe WP" />
    </ControlTemplate>

    I need to bind the content of these controls to data from SQL.   Would I code the sql data, etc inside the CustomShape.cs or should I create a separate class file for this? How would I bind? I have been trying out samples, etc, but with no luck. I'm new, a little lost and really could use some help on where to go from here. Thanks so much.

  2. Francois Vanderseypen
    Francois Vanderseypen avatar
    46 posts
    Member since:
    Oct 2009

    Posted 22 Mar 2013 Link to this post

    Michael,

    an enterprise-level app would normally have some kind of data access layer (and a business layer on top of this) which talks to the database or webservice. The MVVM would then load data fetched through this stack of layers. Through XAML databinding the shape would then get its data from the MVVM/DataContext. 
    The advantage of this stack are manifold but in case you have only something simple in mind you can equally well do the data access inside your application or inside a custom shape. The 'simple' here means that the inter-dependency and logic is low and that what you potentially code inside a custom shape is not necessary in another shape (or another part of the app), otherwise you end up with spaghetti and maybe even instantiating custom shapes just for the sake of doing data access. So, think a bit in advance what your end-goal is and what the common API is you need, put it separately and do the minimum inside the custom shape. This way you make sure that data-logic is not locked inside a (custom) shape class.

    Hope this helps, Fr.


  3. DevCraft banner
  4. Ravi
    Ravi avatar
    3 posts
    Member since:
    Aug 2013

    Posted 05 Oct 2013 Link to this post

    Hi Francois,

    How are you. I am facing a problem of Databindings for Custom Shape of Drawing Control.

    Scenario:
    =======

    I have a Existing User Control known as "Buyer". This "Buyer User control" has got some Textboxes and Dropdowns with "events" attached to it. I want to utilize this "Buyer User Control" in "Buyer Custom Shape" in "Generic.xaml". I have added this "Buyer Custom Shape" to ListBox. and I have other ListBox which is having "Buyer Names"  I have to Drag Drop this "Buyer Name" along with "Buyer Custom Shape" along with the Data binded to "Buyer User Control".

    I am following the Custom Shape example given by Telerik but I am facing problem in Databinding for this "Buyer Custom Shape". The "Buyer User Control" is not getting its data.

    Can you please let me know how to handle this situation by getting "Buyer User Control" of "Buyer Custom Shape" get its binded data.

    Please help me on this.

    Thanks

    Ravi K
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 09 Oct 2013 Link to this post

    Hello Ravi,

     We think this is a question of organizing your ViewModels. If you have Shape with DataContext - ShapeViewModel, and you need ListBox in the Shape to have ItemsSource - BuyerNames, you just have to ensure that ShapeViewModel provides collection BuyerNames. However, we believe that you can provide more detailed information in a separate support ticket and we will be much better able to advice you.

    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Ravi
    Ravi avatar
    3 posts
    Member since:
    Aug 2013

    Posted 15 Oct 2013 Link to this post

    HI Mladenov ,

    I am using drawing example from the demos of telerik. Can you please tell me how to save the data for custom shape and load the data with custom shape. Please can you provide me an example.

    Thanks

    RaviK
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 18 Oct 2013 Link to this post

    Hello Ravi,

    Actually the Drawing sample ensures that shapes created with Path / Pencil tools can be saved / loaded.
    The save load can be simply tested with copy then pasting a custom shape. Copy operations uses internally save (which serializes the properties of the shape) and paste deserializes these properties.
    You can also add Save / Load buttons and custom shapes will be successfully saved and then loaded.
    Please let us know if you have any additional requirements.

    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
DevCraft banner