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

TableShape

5 Answers 47 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Prime Minister Office
Top achievements
Rank 1
Prime Minister Office asked on 27 Jan 2016, 03:07 PM

Hi,

I'm trying to create a TableShape project that will visualize tables from our DB, and will enable the users to open tables and create joins between row in a different tables.

I used your demo's code for the TableShape, but instead of --> SamplesFactory (class) --> LoadSample (method) --> diagram.Load(xml) (line 146), I created a TableShape and added it by using : diagram.AddShape(tableShape).

Now I'm trying to add rows to the table, but I can't use the RowShape you have in the demo, I get an exception that the rowShape not suitable for the tableShape.

How can I solve it? How can I add rows to my table?

Best Regards.

5 Answers, 1 is accepted

Sort by
0
Dinko
Telerik team
answered on 01 Feb 2016, 02:33 PM
Hello,

We managed to reproduce the exception that you described. Basically, the TableShape example is created to work in data  binding scenario. There is no built-in logic that handles the scenario when you work directly with the visual elements (TableShape and RowShape). You are getting this type of exception because the wrong Style is applied in the ShapeStyleSelector. To work this around, you can update the implementation in the SelectStyle() method in the selector class so that it returns the correct style. 

However, working directly with the custom shapes will require customization on several places in the code. This is why we recommend you to work with the view models (RowModel and TableModel) of the shapes and the graph source of the diagram. In addition, you can take DataBinding help article.

Hope this information is helpful.

Regards,
Dinko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Matt
Top achievements
Rank 1
answered on 04 Mar 2016, 12:49 PM

I am trying to do something similar, I wanted to iterate through a Query and add the rows based on the Table Information.  So I used your models and from the tableShapes Demo to try to get a good starting point.  I have the style Selector, and I used this code here

to add a shape with a single row in it. 

private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            TableModel table = new TableModel();
            tgs.AddNode(table);
            var itemToAdd = new RowModel() { ColumnName = "NewRow", DataType = DataType.String };
            table.AddItem(itemToAdd);
        }

I get error 

An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll

Additional information: 'RowShape' TargetType does not match type of element 'RadDiagramShape'.

Which is odd since it is derived from RadDiagramShapeBase

I have tried adding the Shapes before adding the container to the viewmodel, no bueno.  If comment out the row addition in the table model, I get the TableShape.

0
Matt
Top achievements
Rank 1
answered on 04 Mar 2016, 08:07 PM

DataContext does nothing for me here

Ok. so I decided to change directions and scrap the Table Shape Example, because all I really needed was the rowShape.  I am able to add Row Shapes to a stock ContainerShape. 

I decided to use the RowShape Style (Would rather not use a style, styles suck) and set that programmatically;

first I added a TableInfo class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RoundPegTest
{
    class TableInfo
    {
        public string ColumnName { get; private set; }
        public string DataType { get; private set; }
        public TableInfo(string columnName, string dataType) {
            this.ColumnName = columnName;
            this.DataType = dataType;
        }
    }
}

//after filling the Info class and setting each one to a list i iterate

 foreach (TableInfo info in columnlist) { //iterate through each table
                RadDiagramShape shape = new RadDiagramShape(); //create a shape
       
                shape.Style = (Style)FindResource("rowStyle"); //select the rowStyle from TableShape Example
            
                Debug.WriteLine(info.ColumnName);  // just making sure I have data inside the class and I do

                shape.DataContext = info;  //Info has two variables get; set; ColumnName DataType, and rowStyle Text boxes in the           // datatemplate are bound to ColumnName and DataType So I set the Data context here, and no Bueno
                shape.Position = new Point(0, cont.Items.Count * 30); // just positioning each Row;
                cont.Items.Add(shape);  //adding to the shape
            }

 

Ok So the Code works as expected with the exception being that the binding doesn't seem to want to work.  So I get Blank row shapes instead of the ColumnName and DataType that I am expecting.  I could just set the text on each one manually, but I havent the foggiest of how to get the TextBlock and set its text from Code Behind. 

 

What I would rather have is a shape where I could Throw two named TextBlocks that are named and be able to set them in code behind. Starting to wonder if this WPF stuff is worth the trouble really.  I am old school, I like to just create stuff with code. XML is for data. Anyway, any help figuring out why setting the data context of the shape does absolutely nothing for me

 

 

0
Dinko
Telerik team
answered on 09 Mar 2016, 12:29 PM
Hi Matt,

I need more time to check your scenario. I will contact you as soon we have more information about the case.

Regards,
Dinko
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Dinko
Telerik team
answered on 09 Mar 2016, 03:26 PM
Hi Matt,

Let me start first with that the RadDiagramShape is ContentControl. This means that the bindings in its ContentTemplate point to the Content property instead of the DataContext. In other words, to set the context of the RadDiagramShape, you need to set its Content property. 
RadDiagramShape shape = new RadDiagramShape();
shape.Style = (Style)FindResource("rowStyle");
shape.Content = yourBusinessObject;
.  .  .
In addition you can take a look at the MSDN Content Controls help article where you can find more information about this type of controls.

Regards,
Dinko
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Diagram
Asked by
Prime Minister Office
Top achievements
Rank 1
Answers by
Dinko
Telerik team
Matt
Top achievements
Rank 1
Share this question
or