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

DataBinding in CustomShape.cs

5 Answers 83 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 22 Mar 2013, 04:00 PM
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.

5 Answers, 1 is accepted

Sort by
0
Francois Vanderseypen
Top achievements
Rank 2
answered on 22 Mar 2013, 04:56 PM
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.


0
Ravi
Top achievements
Rank 1
answered on 05 Oct 2013, 04:24 PM
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
0
Petar Mladenov
Telerik team
answered on 09 Oct 2013, 02:12 PM
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 >>
0
Ravi
Top achievements
Rank 1
answered on 15 Oct 2013, 06:14 PM
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
0
Petar Mladenov
Telerik team
answered on 18 Oct 2013, 02:15 PM
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 >>
Tags
Diagram
Asked by
Michael
Top achievements
Rank 1
Answers by
Francois Vanderseypen
Top achievements
Rank 2
Ravi
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or