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

Expression Editor without Grid View?

4 Answers 113 Views
ExpressionEditor
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 23 Oct 2012, 03:20 PM
I'm trying to provide a "formula editor" for an in-house application.  I'm trying out the Expression Editor to see if it will work for what we want ... notably, the list of fields available for to be used in a formula will be determined at run-time depending on the application state/context.

I haven't done very much with WPF, so just to get my feet wet, I followed the instructions in the "Getting Started" help topic to create a small app that uses the Expression Editor (with a grid view).

I then created an almost identical sample app that uses the Expression Editor without a Grid View. 
Since the field list will be "dynamic" I'm using an ExpandoObject as the view model, as described in this forum post.  And in fact the ExpandoObject properties do show up in the field list. 
However, the expression always seems to be invalid ... even for simple expressions like "Qty_1 * Unit_Price_1". 
Again, this is almost all identical to the previous iteration ... except that now I don't have a data grid, and I'm generating the "property bag" dynamically. Do I have to use the editor in conjunction with a RadGridView?  Or is it the dynamic properties that are the problem?


Here's my model:
<PRE>
public
class FormInfoModel
{
    public IDictionary<stringobject> Elements
    {
         get { return _elements; }
    }
    private IDictionary<stringobject> _elements;
    public FormInfoModel()
    {
         _elements = new Dictionary<stringobject>();
         _elements.Add("Order_Date"DateTime.Today);
         _elements.Add("Qty_1", 0);
         _elements.Add("Unit_Price_1", 0);
    }
}
</PRE>
...and the view model:
<PRE>public class FormInfoViewModel
{
    public
ExpandoObject Info
   
{
        get { return _info;
}
    }
    private ExpandoObject _info;
    public void SetInfo(FormInfoModel model)
    {
       
dynamic dobj = new ExpandoObject();
        foreach (var key in model.Elements.Keys)
       
{
            (dobj as
IDictionary<string, object>).Add(key, model.Elements[key]);
       
}
        _info =
dobj;
    }
}</PRE>

Then in the MainWindow constructor I set the binding programmatically:

  _viewModel = this.Resources["FormInfoViewModel"] as FormInfoViewModel;
   ExpressionEditor.Item =
_viewModel.Info;

 

4 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 23 Oct 2012, 05:26 PM
If I replace the dynamic property bag with a statically typed object -- whose properties are int / double / decimal / etc. -- the issue appears to go away.  So I'm guessing it's the dynamic properties.  Can you confirm?
0
Accepted
Vlad
Telerik team
answered on 24 Oct 2012, 06:23 AM
Hello,

 Indeed dynamic objects are not supported currently and we will do our best to add this as soon as possible - most probably Q1 2013 (end of February 2013) . 

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
David
Top achievements
Rank 1
answered on 25 Oct 2012, 01:18 PM
As a workaround, would it be possible to set up a non-visble RadGridView, define its columns dynamically, and then bind the expression editor to those column definitions? i.e.

GridViewDataColumn col;<BR>
col =
new
GridViewDataColumn()<BR>
     
{<BR>
        UniqueName =
"Qty_1",<BR>
        DataType   =
typeof(int),<BR>     
};<BR>
DataGrid.Columns.Add(col);<BR>
col =
new
GridViewDataColumn()<BR>
    
{<BR>
        UniqueName =
"Unit_Price_1",<BR>
       
DataType   = typeof(decimal),<BR>     
};<BR>
DataGrid.Columns.Add(col);<BR>
//etc

... but I'm not sure how to set up the binding for the expression editor in this case -- all the examples I've seen on your site bind to a particular object (or collection).

I realize this is far from best practice.  I'm just wondering if it's even possible.
0
Vlad
Telerik team
answered on 30 Oct 2012, 07:30 AM
Hi,

 The editor will work with underlying data item directly and will not depend on column visibility. The only solution we can offer you at the moment is to not use dynamic objects. 

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ExpressionEditor
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or