Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - XmlDataProvider Problem : How to initialize to load XML Data

 
 
Old 07-27-2006   #1 (permalink)
HolaMan


 
 

XmlDataProvider Problem : How to initialize to load XML Data

Hi~~~

I look up many samples about XmlDataProvider.
But I found a problem.

If I add a XmlDataProvider in XML and want to C# code to access it. It
doesn't work.
But if I add a control or menu and assign this XmlDataProvider to its
DataContext.
Then the code works.

<!-- Sample XML -->
<XmlDataProvider x:Key="menuData">
<x:XData>
<Items xmlns="">
<Item Title="Foo..." GroupName="First Group">
<Item Title="A"/>
<Item Title="B"/>
<Item Title="C"/>
</Item>
<Item Title="Crimp" GroupName="Another Group" />
<Item Title="Splange" GroupName="Another Group" />
<Item Title="Frobnicate..." GroupName="Another One" />
<Item Title="Do stuff" GroupName="First Group" />
<Item Title="Mangle" GroupName="First Group" />
</Items>
</x:XData>
</XmlDataProvider>
....
<Menu DataContext="{StaticResource menuData}"/> <!-- if i remove this
line, then code doesn't work -->



// Code
XmlDataProvider xdp = FindResource("menuData") as XmlDataProvider;
if( xdp.Data == null )
MessageBox.Show("Data is not loaded");


I guess there's some initialized actions for XmlDataProvider by XAML
intrepreter.
But I can't find the mappings code or what should I write to let the
XmlDataProvider works.

Thank you for reading

BR,

HolaMan


My System SpecsSystem Spec
Old 07-31-2006   #2 (permalink)
=?Utf-8?B?Sm9zaCBTbWl0aA==?=


 
 

RE: XmlDataProvider Problem : How to initialize to load XML Data

In what method are you accessing the XmlDataProvider? If you're accessing it
in the Window/Page's constructor, then the data might not be loaded yet -
you're better off accessing it in a Loaded event handler.

"HolaMan" wrote:

> Hi~~~
>
> I look up many samples about XmlDataProvider.
> But I found a problem.
>
> If I add a XmlDataProvider in XML and want to C# code to access it. It
> doesn't work.
> But if I add a control or menu and assign this XmlDataProvider to its
> DataContext.
> Then the code works.
>
> <!-- Sample XML -->
> <XmlDataProvider x:Key="menuData">
> <x:XData>
> <Items xmlns="">
> <Item Title="Foo..." GroupName="First Group">
> <Item Title="A"/>
> <Item Title="B"/>
> <Item Title="C"/>
> </Item>
> <Item Title="Crimp" GroupName="Another Group" />
> <Item Title="Splange" GroupName="Another Group" />
> <Item Title="Frobnicate..." GroupName="Another One" />
> <Item Title="Do stuff" GroupName="First Group" />
> <Item Title="Mangle" GroupName="First Group" />
> </Items>
> </x:XData>
> </XmlDataProvider>
> ....
> <Menu DataContext="{StaticResource menuData}"/> <!-- if i remove this
> line, then code doesn't work -->
>
>
>
> // Code
> XmlDataProvider xdp = FindResource("menuData") as XmlDataProvider;
> if( xdp.Data == null )
> MessageBox.Show("Data is not loaded");
>
>
> I guess there's some initialized actions for XmlDataProvider by XAML
> intrepreter.
> But I can't find the mappings code or what should I write to let the
> XmlDataProvider works.
>
> Thank you for reading
>
> BR,
>
> HolaMan
>
>

My System SpecsSystem Spec
Old 08-01-2006   #3 (permalink)
HolaMan


 
 

Re: XmlDataProvider Problem : How to initialize to load XML Data

Hi Josh

Thanks for your reply.
I know that all initilization of XAML will be completed after Loaded.
But the key point it that if the XmlDataProvider doesn't link to any
DataContext or Controls at XAMLs, the XmlDataProvider will not be
initlized.

So my question is if I want to use code to initilize, what should I do?

Thanks :-D

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
BT Auto Backup problem with 'Initialize' on Vista Home Premium Vista General
Initialize Junk Mail Filtering and MSOE.DLL could not initialize Vista mail
Can I load saved (tib) data via Acronis from XP PRO? Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46