I have a problem when creating a menu in WPF. What happens is that it closes automatically when you stop pressing the mouse button. I want it to behave as regular menu’s where you can click and the subitems will stay up but I can’t find anyway to get this done.
The code looks like this:
<Window x:Class="ExcelAddIn.MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<DockPanel>
<Menu Width="Auto" IsMainMenu="True" >
<MenuItem Header="Item">
<MenuItem Header="SubItem" />
</MenuItem>
</Menu>
</DockPanel>
</Grid>
</Window>
I’m wondering if it has anything to do with logical focus maybe? I saw something about it might being a bug in .NET framwork? Any ideas?
Thanks in advance
I didn’t think it made any difference at first but obviously it does. When running the code in a standalone WPF application it works, however when I try to open the WPF window from a Excel-addin project I get this problem..
Ok! I solved the problem. Turns out it was a focus problem after all.
When the excel addin executed the WPF window the excel window was still in focus. So on every mouseup the focus would jump back from WPF to excel.
All I had to do was change the execution from this:
to this:
Thanks for help anyway guys!