Menu icon appears in design mode but not in debug mode:
<Menu IsMainMenu="True" DockPanel.Dock="Top">
<MenuItem Header="_Application">
<MenuItem Header="_MasterData" Click="btnMasterData_Click">
<MenuItem.Icon>
<Image Source="database.png" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
Related
Just look at images you will understand
When I starts program first view=>Click
When maximize its form its view=>Click
I am very new to WPF and I don't know how to fix this problem this is my code:
<Window x:Class="WpfApplication3.MainWindow"
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/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication3"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Menu Margin="0,0,0,285">
<MenuItem Header="File" Name="meFile"></MenuItem>
<MenuItem Header="Edit" Name="meEdit"></MenuItem>
<MenuItem Header="View" Name="meView"></MenuItem>
<MenuItem Header="Project" Name="meProject"></MenuItem>
<MenuItem Header="Build" Name="meBuild"></MenuItem>
<MenuItem Header="Debug" Name="meDebug"></MenuItem>
<MenuItem Header="Team" Name="meTeam"></MenuItem>
</Menu>
</Grid>
</Window>
Remove Margin altogether and use VerticalAlignment="Top" to make it work with Grid.
Don't use Grid, DockPanel is the way to go. Eg;
<DockPanel LastChildFill="False">
<Menu DockPanel.Dock="Top">
<MenuItem Header="File" Name="meFile"></MenuItem>
<MenuItem Header="Edit" Name="meEdit"></MenuItem>
<MenuItem Header="View" Name="meView"></MenuItem>
<MenuItem Header="Project" Name="meProject"></MenuItem>
<MenuItem Header="Build" Name="meBuild"></MenuItem>
<MenuItem Header="Debug" Name="meDebug"></MenuItem>
<MenuItem Header="Team" Name="meTeam"></MenuItem>
</Menu>
</DockPanel>
You might need to set Height if you won't set LastChildFill = False.
You can try DockPanel as below..
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="File" Name="meFile"></MenuItem>
<MenuItem Header="Edit" Name="meEdit"></MenuItem>
<MenuItem Header="View" Name="meView"></MenuItem>
<MenuItem Header="Project" Name="meProject"></MenuItem>
<MenuItem Header="Build" Name="meBuild"></MenuItem>
<MenuItem Header="Debug" Name="meDebug"></MenuItem>
<MenuItem Header="Team" Name="meTeam"></MenuItem>
</Menu>
<StackPanel></StackPanel>
You can refer here as well.
I have the following piece of code (XAML C#):
<Menu IsMainMenu="True" DockPanel.Dock="Top">
<MenuItem Name="fileMenu" Header="_File" />
<MenuItem Name="editMenu" Header="_Edit" />
<MenuItem Name="setupMenu" Header="_Setup">
<MenuItem Header="_Language">
<MenuItem.Icon>
//I want to insert image here
</MenuItem.Icon>
</MenuItem>
</MenuItem>
<MenuItem Name="helpMenu" Header="_Help" />
</Menu>
And a resource file named images.resx containing an image called lang.png.
How can I insert the image as an icon for the Menu-Item?
Is there a better way?
As Jason said, it's better to add your images as Resources to your project.
Open "Properties" for your project
Select Vertical-tab Resources
Choose Images from the left ComboBox
Choose "Add Resource -> Add Existing File..." from the right ComboBox
Locate the Image you would like to use, e.g "C1.png" (it will automatically be copied to the Resources folder in the root of your project)
Select properties on your newly added Resource Image
In properties, set Build Action to Resource
Open the designer for the .xaml file containing the Menu and add an Image in MenuItem.Icon and then place the cursor on Image.
xaml
<Menu IsMainMenu="True" DockPanel.Dock="Top">
<MenuItem Name="fileMenu" Header="_File" />
<MenuItem Name="editMenu" Header="_Edit" />
<MenuItem Name="setupMenu" Header="_Setup">
<MenuItem Header="_Language">
<MenuItem.Icon>
<Image/>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
<MenuItem Name="helpMenu" Header="_Help" />
</Menu>
From properties you can now select the symbol on the Source Property and all available Image resources will be displayed.
From this dialog you can also choose "Add", locate an image file on the disk and all the above steps will be made for you by Visual Studio.
The resulting uri for the Image.Source in xaml will look something like this (which ofcourse also can be added by hand)
<Menu IsMainMenu="True" DockPanel.Dock="Top">
<MenuItem Name="fileMenu" Header="_File" />
<MenuItem Name="editMenu" Header="_Edit" />
<MenuItem Name="setupMenu" Header="_Setup">
<MenuItem Header="_Language">
<MenuItem.Icon>
<Image Source="/MenuIconImage;component/Resources/C1.png" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
<MenuItem Name="helpMenu" Header="_Help" />
</Menu>
You could add this, to the Menu.Icon.
<Image>
<Image.Source>
<BitmapImage UriSource="/ASSEMBLYNAME;component/PATH/IMAGE.png" />
</Image.Source>
<Image>
Currently, I have a context menu with submenus containing checkboxes. I have implemented it in a manner similar to below:
<ContextMenu>
<MenuItem Header="Submenu1">
<MenuItem Header="item1.1" IsTabStop="False">
<CheckBox Content="item1.1 checkbox"/>
</MenuItem>
<MenuItem Header="item1.2" IsTabStop="False">
<CheckBox Content="item1.2 checkbox"/>
</MenuItem>
<MenuItem Header="item1.3" IsTabStop="False">
<CheckBox Content="item1.3 checkbox"/>
</MenuItem>
</MenuItem>
<MenuItem Header="Submenu2">
<MenuItem Header="item2.1" IsTabStop="False">
<CheckBox Content="item2.1 checkbox"/>
</MenuItem>
<MenuItem Header="item2.2" IsTabStop="False">
<CheckBox Content="item2.2 checkbox"/>
</MenuItem>
<MenuItem Header="item2.3" IsTabStop="False">
<CheckBox Content="item2.3 checkbox"/>
</MenuItem>
</MenuItem>
</ContextMenu>
I have set the IsTabStop property of each MenuItem to false to fix an earlier bug I found wherein the focus gets stuck on a single menu item (when TAB key is used). However, what happens now is when Submenu1 is open and I try to move focus through the different menu items using the Up or Down arrow key, the submenu closes immediately and highlights the Submenu2 item in the context menu.
I would like to be able to use TAB or arrow keys in moving the focus through the menu items in each submenu. Thank you in advanced for the help.
I'm posting here on SOF because I'm getting frustrated in C# WPF. :(
I don't know how to make an event handler in menustrip of WPF.
I know in ordinary win form and in VB.NET and in Buttons of WPF, JUST BY double clicking the controls (UI) I will be directed instantly in auto generated event handler.
In a menu strip of C#, when I assigned both Name and Click (click="button2Click") and then double click the menu tool or whatever you call that, I am being directed to the event handler of the HEADER of menustriptool.
Under "FILE" is "exit" menu. When I assigned click and name in that "exit" and then double click it, the focus will be in the "FILE".
XAML code:
<MenuItem Header="_FILE" >
<MenuItem Header="_Open | View">
<MenuItem.Icon>
<Image Source="Picture/open.png" />
</MenuItem.Icon>
<MenuItem Header="_Connection String">
</MenuItem>
</MenuItem>
<MenuItem Header="_Exit" Click="exitMenu_click">
<MenuItem.Icon>
<Image Source="Picture/close1.png" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
Just add command in MenuItem and write handler for it. Simple.
<MenuItem Header="_FILE" >
<MenuItem Header="_Open | View" Command=OpenCommand>
<MenuItem.Icon>
<Image Source="Picture/open.png" />
</MenuItem.Icon>
<MenuItem Header="_Connection String">
</MenuItem>
</MenuItem>
I create user interface in WPF. I have one problem with menu i used DockPanel for it, all works good but there is one problem when i click MaximizeButton DockPanel size don't change like in this pic.
http://xmages.net/i/3405572
Code:
<Grid >
<DockPanel Background="LightBlue">
<Menu Height="23" Name="menu1" DockPanel.Dock="Top">
<MenuItem Header="File" Name="File_Menu"></MenuItem>
<MenuItem Header="Tasks" Name="Tasks_Menu"></MenuItem>
<MenuItem Header="View" Name="View_Menu"></MenuItem>
<MenuItem Header="HandBook" Name="HandBook_Menu"></MenuItem>
<MenuItem Header="Email" Name="Email_Menu"></MenuItem>
<MenuItem Header="Tools" Name="Tools_Menu"></MenuItem>
<MenuItem Header="Options" Name="Options_Menu"></MenuItem>
<MenuItem Header="Help" Name="Help_Menu"></MenuItem>
</Menu>
.........
I imagine its due to the container of the DockPanel the grid, or the way the Dockpanel is set in this grid.