How to resize the icon of the menu and menuitems in WPF C#
I have done following
<DockPanel>
<Menu Background="CadetBlue" Height="53" Width="500" IsMainMenu="True" DockPanel.Dock="Top" VerticalAlignment="Top">
<MenuItem Padding="40,0,0,0" Header="File" Foreground="#FF383131" FontSize="20" Background="Beige" Width="100" Height="50" >
<MenuItem.Icon>
<Image Source="/WPFMenuItem;component/Images/garden.jpg" Stretch="Uniform"/>
</MenuItem.Icon>
<MenuItem Header="New" FontSize="20">
<MenuItem.Icon>
<Image Source="/WPFMenuItem;component/Images/garden.jpg" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Exit" FontSize="20">
<MenuItem.Icon>
<Image Source="/WPFMenuItem;component/Images/ic_launch_man.png" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
<TextBox />
</DockPanel>
I have increased width,height and margin but did not work?
Try using a render transform and set the X and Y scale.
http://msdn.microsoft.com/en-us/library/ms750596(v=vs.110).aspx
<Image Source="/WPFMenuItem;component/Images/garden.jpg" Stretch="Uniform" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform X="2" Y="3.7"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
Related
I'm developing a menu bar using only Controls:Tiles with the attribute ContextMenu which only let me open it clicking on right mouse button. After some search I made it clickable with left mouse button but the behaviour is different: When I press right click ContextMenu opens and all MenuItems are clickable. When I press left click ContextMenu opens but all MenuItems looks disabled and I can't click on them.
My code is here:
<Controls:Tile x:Name="FileTile" Width="Auto" Height="30" TitleFontSize="10" HorizontalContentAlignment="Left"
VerticalAlignment="Top" VerticalContentAlignment="Top" Background="White" HorizontalTitleAlignment="Right"
Foreground="Gray" ContextMenuService.IsEnabled="True">
<Controls:Tile.Content>
<StackPanel Orientation="Horizontal" Height="Auto">
<Image Source="/images/topbaricons/files.png" Width="22" Height="22" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Text="{x:Static p:Resources.File}" VerticalAlignment="Center" Margin="5,0,5,0" />
</StackPanel>
</Controls:Tile.Content>
<Controls:Tile.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<EventTrigger RoutedEvent="Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="ContextMenu.IsOpen" FillBehavior="HoldEnd">
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</Controls:Tile.Style>
<Controls:Tile.ContextMenu>
<ContextMenu x:Name="File_ContextMenu" >
<MenuItem Header="{x:Static p:Resources.Menu_item_New}" Command="ApplicationCommands.New" IsEnabled="true">
<MenuItem.Icon>
<Image Source="/images/topbaricons/new_file.png" Height="22" Width="22" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{x:Static p:Resources.Menu_item_Open}" Command="ApplicationCommands.Open" IsEnabled="true">
<MenuItem.Icon>
<Image Source="/images/topbaricons/open_file.png" Height="22" Width="22" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{x:Static p:Resources.Menu_item_Save}" x:Name="MenuItemSave" Command="ApplicationCommands.Save" IsEnabled="False">
<MenuItem.Icon>
<Image Source="/images/topbaricons/save.png" Height="22" Width="22" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="ApplicationCommands.SaveAs" Visibility="Visible" >
<MenuItem.Icon>
<Image Source="/images/topbaricons/save_as.png" Height="22" Width="22" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{x:Static p:Resources.Menu_item_Exit}" Command="ApplicationCommands.Close" IsEnabled="true">
<MenuItem.Icon>
<Image Source="/images/topbaricons/off.png" Height="22" Width="22" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Controls:Tile.ContextMenu>
</Controls:Tile>
To show exactly the difference I've been talking about on this post there's this image:
Can someone help me? I really wanna do with left click the same I can do with right click.
Thanks.
I suppose that the CanExecute for the commands will be handled somewhere(maybe element currently focused has own implementation). Pasting
<ContextMenu.CommandBindings>
<CommandBinding Command="ApplicationCommands.Open" CanExecute="CommandBinding_CanExecute" />
<CommandBinding Command="ApplicationCommands.New" CanExecute="CommandBinding_CanExecute"/>
<CommandBinding Command="ApplicationCommands.Save" CanExecute="CommandBinding_CanExecute"/>
<CommandBinding Command="ApplicationCommands.SaveAs" CanExecute="CommandBinding_CanExecute"/>
<CommandBinding Command="ApplicationCommands.Close" CanExecute="CommandBinding_CanExecute"/>
</ContextMenu.CommandBindings>
and
private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
//e.Handled = true;
}
should do the trick.
I have a Menu in my app, that consists of few MenuItems. I'd like a vertical label on the left side of all the MenuItems. Like this (of course with grey background, pardon my paint skill):
I've tried it this way:
<Menu IsMainMenu="True" Grid.Row="0" Grid.ColumnSpan="3">
<MenuItem Header="_File">
<TextBlock Text="Type1" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,0">
<TextBlock.LayoutTransform>
<RotateTransform Angle="-90"/>
</TextBlock.LayoutTransform>
</TextBlock>
<MenuItem Header="_Open" Command="{Binding OpenFileCommand}" IsEnabled="{Binding CanOpenFile}"/>
<Separator/>
<MenuItem Header="_Save" Command="{Binding SaveFileCommand}"/>
<MenuItem Header="_Save As" Command="{Binding SaveAsFileCommand}"/>
<Separator/>
<MenuItem Header="_Exit" Command="{Binding ExitAppCommand}"/>
</MenuItem>
</Menu>
But it produces an output like this:
Then I tried it via background image (transparent with just a plain text):
<Menu IsMainMenu="True" Grid.Row="0" Grid.ColumnSpan="3">
<MenuItem Header="_File">
<MenuItem.Background>
<ImageBrush ImageSource="{Binding SelectedObjectResourcePath}"/>
</MenuItem.Background>
<MenuItem Header="_Open" Command="{Binding OpenFileCommand}" IsEnabled="{Binding CanOpenFile}"/>
<Separator/>
<MenuItem Header="_Save" Command="{Binding SaveFileCommand}"/>
<MenuItem Header="_Save As" Command="{Binding SaveAsFileCommand}"/>
<Separator/>
<MenuItem Header="_Exit" Command="{Binding ExitAppCommand}"/>
</MenuItem>
</Menu>
But it sets the background for the first menuItem only:
Using StackPanel (with horizontal orientation) here is the best solution in my opinion. Check this out. You just need to make it look as good as you want :)
<Menu IsMainMenu="True" Grid.Row="0">
<MenuItem Header="_File">
<StackPanel Orientation="Horizontal">
<Label Content="Type1" Margin="-30" HorizontalContentAlignment="Center">
<Label.LayoutTransform>
<RotateTransform Angle="-90"/>
</Label.LayoutTransform>
</Label>
<StackPanel>
<MenuItem Header="_Open" Command="{Binding OpenFileCommand}" IsEnabled="{Binding CanOpenFile}"/>
<Separator/>
<MenuItem Header="_Save" Command="{Binding SaveFileCommand}"/>
<MenuItem Header="_Save As" Command="{Binding SaveAsFileCommand}"/>
<Separator/>
<MenuItem Header="_Exit" Command="{Binding ExitAppCommand}"/>
</StackPanel>
</StackPanel>
</MenuItem>
</Menu>
I do not have an idea of how to make the menu bar, tool bar, and canvas fix their positions. While scrolling they shouldn't move.
I have a WPF window where I have a menu bar and a tool bar and two canvases.
Canvas 1 is in XAML and canvas 2 is dynamic through vb.net
Now I want to fix the first three.
Menu bar
Tool bar
Canvas 1
Here is my XAML:
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" >
<DockPanel>
<Grid ScrollViewer.HorizontalScrollBarVisibility="Visible" >
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="350"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Menu x:Name="menu1" BorderBrush="AliceBlue" VerticalAlignment="Top" FontFamily="Comic Sans MS" >
<MenuItem Header="_File" Width="92" FontSize="16" FontWeight="Normal" FontFamily="Century Gothic" >
<MenuItem Header="Location" FontSize="16">
<MenuItem Header="01" />
<MenuItem Header="02"/>
<MenuItem Header="03"/>
<MenuItem Header="04"/>
<MenuItem Header="05"/>
<MenuItem Header="06"/>
<MenuItem Header="07"/>
<MenuItem Header="08"/>
<MenuItem Header="09"/>
<MenuItem Header="10"/>
<MenuItem Header="11"/>
<MenuItem Header="12"/>
<MenuItem Header="13"/>
<MenuItem Header="14"/>
</MenuItem>
<MenuItem Header="_Print"/>
<MenuItem Header="_Print Preview"/>
<MenuItem Header="_Exit"/>
</MenuItem>
</Menu>
<ToolBar Grid.Row="1" x:Name="toolBar1" BorderBrush="Red" BorderThickness="3" Margin="0,0,0,900" Grid.RowSpan="2" Height="30" VerticalAlignment="Top" >
<Button x:Name="Zoomin" Click="menuItemZoomin_Click" HorizontalAlignment="Left" Margin="1" Width="90" FontSize="16" FontWeight="SemiBold" Height="55" RenderTransformOrigin ="0.917,0.587" IsHitTestVisible="True" IsEnabled="True" FontFamily="Century Gothic" Content="Zoom In" />
<Button x:Name="Zoomout" Click="menuItemZoomout_Click" HorizontalAlignment="Left" Margin="1" Width="90" FontSize="16" FontWeight="SemiBold" RenderTransformOrigin="0.917,0.587" Height="55" FontFamily="Century Gothic" Content="Zoom Out"/>
<Button x:Name="Print" Click="PrintBtn_Click" HorizontalAlignment="Left" Margin="1" Width="90" FontSize="16" FontWeight="SemiBold" RenderTransformOrigin="0.917,0.587" Height="55" FontFamily="Century Gothic" Content="Print"/>
</ToolBar>
<DockPanel>
<Canvas x:Name="cvsZoneColor" DockPanel.Dock="Top" >
<Rectangle Width="25" Height="25" Margin="60 60 60 950" >
<Rectangle.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<Color A="219" R="219" G="249" B="217" />
</SolidColorBrush.Color>
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Text="A" Margin="60 80 60 950" Width="20" Height="20" ></TextBlock>
<Rectangle Width="25" Height="25" Margin="90 60 70 990" >
<Rectangle.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<Color A="219" R="255" G="238" B="204" />
</SolidColorBrush.Color>
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Text="B" Margin="90 80 70 950" Width="20" Height="20" ></TextBlock>
<Rectangle Width="25" Height="25" Margin="120 60 70 990" >
<Rectangle.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<Color A="219" R="204" G="238" B="255" />
</SolidColorBrush.Color>
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Text="C" Margin="120 80 70 950" Width="20" Height="20" ></TextBlock>
<Rectangle Width="25" Height="25" Margin="150 60 70 990" >
<Rectangle.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<Color A="219" R="204" G="238" B="221" />
</SolidColorBrush.Color>
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Text="D" Margin="150 80 70 950" Width="20" Height="20" ></TextBlock>
<Rectangle Width="25" Height="25" Margin="180 60 70 990" >
<Rectangle.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<Color A="219" R="255" G="221" B="238" />
</SolidColorBrush.Color>
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Text="E" Margin="180 80 70 950" Width="20" Height="20" ></TextBlock>
<Rectangle Width="25" Height="25" Margin="210 60 70 990" >
<Rectangle.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<Color A="219" R="255" G="238" B="255" />
</SolidColorBrush.Color>
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Text="F" Margin="210 80 70 950" Width="20" Height="20" ></TextBlock>
</Canvas>
</DockPanel>
<Canvas x:Name="cvsWarehouse" Focusable="True" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" MouseWheel="Canvas_MouseWheel" Grid.Row="3" RenderTransformOrigin="0.5,0.5" Margin="0,150,0,0" >
<Canvas.LayoutTransform>
<TransformGroup>
<ScaleTransform x:Name ="st1" ScaleX="{Binding Value, ElementName=uiScaleSlider}"
ScaleY="{Binding Value, ElementName=uiScaleSlider}" />
<TranslateTransform Y="100" />
</TransformGroup>
</Canvas.LayoutTransform>
</Canvas>
</Grid>
</DockPanel>
</ScrollViewer>
Scrolling the bar on the right hand side shouldn't move these three highlighted ...
Image
While using DockPanel, it's important to keep note of order.
You should use below XAML as your starting point and modify it for your needs :
<Window ...>
<DockPanel LastChildFill="True">
<Menu x:Name="menu1" BorderBrush="AliceBlue" VerticalAlignment="Top" FontFamily="Comic Sans MS" DockPanel.Dock="Top">
<MenuItem Header="_File" Width="92" FontSize="16" FontWeight="Normal" FontFamily="Century Gothic" >
<MenuItem Header="Location" FontSize="16">
<MenuItem Header="01" />
<MenuItem Header="02"/>
<MenuItem Header="03"/>
<MenuItem Header="04"/>
<MenuItem Header="05"/>
<MenuItem Header="06"/>
<MenuItem Header="07"/>
<MenuItem Header="08"/>
<MenuItem Header="09"/>
<MenuItem Header="10"/>
<MenuItem Header="11"/>
<MenuItem Header="12"/>
<MenuItem Header="13"/>
<MenuItem Header="14"/>
</MenuItem>
<MenuItem Header="_Print"/>
<MenuItem Header="_Print Preview"/>
<MenuItem Header="_Exit"/>
</MenuItem>
</Menu>
<ToolBar x:Name="toolBar1" BorderBrush="Red" BorderThickness="3" Height="30" VerticalAlignment="Top" DockPanel.Dock="Top">
<Button x:Name="Zoomin" Click="menuItemZoomin_Click" HorizontalAlignment="Left" Margin="1" Width="90" FontSize="16" FontWeight="SemiBold" Height="55" RenderTransformOrigin ="0.917,0.587" IsHitTestVisible="True" IsEnabled="True" FontFamily="Century Gothic" Content="Zoom In" />
<Button x:Name="Zoomout" Click="menuItemZoomout_Click" HorizontalAlignment="Left" Margin="1" Width="90" FontSize="16" FontWeight="SemiBold" RenderTransformOrigin="0.917,0.587" Height="55" FontFamily="Century Gothic" Content="Zoom Out"/>
<Button x:Name="Print" Click="PrintBtn_Click" HorizontalAlignment="Left" Margin="1" Width="90" FontSize="16" FontWeight="SemiBold" RenderTransformOrigin="0.917,0.587" Height="55" FontFamily="Century Gothic" Content="Print"/>
</ToolBar>
<Canvas Background="Pink" DockPanel.Dock="Bottom" Height="25">
<TextBlock Text="Bottom"/>
</Canvas>
<ScrollViewer>
<Canvas Background="Red" ScrollViewer.VerticalScrollBarVisibility="Visible">
<Button Content="Press"/>
</Canvas>
</ScrollViewer>
</DockPanel>
</Window>
I think this might get you a UI closer to what it looks like you are trying to do. If you make the XAML to use the dock panel more, you can get a more fixed UI.
<DockPanel LastChildFill="True">
<Menu x:Name="menu1" DockPanel.Dock="Top">
<MenuItem Header="_File" >
...
</Menu>
<ToolBar x:Name="toolBar1" DockPanel.Dock="Top">
...
</ToolBar>
<Grid x:Name="cvsZoneColor" DockPanel.Dock="Top">
<StackPanel Orientation="Vertical">
<Rectangle Width="25" Height="25" Margin="60 0 60 0" >
...
</Rectangle>
<TextBlock Text="A" Margin="60 0 60 0" Width="20" Height="20"/>
</StackPanel>
...
</Grid>
<ScrollViewer DockPanel.Dock="Bottom">
<Canvas x:Name="cvsWarehouse">
...
</Canvas>
</ScrollViewer>
</DockPanel>
I'm trying to write for the first time in WPF and I see that I can't manage the icons in the menus.
My Code is that.
<Grid>
<my:RibbonControl Height="49" HorizontalAlignment="Left" Name="RibbonControl1" VerticalAlignment="Top" Width="503" />
<my:Ribbon Name="Ribbon">
<my:RibbonTab Name="Manage" Header="Διαχείριση" KeyTip="m">
<my:RibbonGroup Name="groupadd" Header="Χρήστες">
<my:RibbonSplitButton x:Name="btnUser" LargeImageSource="/Economy;component/Images/users01.png" Width="30" Height="60" TabIndex="1" FontFamily="Palatino Linotype" FontSize="12" FocusedBackground="#FFE2AB7F" LayoutTransform="{Binding}" MaxHeight="120" MaxWidth="80" Margin="1,0,0,1" OverridesDefaultStyle="False" Padding="0" ToolTipFooterTitle="Επιλογή">
<MenuItem Header="Ανάθεση">
<MenuItem.Icon>
<Image Source="/Economy;component/Images/delegation.jpg" Stretch="Fill" Width="20" Height="20"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Διαγραφή">
<MenuItem.Icon>
<Image Source="/Economy;component/Images/deletion.ico" Stretch="Fill" Width="20" Height="20" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Είσοδος">
<MenuItem.Icon>
<Image Source="/Economy;component/Images/login.jpg" Stretch="Fill" Width="20" Height="20"/>
</MenuItem.Icon>
</MenuItem>
<my:RibbonSeparator />
<MenuItem Header="Έξοδος">
<MenuItem.Icon>
<Image Source="/Economy;component/Images/logout.ico" Stretch="Fill" Width="20" Height="20"/>
</MenuItem.Icon>
</MenuItem>
</my:RibbonSplitButton>
</my:RibbonGroup>
</my:RibbonTab>
</my:Ribbon>
</Grid>
this code produces the following
What I need is to have the icons at the most left site of the menu.
I read another question about that... which is
<ribbon:RibbonSplitButton x:Name="SplitButton3DViews"
ItemsSource="{Binding items}"
Label="Views3D"
IsCheckable="False" >
<ribbon:RibbonSplitButton.Resources>
<Style TargetType="{x:Type ribbon:RibbonMenuItem}">
<Setter Property="Header" Value="{Binding Path=Name}" />
<Setter Property="Command" Value="{Binding Path=cmd}" />
<Setter Property="ImageSource" Value="{Binding Icon}" />
</Style>
</ribbon:RibbonSplitButton.Resources>
</ribbon:RibbonSplitButton>
But it is not working with my page...
Is there some one to assist me on this?
First of all, please state which ribbon control library you are using, as <my:Ribbon> is not part of the built-in .NET framework.
Secondly, I think that <MenuItem> is the wrong element to use inside your ribbon control.
According to this webpage:
http://www.renevo.com/blogs/dotnet/archive/2009/02/10/your-first-wpf-ribbon-application.aspx
a RibbonApplicationMenuItem should be used instead, no mention of MenuItem anywhere. You might not be using the same ribbon control as shown in the webpage, but I'm guessing that your ribbon control requires another element instead of Menuitem.
I need to have an image instead of text in my menu header. I have written a code but its not showing up the image.
Following is my xaml part for it.
<Menu Height="50" Width="50" VerticalAlignment="Top" IsMainMenu="True">
<MenuItem Height="50" Width="50">
<MenuItem.Header>
<Image HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="50" Source="Images/pulsesi_icon_black.PNG"/>
</MenuItem.Header>
</MenuItem>
</Menu>
Help me out of it, I don't need an Icon.
you can use Menuitem.Icon for image in header.
<MenuItem >
<MenuItem.Icon>
<Image Width="20" Height="20" Source="/Resources/Images/Key.jpg" />
</MenuItem.Icon>
</MenuItem>