Disappearing Data on Dynamically Loaded WPF Form

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.
 
L

Linda Liu[MSFT]

Hi Ryan,

Welcome to the MSDN managed Newsgroup!

Your problem seems a little complex. It would be better for us to
trouble-shoot the problem for you if you could provide a sample project
that could just reproduce the problem. Please send your sample project to
my email box ([email protected]).

Thank you for your understanding and cooperation!
I look forward to your reply.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

ryan baldwin

Hi Linda,

The problem is indeed complex. I'll try my best to create a small
sample project that reproduces the error.

Thanks.

- ryan.
 
L

Linda Liu[MSFT]

Hi Ryan,

How about your sample project now?

I know when you're trying to reproduce the problem you encountered another
problem and you posted another issue with the title "WPF ComboBox Binding
Confusion" in the
microsoft.public.dotnet.framework.windowsforms.databinding newsgroup.

The issue you described in the "WPF ComboBox Binding Confusion" post is
confirmed a limitation of the ComboBox control by our product team.

The reason behind this issue is that ComboBox uses a private binding to get
the text representing the selected item (see TextSearch.GetPrimaryText).
This binding binds directly to the selected item, in this case an
XmlElement. There's no back link from the XmlElement to the
XmlDataProvider, and therefore no way to get to the namespace map. So any
binding that uses ns prefixes won't be able to map them to Uri's.

A workaround is to specify Binding.XmlNamespaceManager for the ComboBox
explicitly:
<ComboBox Binding.XmlNamespaceManager="{StaticResource namespaceMappings}"
../>

Hope this will help you to reproduce the original problem in a simple
project.

I look forward to your reply!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top