locked
XML Databinding to Menu and TreeView (Agave) - 12/3/2007 4:24 PM PST RRS feed

  • Question

  • By: Agave


    I have looked in many books and read a lot of articles and blogs, but still 
    can't figure out how to create a Menu and Navigation Tree using the following 
    XML. I'm under the impression that I can do the whole thing using XAML 
    declarations and not need any code-behind (except for the event handling).
    
    TIA for any help.
    
    
    <elements>
    	<MainMenu>
    		<!-- All Menus have submenus; not all items have icons -->
    		<Menu sID="mmFile">
    			<header>_File</header>
    			<tooltip>The items under here allow you to work with files and the 
    console</tooltip>
    			<icon>ui\images\mmFileNew.ico</icon>
    			<!-- DO NOT Change any of these Child Nodes -->
    			<sOnclick></sOnclick>
    			<SubMenu sID="mmFileOpen">
    				<header>_Open</header>
    				<tooltip>Displays an Open File dialog box where you choose the file to 
    work with</tooltip>
    				<icon>ui\images\mmFileOpen.ico</icon>
    				<!-- DO NOT Change any of these Child Nodes -->
    				<sOnclick>menuFileOpen()</sOnclick>
    			</SubMenu>
    			...
    		</Menu>
    		...
    	</MainMenu>
    	<NavigationPane>
    		<Heading>Configurable Options</Heading>
    
    		<!-- All Roots have Parents; not all Parents have Children; not all items 
    have icons -->
    
    		<Root sID="navRecpConfig">
    			<header>Recipient Configurations</header>
    			<tooltip>The items under here display information about the users, 
    devices, and client components</tooltip>
    			<icon>ui\images\users.ico</icon>
    			<!-- DO NOT Change any of these Child Nodes -->
    			<sOnclick>navShowRecps()</sOnclick>
    			<sOnRclick>navRecpCtxMenu()</sOnRclick>
    			<Parent sID="navRecpDevs">
    				<header>Device Platforms</header>
    				<tooltip>Display or configure devices in the Work Area Grid</tooltip>
    				<icon></icon>
    				<!-- DO NOT Change any of these Child Nodes -->
    				<sOnclick>navShowRecpDevs()</sOnclick>
    				<sOnRclick>navRecpDevsCtxMenu()</sOnRclick>
    				<Child sID="navRecpDevX86">
    					<header>x86</header>
    					<tooltip>Display or configure x86 devices in the Work Area Grid</tooltip>
    					<icon></icon>
    					<!-- DO NOT Change any of these Child Nodes -->
    					<sOnclick>navShowRecpDevX86()</sOnclick>
    					<sOnRclick>navRecpDevX86CtxMenu()</sOnRclick>
    				</Child>
    				...
    			</Parent>
    			...
    		</Root>
    		...
    	</NavigationPane>
    </elements>
    -- 
    TIA, Agave
    Thursday, February 21, 2008 8:52 PM

All replies

  • By: Agave

    I've tried the declarations below, as well as other permutations and none 
    seem to work.
    
    Some help, please.
    -- 
    TIA, Agave
    
    <Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2006"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        x:Class="scraps.test"
        Title="test" Height="300" Width="300">
        <Window.Resources>
            <XmlDataProvider
                x:Key="DSelementsXML"
                d:IsDataSource="True"
                Source="ui\en-US\en-US.xml"
                XPath="/elements" />
    
            <HierarchicalDataTemplate DataType="Root" ItemsSource="{Binding 
    XPath=Parent}" >
    			 		<TextBlock Text="{Binding XPath=header}" />
            </HierarchicalDataTemplate>
    
            <HierarchicalDataTemplate DataType="Parent" ItemsSource="{Binding 
    XPath=Child}" >
                <TextBlock Text="{Binding XPath=header}" />
            </HierarchicalDataTemplate>
    				
            <HierarchicalDataTemplate DataType="Child" >
                <TextBlock Text="{Binding XPath=header}" />
            </HierarchicalDataTemplate>
    
    				
            </Window.Resources>
    	<Grid>
    		<TreeView x:Name="NavConfig" Margin="5"
    			ItemsSource="{Binding Mode=Default, Source={StaticResource 
    DSelementsXML}, XPath=/elements/NavigationPane}"	
    			/>
    	</Grid>
    </Window>
    
    
    "Agave" wrote:
    
    > I have looked in many books and read a lot of articles and blogs, but still 
    > can't figure out how to create a Menu and Navigation Tree using the following 
    > XML. I'm under the impression that I can do the whole thing using XAML 
    > declarations and not need any code-behind (except for the event handling).
    > 
    > TIA for any help.
    > 
    > 
    > <elements>
    > 	<MainMenu>
    > 		<!-- All Menus have submenus; not all items have icons -->
    > 		<Menu sID="mmFile">
    > 			<header>_File</header>
    > 			<tooltip>The items under here allow you to work with files and the 
    > console</tooltip>
    > 			<icon>ui\images\mmFileNew.ico</icon>
    > 			<!-- DO NOT Change any of these Child Nodes -->
    > 			<sOnclick></sOnclick>
    > 			<SubMenu sID="mmFileOpen">
    > 				<header>_Open</header>
    > 				<tooltip>Displays an Open File dialog box where you choose the file to 
    > work with</tooltip>
    > 				<icon>ui\images\mmFileOpen.ico</icon>
    > 				<!-- DO NOT Change any of these Child Nodes -->
    > 				<sOnclick>menuFileOpen()</sOnclick>
    > 			</SubMenu>
    > 			...
    > 		</Menu>
    > 		...
    > 	</MainMenu>
    > 	<NavigationPane>
    > 		<Heading>Configurable Options</Heading>
    > 
    > 		<!-- All Roots have Parents; not all Parents have Children; not all items 
    > have icons -->
    > 
    > 		<Root sID="navRecpConfig">
    > 			<header>Recipient Configurations</header>
    > 			<tooltip>The items under here display information about the users, 
    > devices, and client components</tooltip>
    > 			<icon>ui\images\users.ico</icon>
    > 			<!-- DO NOT Change any of these Child Nodes -->
    > 			<sOnclick>navShowRecps()</sOnclick>
    > 			<sOnRclick>navRecpCtxMenu()</sOnRclick>
    > 			<Parent sID="navRecpDevs">
    > 				<header>Device Platforms</header>
    > 				<tooltip>Display or configure devices in the Work Area Grid</tooltip>
    > 				<icon></icon>
    > 				<!-- DO NOT Change any of these Child Nodes -->
    > 				<sOnclick>navShowRecpDevs()</sOnclick>
    > 				<sOnRclick>navRecpDevsCtxMenu()</sOnRclick>
    > 				<Child sID="navRecpDevX86">
    > 					<header>x86</header>
    > 					<tooltip>Display or configure x86 devices in the Work Area Grid</tooltip>
    > 					<icon></icon>
    > 					<!-- DO NOT Change any of these Child Nodes -->
    > 					<sOnclick>navShowRecpDevX86()</sOnclick>
    > 					<sOnRclick>navRecpDevX86CtxMenu()</sOnRclick>
    > 				</Child>
    > 				...
    > 			</Parent>
    > 			...
    > 		</Root>
    > 		...
    > 	</NavigationPane>
    > </elements>
    > -- 
    > TIA, Agave
    Friday, February 22, 2008 8:29 PM
  • Hey Microsoft.

    This seems like a good tutorial as many of us are having the same issue! These seems like a basic function and the help in Blend 2.5 does not even talk about the treeview control and how to use it.

    Scott Peal
    Chief IT Architect
    Sunday, March 16, 2008 1:58 PM