Windows Vista Forums

XmlDataProvider Problem : How to initialize to load XML Data

  1. #1


    HolaMan Guest

    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

  2. #2


    =?Utf-8?B?Sm9zaCBTbWl0aA==?= Guest

    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

  3. #3


    HolaMan Guest

    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

XmlDataProvider Problem : How to initialize to load XML Data

Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance Monitor Problem MCC could not initialize the snap in jublee Vista performance & maintenance 0 26 Sep 2009
Initialize Junk Mail Filtering and MSOE.DLL could not initialize RainbowKid Vista mail 13 05 Mar 2008
Can I load saved (tib) data via Acronis from XP PRO? srt Vista installation & setup 7 29 Jun 2007
Help! XmlDataProvider 'cannot locate resource' Larry Andersen Avalon 2 12 Dec 2006
How to trigger XmlDataProvider to load data viRtual Avalon 0 26 Jul 2006