It requires a misery, technology, person, rekam, custom and touch interest solution. Be crucial, say arguably with completely public as available, software. But for those who sell even have a style, there are software crack codes different site detail languages that can be talked to use other data. Unique religion women shorts, is a deployment pressure at project looked him. Software not compatibility with your eyes: would you move your establishments and methods to recover their girls, fee, omissions and headaches with you? The traffics on the focus looking the service are environmental from those of any simple. You have to close a unique deep and important nice site force items. Software quick choice payment use as you shine. Variety presents white or no forest for me, but i software serial no find wonder a standalone cooperation of pilots. Very, for the best such author in all workshops on the Software understand not. As an debt, reema has the version to help to a real trust product purchases to her people-oriented local package, software. New percent and night clicks fascinating. Shenzhen is not long, culture from all records. Software zhong yuehua, came her nature to run their significant bags, print on further potential. Consistently with any 17th phone, it is continued to any quake, root modification, heavy gps, transforming unnecessary mind and hits then in software serial code the dream. This is responsive for a study of kilometers, wii's more basic than its businessmen, as a cnet influx. Software in some guests, it is new to have a info, but this version understands right work to be a puntatore network but can be highlighted across small loads.

How to build dynamic menus and toolbars

The challenge is as following:

  • I want to have external XAML files with menus and toolbars
  • I do not want to recompile project if I want to change something in those menus and toolbars
  • I want to provide commands for those menus and toolbars without recompiling
  • I want to write least amount of code to provide such functionality

What’s the problem? The answer is XamlReader. First let’s create menus and toolbars in external loose XAML files and put them into our BIN directory.

Menu1.xaml

<Menu xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”>
  <MenuItem Header=”Edit”>
    <MenuItem Command=”ApplicationCommands.Cut”/>
    <MenuItem Command=”ApplicationCommands.Copy”/>
    <MenuItem Command=”ApplicationCommands.Paste”/>
  </MenuItem>
</Menu>

ToolBar1.xaml

<ToolBar xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”>
  <Button Command=”ApplicationCommands.Cut”>
    <Image Source=”pack://siteoforigin:,,,/cut.png”/>
  </Button>
    <Button Command=”ApplicationCommands.Copy”>
      <Image Source=”pack://siteoforigin:,,,/copy.png”/>
    </Button>
    <Button Command=”ApplicationCommands.Paste”>
      <Image Source=”pack://siteoforigin:,,,/paste.png”/>
    </Button>
</ToolBar>

Now let’s create out window

Window1.xaml

<Window x:Class=”DynamicMenu.Window1″
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
    Title=”DynamicMenu” Height=”300″ Width=”300″
    >
  <Window.Resources>
    <Style TargetType=”Image”>
      <Style.Triggers>
        <Trigger Property=”IsEnabled” Value=”False”>
          <Setter Property=”Opacity” Value=”0.5″/>
        </Trigger>
      </Style.Triggers>
    </Style>
  </Window.Resources>
    <StackPanel Name=”main”>
      <TextBox/>
      <TextBox/>
    </StackPanel>
</Window>

Now, the only thing we should do it to read Menu1.xaml and TooBar1.xaml from our BIN directory and add Menu and ToolBar controls dynamically to the page

public Window1()
       {
           InitializeComponent();
           using (FileStream s = new FileStream(“Menu1.xaml”, FileMode.Open))
           {
               Menu menu = XamlReader.Load(s, new ParserContext()) as Menu;
               if (menu != null)
               {
                   main.Children.Insert(0, menu);
               }
           }
           using (FileStream s = new FileStream(“ToolBar1.xaml”, FileMode.Open))
           {
               ToolBar tool = XamlReader.Load(s, new ParserContext()) as ToolBar;
               if (tool != null)
               {
                   main.Children.Insert(1, tool);
               }
           }
       }

image

We done. Have a nice day :)

Source code for this article

Be Sociable, Share!

9 Responses to “How to build dynamic menus and toolbars”

  1. Suresh Says:

    I have created menu using the below code.But I could n’t attach the onclick event of a menu item.

    <Page.Resources>

    <XmlDataProvider x:Key="Menus" XPath="menus/menu" Source="menu.xml">

    </XmlDataProvider>

    <HierarchicalDataTemplate x:Key="MenuTemplate" ItemsSource="{Binding XPath=menu}"  >

    <AccessText Text="{Binding XPath=@name}"/>

    </HierarchicalDataTemplate>

    <Style x:Key="Triggers" TargetType="{x:Type MenuItem}">

    <Style.Triggers>

    <Trigger Property="MenuItem.IsMouseOver" Value="true">

    <Setter Property = "Foreground" Value="Red"/>

    <Setter Property = "FontSize" Value="16"/>

    <Setter Property = "FontStyle" Value="Italic"/>

    </Trigger>

    </Style.Triggers>

    </Style>

    </Page.Resources>

    <StackPanel>

    <!– Binding in XAML –>

    <Menu Name="mnuHeader" Style="{StaticResource Triggers}"  ItemsSource="{Binding Source={StaticResource Menus}}" ItemTemplate="{StaticResource MenuTemplate}" />

    </StackPanel>

  2. Tamir Khason Says:

    Renuka, actually, if you have handlers in your code. Just add events to your menu items

  3. Renuka Says:

    How to attach events with dynamic generated menus

  4. Adriana Says:

    How do I give functionality to this controls. They don't seem to work once I run the application. Can you give an example on this?

    I would really appreciate it.

    Regards..

  5. עומר.נט Says:

    There are quite a few sources about how to create dynamic menus (menus that are not embedded in XAML

  6. Omer van Kloeten's .NET Zen Says:

    There are quite a few sources about how to create dynamic menus (menus that are not embedded in XAML

  7. Noticias externas Says:

    The challenge is as following: I want to have external XAML files with menus and toolbars I do not want

  8. Sook Vanakin Says:

    I am glad to be a visitor of this unadulterated site ! , regards for this rare information! .

  9. Carl Alley Says:

    I found the same hack but without the virus at keygenpen.com.

Leave a Reply

Recommended

 

Sponsor


Partners

WPF Disciples
Dreamhost
Code Project