I've never done any work in wpf before and i'm supposed to add an undo button. I want it to look like what the undo button in VS looks like (click to undo once, hover over to get the more in depth listbox). I managed to get whats in the picture. It is inside a menuitem and i can't figure out how to just make it a white box without any borders or anything. Please Help!
Here's code:
<MenuItem Header="Edit" Width="50" HorizontalContentAlignment="Center" >
<MenuItem x:Name="MenuCopy" Header="Copy to Excel" >
<MenuItem.Icon>
<Image Source="copy.ico" Width="24" Height="24" />
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="MenuUndo" Header="Undo Last Action" IsEnabled="true">
<MenuItem.Icon>
<Image Source="Undo.png" Width="24" Height="24" />
</MenuItem.Icon>
<ListBox>
<ListBoxItem Name="Item" Height="10" Width="100">
</ListBoxItem>
</ListBox>
</MenuItem>
you may try to override the ControlTemplate and set the styles and remove padding, borders.
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
...
</ControlTemplate>
</Setter.Value>
</Setter>
Check this msdn link for Listbox style.
Related
I am new to WPF. I want to create a menu like given in the picture in wpf. i have created menu,but don't know how to create extendable menu items
also i want the arrow in shape as underline in picture.
This should get your started.
<Expander HorizontalAlignment="Left" FlowDirection="RightToLeft" Width="200" Background="#394768" Foreground="White" FontSize="16" FontFamily="Verdana">
<Expander.Header>
<Grid Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}}, Path=ActualWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Schedule" />
<Image Grid.Column="1" Source="calendar.png" Width="20" Height="20" />
</Grid>
</Expander.Header>
<Menu Background="#232230" Foreground="White" FontSize="16" FontFamily="Verdana">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<Menu.ItemContainerStyle>
<Style TargetType="MenuItem">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="TextBlock.TextDecorations" Value="Underline"/>
</Trigger>
</Style.Triggers>
</Style>
</Menu.ItemContainerStyle>
<MenuItem Header="Department Schedule" />
<MenuItem Header="Employee Schedule"/>
<MenuItem Header="Temporary Schedule"/>
<MenuItem Header="Schedule View"/>
</Menu>
</Expander>
Here's the calendar.png that I used for this example (WARNING: IT'S WHITE SO YOU WILL NEED TO CLICK ON IT TO SEE IT):
Now if you want to change the arrow icon to something that looks like the picture you provided, you will need to override the Expander's ControlTemplate entirely, and replace it with your own arrow icon. Here's a good guide from codeproject. It will take some studying and understanding on your part here, so I will leave that exercise up to you.
I'm using a ContextMenu on the right click on a DataGrid. I don't want to show the ContextMenu on the DataGrid header.
<dgWPFCtrl:SelfBindingDataGrid Grid.Row="1" Margin="0,5,0,0" Name="_cycleList"
ItemsSource="{Binding Path=CurrentElementsList, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
IsReadOnly="False"
SelectedItem="{Binding Path=CurrentItem}">
<dgWPFCtrl:SelfBindingDataGrid.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding OpenCycleCommand}" Header="CYCLE" CommandParameter="CYCLE"/>
<MenuItem Command="{Binding OpenCycleCommand}" Header="H1" CommandParameter="H1"/>
<MenuItem Command="{Binding OpenCycleCommand}" Header="PDF" CommandParameter="PDF"/>
</ContextMenu>
</dgWPFCtrl:SelfBindingDataGrid.ContextMenu>
How can I solve this?
You can change ContextMenu just for the header with ColumnHeaderStyle:
<dgWPFCtrl:SelfBindingDataGrid>
<dgWPFCtrl:SelfBindingDataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu Visibility="Collapsed" />
</Setter.Value>
</Setter>
</Style>
</dgWPFCtrl:SelfBindingDataGrid.ColumnHeaderStyle>
So I made a simple menu with a Width of 55 I try to make my title ("FILE") centered within the button itself while still being on the left of the window.
At the moment the basic code looks like that
<Menu Height="25" VerticalAlignment="Top" Width="800" Margin="0">
<MenuItem Header="File" Margin="0" Height="25" Width="55" HorizontalContentAlignment="Center">
<MenuItem Header="Login"/>
<MenuItem Header="New User"/>
...
</MenuItem> </Menu>
I've already tried playing around with a code like
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
To remove the grid but no sucess it's only the actual menu being centered and not the text "FILE" within the button.
Here's an example of what the "FILE" looks like at the moment and I try to make it centered within the blue area.
http://i.stack.imgur.com/KRXw2.png
(Cannot post the actual image I don't have enough rep.)
Thanks.
You an achieve this by setting the MenuItem's header template to be a TextBlock, with the TextBlock being the same width of the MenuItem itself. Also, you will need to add a Margin to compensate for the default MenuItem template.
<Menu Height="25" VerticalAlignment="Top" Width="800" Margin="0">
<MenuItem Margin="0" Height="25" Width="55" HorizontalContentAlignment="Center">
<MenuItem.Header>
<TextBlock Text="File" HorizontalAlignment="Stretch" Margin="-7" Width="55" TextAlignment="Center"/>
</MenuItem.Header>
<MenuItem Header="Login"/>
<MenuItem Header="New User"/>
</MenuItem>
</Menu>
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.
How do I vertically center a header in the menu control?
This was my try:
<MenuItem Header="File" StaysOpenOnClick="True" FontFamily="Arial" VerticalAlignment="Center">
<MenuItem Header="Open" Click="Open_Click" IsEnabled="True"/>
</MenuItem>
</Menu>
But its aligned to the Top-left.
What am I doing wrong?
[EDIT]
My whole menu now looks like this:
<Menu Canvas.Left="0" Canvas.Top="0" Name="menu1" Margin="0,0,0,384">
<MenuItem Header="File" StaysOpenOnClick="True" FontFamily="Arial" VerticalAlignment="Center">
<MenuItem Click="Open_Click" IsEnabled="True">
<MenuItem.Header>
<TextBlock Text="Open" VerticalAlignment="Center"/>
</MenuItem.Header>
</MenuItem>
</MenuItem>
</Menu>
The header text 'file' still isn't vertically centered (which is what i want to center).
What exactly is this code centering? Is it the text 'open'?
[/EDIT]
If you want to format the header you'll need to explicitly layout the header control:
<MenuItem StaysOpenOnClick="True" FontFamily="Arial" VerticalAlignment="Center">
<MenuItem Click="Open_Click" IsEnabled="True">
<MenuItem.Header>
<TextBlock Text="Open" VerticalAlignment="Center"/>
</MenuItem.Header>
</MenuItem>
</Menu>
Update:
To format the position of a MenuItem in the Menu you'll need to override the Menu's ItemsPanelTemplate. By default the Menu uses a vertical WrapPanel which justifies the items to the top. Replace the default with a panel of your choice (StackPanel, Grid, DockPanel, etc) and you'll be able center the menu items as you please. Here's an example:
<Menu Canvas.Left="0" Canvas.Top="0" Name="menu1" Margin="0,0,0,384">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem Header="File" StaysOpenOnClick="True" FontFamily="Arial" VerticalAlignment="Center" >
<MenuItem Header="Open" Click="Open_Click" IsEnabled="True"/>
</MenuItem>
</Menu>
Information gathered from this post on MSDN.
I think you would want to set the VerticalContentAlignment. If the aligmnet is still not to your liking there is probably a problem with the default MenuItem Template, it may not bind to the property or there are some margins or Paddings which shift the header.