locked
wpf menu itemsource from dataset RRS feed

  • Question

  • Hi

    In my application i have a menu control,where i want to set the itemsource of that menu control through dataset

    pls clear provide me code help regarding this


    karthik

    Monday, May 14, 2012 6:12 AM

Answers

  • You have to define Hierarchical DataTemplate for menu. It would be something like this

    <Menu.ItemTemplate>
    	<HierarchicalDataTemplate ItemsSource="{Binding Path=Cities}">
    		<TextBlock Margin="1" Text="{Binding Name}"/>           
    		<HierarchicalDataTemplate.ItemTemplate>
    			<DataTemplate>
    				<TextBlock Margin="1" Text="{Binding Name}"/>
    			</DataTemplate>                        
    		</HierarchicalDataTemplate.ItemTemplate>
    	</HierarchicalDataTemplate>       
    </Menu.ItemTemplate>

    Then you just have to set the ItemSource property of menu to your hierarchical data. You can see the complete example here.

    http://zamjad.wordpress.com/2009/12/18/using-hierarchical-data-template-with-menu-item/

    Regards

    Zeeshan Amjad

    http://zamjad.wordpress.com/


    http://zamjad.wordpress.com

    • Marked as answer by Annabella Luo Thursday, May 24, 2012 5:22 AM
    Monday, May 14, 2012 10:29 PM