Putting a drop shadow on a menu item box - c#

This is my first attempt at creating an application, so apologies if my questions are misformed or misplaced.
First a question of terminology: when you click on 'file' in a menu bar and a little box appears below with options like 'quit' and 'save,' what's this box called? Is this just called a 'context menu'?
Second: how can I put a drop shadow on this box? I've seriously been tinkering and googling for the longest time with no luck. For some reason the default in visual studio express 2013, at least as I'm using it, seems to be no shadow, which looks pretty odd imo. Here's the relevant XAML:
<Menu x:Name="MenuBar" HorizontalAlignment="Stretch" Height="27" Margin="-20,-36,140.4,0" VerticalAlignment="Top" Width="Auto" Foreground="Black" RenderTransformOrigin="0.5,0" Background="#FFE5E5E5">
<MenuItem x:Name="File" Header="File" Height="27" Width="39" TextOptions.TextHintingMode="Animated" Foreground="#FF323334" BorderThickness="0" BorderBrush="{x:Null}" Margin="1,0,4,4" Padding="6,0">
<MenuItem x:Name="Save" Header="Save" HorizontalAlignment="Left" Width="139.2" Click="Save_Click"/>
<MenuItem Header="Quit" HorizontalAlignment="Left" Width="139.2" Click="MenuItem_Click" Background="{x:Null}" BorderBrush="{x:Null}" UseLayoutRounding="False"/>
</MenuItem>
</Menu>
Thanks in advance for any help!
EDIT: I ended up getting my answer elsewhere.

Related

How can I make the checkmark in this MenuItem respect the overall Foreground color?

I am making a menu using MenuItem controls placed inside of a StackPanel.
Here's an example of the menu item XAML:
<Border Grid.Column="1"
Background="Black"
BorderBrush="{x:Static SystemColors.ActiveBorderBrush}"
BorderThickness="1"
Opacity="0.8"
Padding="3">
<StackPanel Orientation="Vertical">
<MenuItem Foreground="White"
Header="Show Mini Map"
IsCheckable="True"
IsChecked="{Binding ShowMiniMap, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
...more items...
</StackPanel>
</Border>
...and here's what it looks like on-screen:
You can see how the checked items have the usual blue ring around the checkmark, and the checkmark is there...it's just black. Why does it not respect the item's Foreground property?
Is there a way to make it do so without having to take on maintenance of a gazillion-line template override? The examples I've found online thus far are incredibly ridiculous for such a small thing.

How to get rid of grey area on DockPanel and Calender?

I have a Calendar control made to drop down when needed, but I have these great big greay area on both sides.
I have tried everything I possibly can, but I can't seem to get rid of the grey area on both sides of a calendar.
This is the XAML,
<DockPanel Grid.Row="0" Grid.Column="8" Height="25">
<Menu DockPanel.Dock="Top" Height="25" Width="100">
<MenuItem Header="calender" Height="25" Width="100" >
<Calendar Name="CalenderSelect"
SelectionMode="MultipleRange"
SelectedDatesChanged="Calendar_OnSelectedDatesChanged"
Width="192">
</Calendar>
</MenuItem>
</Menu>
</DockPanel>
My second question, is this the correct way to create a drop down control with a calendar inside it. Or am I doing this wrong, any help would be much appreciated.
First of all, from my point of view to use a menu is a bad idea to create a drop down control. You can do something similar and easier with a button.
However if you want to use the MenuItem control, you have to change the MenuItem.ItemsTemplate in order to reduce margins and remove background color:
<Menu DockPanel.Dock="Top" Height="25" Width="100">
<MenuItem Header="calender" Height="25" Width="100" AutomationProperties.IsColumnHeader="True" >
<MenuItem.Items>
<Calendar Name="CalenderSelect" SelectionMode="MultipleRange" > </Calendar>
</MenuItem.Items>
<MenuItem.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Margin="-35,-5,-50,-5" Background="{x:Null}"></StackPanel>
</ItemsPanelTemplate>
</MenuItem.ItemsPanel>
</MenuItem>
</Menu>
I hope this can help you.

