![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| 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 | |||