MenuBar and ToolBar : Menu « Windows Presentation Foundation « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Windows Presentation Foundation » MenuScreenshots 
MenuBar and ToolBar
MenuBar and ToolBar
     

<Window x:Class="Commands.TwoDocument"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TwoDocument" Height="300" Width="300">

  <Window.Resources>
    <CommandBinding x:Key="binding" Command="ApplicationCommands.Save" Executed="SaveCommand" CanExecute="SaveCommand_CanExecute" />
  </Window.Resources>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <Menu Grid.Row="0">
      <MenuItem Header="File">
        <MenuItem Command="New"></MenuItem>
        <MenuItem Command="Open"></MenuItem>
        <MenuItem Command="Save"></MenuItem>
        <MenuItem Command="SaveAs"></MenuItem>
        <Separator></Separator>
        <MenuItem Command="Close"></MenuItem>
      </MenuItem>
    </Menu>

    <ToolBarTray Grid.Row="1">
      <ToolBar>
        <Button Command="New">New</Button>
        <Button Command="Open">Open</Button>
        <Button Command="Save">Save</Button>
      </ToolBar>
      <ToolBar>
        <Button Command="Cut">Cut</Button>
        <Button Command="Copy">Copy</Button>
        <Button Command="Paste">Paste</Button>
      </ToolBar>
    </ToolBarTray>
    <TextBox Margin="5" Grid.Row="2" TextWrapping="Wrap" AcceptsReturn="True" TextChanged="txt_TextChanged">
      <TextBox.CommandBindings>
        <StaticResource ResourceKey="binding"></StaticResource>
      </TextBox.CommandBindings>
      
    </TextBox>
    <TextBox Margin="5" Grid.Row="3" TextWrapping="Wrap" AcceptsReturn="True" TextChanged="txt_TextChanged">
      <TextBox.CommandBindings>
        <StaticResource ResourceKey="binding"></StaticResource>

        <CommandBinding Command="ApplicationCommands.Save"
          Executed="SaveCommand" />
      </TextBox.CommandBindings>
    </TextBox>
  </Grid>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Shapes

Namespace Commands
  Public Partial Class TwoDocument
    Inherits System.Windows.Window
    Public Sub New()
    End Sub

    Private Sub SaveCommand(sender As Object, e As ExecutedRoutedEventArgs)
      Console.WriteLine("SaveCommand")
    End Sub
    Private Sub txt_TextChanged(sender As Object, e As RoutedEventArgs)
      Console.WriteLine("text changed")
    End Sub
    Private Sub SaveCommand_CanExecute(sender As Object, e As CanExecuteRoutedEventArgs)
      e.CanExecute = False
    End Sub
  End Class
End Namespace

   
    
    
    
    
  
Related examples in the same category
1.Mixed MenusMixed Menus
2.Sidebar MenuSidebar Menu
3.Put a Menu and toolbar on the top of a DockPanelPut a Menu and toolbar on the top of a DockPanel
4.Nesting content inside MenuItem.HeaderNesting content inside MenuItem.Header
5.Multiple command targetsMultiple command targets
6.Commands with a menu and text boxCommands with a menu and text box
7.Set Access key for Menu with underscoreSet Access key for Menu with underscore
8.Menu and MenuItemMenu and MenuItem
9.MenuItem Commands And EventsMenuItem Commands And Events
10.Display a Context Menu with OpacityDisplay a Context Menu with Opacity
11.Add Menu to NavigationWindow ContentAdd Menu to NavigationWindow Content
12.Menu item action handlerMenu item action handler
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.