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:
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:
...and the view model:
<PRE>
publicclass
FormInfoModel
{
public
IDictionary
<
string
,
object
> Elements
{
get
{
return
_elements; }
}
private
IDictionary
<
string
,
object
> _elements;
public
FormInfoModel()
{
_elements =
new
Dictionary
<
string
,
object
>();
_elements.Add(
"Order_Date"
,
DateTime
.Today);
_elements.Add(
"Qty_1"
, 0);
_elements.Add(
"Unit_Price_1"
, 0);
}
}
</PRE>
<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;