MenuItem command called when clicking IsCheckable checkbox

My XAML:
<MenuItem Command="{Binding ShowRequestsCommand}" HorizontalAlignment="Stretch" IsCheckable="True" IsChecked="{Binding ShowUrgentEvaluationRequestNotification, Source={x:Static Properties:Settings.Default}, Mode=TwoWay}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<Border Background="Red" CornerRadius="5" Padding="3,1,3,1" Margin="1,1,5,1" HorizontalAlignment="Left" MinWidth="18"></Border>
<TextBlock>Beställningshanteraren</TextBlock>
</StackPanel>
</MenuItem.Header>
</MenuItem>
So it's a MenuItem with some stuff in the header, it is checkable, and that value is supposed to have some functionality elsewhere, it also has a command.
My problem is that when you click the checkbox, the command is called, which is not my intention, and it seems wrong for any situation honestly. You should be able to click the checkbox without activating whatever the MenuItem is supposed do do. I get the same result if I add a click event on the menuitem instead.
Why does WPF work like this? Is there a workaround?

Adding drop shadow on a menu item box

This is my first attempt at creating an application, so apologies if my questions are misformed or misplaced.
When you click on 'file' in a menu bar and a little box appears below with options like 'quit' and 'save,' how do I put a drop shadow on this box? I've seriously been tinkering and googling for the longest time with no luck. I feel like I've exhausted the options in visual studio and tried various code in my xaml. Here's the relevant XAML:
<Menu x:Name="MenuBar" HorizontalAlignment="Stretch" Height="27" Margin="-20,-36,140.4,0" VerticalAlignment="Top" Width="Auto" Foreground="Black" RenderTransformOrigin="0.5,0" Background="#FFE5E5E5">
<MenuItem x:Name="File" Header="File" Height="27" Width="39" TextOptions.TextHintingMode="Animated" Foreground="#FF323334" BorderThickness="0" BorderBrush="{x:Null}" Margin="1,0,4,4" Padding="6,0">
<MenuItem x:Name="Save" Header="Save" HorizontalAlignment="Left" Width="139.2" Click="Save_Click"/>
<MenuItem Header="Quit" HorizontalAlignment="Left" Width="139.2" Click="MenuItem_Click" Background="{x:Null}" BorderBrush="{x:Null}" UseLayoutRounding="False"/>
</MenuItem>
</Menu>
Thanks in advance for any help!
EDIT: I ended up getting my answer eslewhere
You just need to create your own Template
here's a link on how to ovveride the default MenuItem Style

ContextMenu in WPF is too wide

I've got a problem with my ContextMenu in WPF. The menu is far too wide- it's the width of the items I put on it, plus about fifty-a hundred pixels. So when you open the menu, instead of being a clean list of options or buttons, there's loads of greyspace on each side. How can I fix this?
Edit: Here's my XAML for the menu:
<ContextMenu Padding="0">
<Button Content="Close Tab" Height="23" Name="closetabbutton" Width="75" Margin="0,0,0,0" Click="closetabbutton_Click" />
<TextBox Height="23" Name="renamebox" Width="75" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ClipToBounds="True" TextChanged="renamebox_TextChanged" />
<Button Content="Close Menu" Height="23" Name="closemenubutton" Width="75" Margin="0,0,0,0" Click="closemenubutton_Click" />
</ContextMenu>
The space is reserved for icons on the left, and input gesture text (e.g. Ctrl+C) on the right. This is by design.
If you wish to change this, you'll have to create your own ContextMenu style. Here's an example of how to do this:
http://www.dev102.com/2008/06/20/how-to-create-a-wpf-custom-context-menu/
Update
Further to my question comment, MenuItems would normally be used where you have used buttons. For example:
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Name="mnuClose" Header="Close tab" InputGestureText="Ctrl+C" />
<MenuItem Name="mnuRename">
<MenuItem.Header>
<TextBox Name="txtRename" Width="100" />
</MenuItem.Header>
</MenuItem>
</ContextMenu>
</Grid.ContextMenu>

Categories

Resources