R
ryan baldwin
Hey all -
I'm seeing some extremely odd behaviour on dynamically loaded XAML forms
that are bound to an XmlDataProvider. This will be slightly difficult
for me to explain, so I'll try to give everybody some background of what
we're doing and what the problem is.
We're creating an application for our client that has to generate forms,
on the fly, that revolve around XSD (which they will be updating with
additional complexTypes whenever they need). Pretend you have a whole
bunch of XSD complexTypes, and the application has to create forms that
allow users to create XML fragments that are valid for each XSD
complexType. For example, perhaps they have an XSD ComplexType named
"Dog" with a few elements (colour, gender, and breed) - our application
will be required to generate a form with colour, gender, and breed input
controls.
This is easily achieved by running an XSLT stylesheet over the XSD and
generating a bunch of XAML at run time, which we then load it into the
app using a XamlReader. The generated XAML contains 2 XmlDataProviders
which the controls bind to: 1 for binding pick lists (some of the
controls are comboboxes), and a second that is the user-created XML
fragment. The controls are bound to these XmlDataProviders as one would
normally bind to an XmlDAtaProvider in XAML; using XPath.
I have a single class that's responsbile for loading the styles sheets,
creating the XAML on the fly, and keeping track of the generated XAML's
namespace (so that I can reference the various elements on the generated
XAML fragment if needed). I have everything binding, rendering, and
saving beautifully (although the saving is a bit of a hack due to the
XmlDataProvider not creating elements/attributes on the fly)... with one
extremely frustrating and puzzling exception.
Sometimes, after generating, loading, and binding the XAML form, data on
that form will disappear if I modify data on other parts of that same
form. For example, lets say I have 3 textboxes, "Manufacturer", "Make",
and "Model", where "Make" and "Model" are in a stack panel. I provide a
value for Manufacturer, all is well. When I provide the value for Make
or Model, however, the value for Manufacturer suddenly disappears. All
3 textboxes are bound against an XmlDataProvider and are TwoWay. Note
that if I have multiple textboxes at the same level in the XAML (such as
all in a grid, and none of them in a child stackpanel), then they all
behave fine. It's only when some of the textboxes are "deeper" in the
visual/logical tree, such as in a groupbox or stackpanel, when I witness
the behaviour.
I have no idea why data is just disappearing like this... it makes no
sense to me. None of the three xaml elements are dependent upon
eachother - the only thing they have in common is the XmlDataProvider
(however all 3 have a different XPath). Also, if I take the generated
XAML and create a normal Xaml page in VisualStudio, build and deploy,
none of this behaviour is ever exhibited - it seems to only happen when
the form is generated and loaded on the fly.
Has anybody experienced anything like this? Has anybody observed this
behaviour? Have I made any sense? Please help, ask questions, etc - as
I'm currently blocked of advancing on anything until I can get this
resolved (I've burned a couple days exhausting ideas).
Thanks.
- ryan.
I'm seeing some extremely odd behaviour on dynamically loaded XAML forms
that are bound to an XmlDataProvider. This will be slightly difficult
for me to explain, so I'll try to give everybody some background of what
we're doing and what the problem is.
We're creating an application for our client that has to generate forms,
on the fly, that revolve around XSD (which they will be updating with
additional complexTypes whenever they need). Pretend you have a whole
bunch of XSD complexTypes, and the application has to create forms that
allow users to create XML fragments that are valid for each XSD
complexType. For example, perhaps they have an XSD ComplexType named
"Dog" with a few elements (colour, gender, and breed) - our application
will be required to generate a form with colour, gender, and breed input
controls.
This is easily achieved by running an XSLT stylesheet over the XSD and
generating a bunch of XAML at run time, which we then load it into the
app using a XamlReader. The generated XAML contains 2 XmlDataProviders
which the controls bind to: 1 for binding pick lists (some of the
controls are comboboxes), and a second that is the user-created XML
fragment. The controls are bound to these XmlDataProviders as one would
normally bind to an XmlDAtaProvider in XAML; using XPath.
I have a single class that's responsbile for loading the styles sheets,
creating the XAML on the fly, and keeping track of the generated XAML's
namespace (so that I can reference the various elements on the generated
XAML fragment if needed). I have everything binding, rendering, and
saving beautifully (although the saving is a bit of a hack due to the
XmlDataProvider not creating elements/attributes on the fly)... with one
extremely frustrating and puzzling exception.
Sometimes, after generating, loading, and binding the XAML form, data on
that form will disappear if I modify data on other parts of that same
form. For example, lets say I have 3 textboxes, "Manufacturer", "Make",
and "Model", where "Make" and "Model" are in a stack panel. I provide a
value for Manufacturer, all is well. When I provide the value for Make
or Model, however, the value for Manufacturer suddenly disappears. All
3 textboxes are bound against an XmlDataProvider and are TwoWay. Note
that if I have multiple textboxes at the same level in the XAML (such as
all in a grid, and none of them in a child stackpanel), then they all
behave fine. It's only when some of the textboxes are "deeper" in the
visual/logical tree, such as in a groupbox or stackpanel, when I witness
the behaviour.
I have no idea why data is just disappearing like this... it makes no
sense to me. None of the three xaml elements are dependent upon
eachother - the only thing they have in common is the XmlDataProvider
(however all 3 have a different XPath). Also, if I take the generated
XAML and create a normal Xaml page in VisualStudio, build and deploy,
none of this behaviour is ever exhibited - it seems to only happen when
the form is generated and loaded on the fly.
Has anybody experienced anything like this? Has anybody observed this
behaviour? Have I made any sense? Please help, ask questions, etc - as
I'm currently blocked of advancing on anything until I can get this
resolved (I've burned a couple days exhausting ideas).
Thanks.
- ryan.