Expression Editor without Grid View?

5 posts, 1 answers
  1. David
    David avatar
    5 posts
    Member since:
    Oct 2012

    Posted 23 Oct 2012 Link to this post

    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;

     

  2. David
    David avatar
    5 posts
    Member since:
    Oct 2012

    Posted 23 Oct 2012 Link to this post

    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?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 24 Oct 2012 Link to this post

    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.

  5. David
    David avatar
    5 posts
    Member since:
    Oct 2012

    Posted 25 Oct 2012 Link to this post

    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.
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 30 Oct 2012 Link to this post

    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.

Back to Top
UI for WPF is Visual Studio 2017 Ready