18 messaggi dal 20 ottobre 2010
Salve ho creato un menu non capisco perchè ,se apro e chiudo i sottomenu, quando poi cerco di chiudere la form devo cliccare due volte sulla x prima che si chiuda. Potete aiutarmi?
Posto il codice:

<Window x:Class="cookinfamily.Menu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Menu" Height="70" Width="440" Loaded="Window_Loaded" >
<DockPanel LastChildFill="True">
<Menu DockPanel.Dock="Left" TabIndex="1"
VerticalAlignment="Stretch" Width="420" Name="Prova" IsMainMenu="True" MouseLeave="Menu_MouseLeave">
<Menu.Resources>
<Style x:Key="ThemeMenuItemStyle" TargetType="MenuItem" >
<Setter Property="Header" Value="{Binding Name}"></Setter>
<Setter Property="Command" Value="{Binding ActivateCommand}"/>
<Setter Property="Background" Value="AliceBlue" />
<Setter Property="Foreground" Value="SteelBlue"/>
<Setter Property="HeaderStringFormat" Value="Bold"/>
<Setter Property="Width" Value="140"/>
<Setter Property="Height" Value="28"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontStretch" Value="2"/>
<Setter Property="BorderBrush" Value="Ivory"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="10,2,0,0"/>
</Style>

</Menu.Resources>




<MenuItem Header="Mapping" ItemsSource="{Binding Themes}"
Style="{StaticResource ThemeMenuItemStyle}"
MouseEnter="MenuItem_MouseEnter" MouseLeave="MenuItem_MouseLeave" >

<MenuItem.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</MenuItem.ItemsPanel>
<MenuItem Header="_New" IsCheckable="true"/>
<MenuItem Header="_Open" IsCheckable="true"/>
<MenuItem Header="_Close" IsCheckable="true"/>
<Separator/>
<MenuItem Header="Menu with Submenu">
<MenuItem Header="_submenuitem1" IsCheckable="true"/>
<MenuItem Header="_submenuitem2" IsCheckable="true">
<MenuItem Header="_submenuitem2.1" IsCheckable="true"/>
</MenuItem>
</MenuItem>
</MenuItem>
<MenuItem Header="Cucina" ItemsSource="{Binding Themes}"
Style="{StaticResource ThemeMenuItemStyle}"
MouseEnter="MenuItem_MouseEnter" MouseLeave="MenuItem_MouseLeave">
<MenuItem.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</MenuItem.ItemsPanel>
<MenuItem Header="_New" IsCheckable="true"/>
<MenuItem Header="_Open" IsCheckable="true"/>
<MenuItem Header="_Close" IsCheckable="true"/>
<Separator/>
<MenuItem Header="Menu with Submenu">
<MenuItem Header="_submenuitem1" IsCheckable="true"/>
<MenuItem Header="_submenuitem2" IsCheckable="true">
<MenuItem Header="_submenuitem2.1" IsCheckable="true"/>
</MenuItem>
</MenuItem>
</MenuItem>
<MenuItem Header="Struttura" ItemsSource="{Binding Themes}"
Style="{StaticResource ThemeMenuItemStyle}"
MouseEnter="MenuItem_MouseEnter" MouseLeave="MenuItem_MouseLeave">
<MenuItem.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</MenuItem.ItemsPanel>
<MenuItem Header="Alimenti" IsCheckable="true"/>
<MenuItem Header="_Open" IsCheckable="true"/>
<MenuItem Header="_Close" IsCheckable="true"/>
<Separator/>
<MenuItem Header="Menu with Submenu">
<MenuItem Header="_submenuitem1" IsCheckable="true"/>
<MenuItem Header="_submenuitem2" IsCheckable="true">
<MenuItem Header="_submenuitem2.1" IsCheckable="true"/>
</MenuItem>
</MenuItem>
</MenuItem>
</Menu>
</DockPanel>
</Window>



private void MenuItem_MouseEnter(object sender, MouseEventArgs e)
{
MenuItem mi = (MenuItem)sender;

if (mi.Role == MenuItemRole.TopLevelHeader) mi.IsSubmenuOpen = true;

}



private void MenuItem_MouseLeave(object sender, MouseEventArgs e)
{
MenuItem mi = (MenuItem)sender;

if (mi.Role == MenuItemRole.TopLevelHeader)
{
mi.IsSubmenuOpen = false;
//Prova.Items.DeferRefresh();
}
}

private void Menu_MouseLeave(object sender, MouseEventArgs e)
{

foreach (MenuItem mi in Prova.Items) mi.IsSubmenuOpen = false;

}
ciao, stavo cercando di ricreare il tuo progetto per verificare se anch'io incontro il tuo streso problema, ma purtroppo ci sono degli errori nello script che hai scritto, se puoi, riesci a postare tutto il codice presente nella tua pagina, di modo che possa fare questo tentativo?

grazie...

Creazione Siti Vicenza
Posizionamento Siti - SEO
18 messaggi dal 20 ottobre 2010
<Window x:Class="cookinfamily.Menu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Menu" Height="70" Width="440"
ResizeMode="CanResizeWithGrip"
Loaded="Window_Loaded">
<DockPanel LastChildFill="True">
<Menu Name="menu_prog" DockPanel.Dock="Left"
VerticalAlignment="Stretch" Width="420" IsMainMenu="True" MouseLeave="Menu_MouseLeave">
<Menu.Resources>
<Style x:Key="ThemeMenuItemStyle" TargetType="MenuItem" >
<Setter Property="Header" Value="{Binding Name}"></Setter>
<Setter Property="Command" Value="{Binding ActivateCommand}"/>
<Setter Property="Background" Value="AliceBlue" />
<Setter Property="Foreground" Value="SteelBlue"/>
<Setter Property="HeaderStringFormat" Value="Bold"/>
<Setter Property="Width" Value="140"/>
<Setter Property="Height" Value="28"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontStretch" Value="2"/>
<Setter Property="BorderBrush" Value="Ivory"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="10,2,0,0"/>

</Style>
</Menu.Resources>

<MenuItem Header="Mapping" ItemsSource="{Binding Themes}"
Style="{StaticResource ThemeMenuItemStyle}"
MouseEnter="MenuItem_MouseEnter" MouseLeave="MenuItem_MouseLeave" >

<MenuItem.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</MenuItem.ItemsPanel>
<MenuItem Header="_New" IsCheckable="true"/>
<MenuItem Header="_Open" IsCheckable="true"/>
<MenuItem Header="_Close" IsCheckable="true"/>
<Separator/>
<MenuItem Header="Menu with Submenu">
<MenuItem Header="_submenuitem1" IsCheckable="true"/>
<MenuItem Header="_submenuitem2" IsCheckable="true">
<MenuItem Header="_submenuitem2.1" IsCheckable="true"/>
</MenuItem>
</MenuItem>
</MenuItem>
<MenuItem Header="Cucina" ItemsSource="{Binding Themes}"
Style="{StaticResource ThemeMenuItemStyle}"
MouseEnter="MenuItem_MouseEnter" MouseLeave="MenuItem_MouseLeave">
<MenuItem.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</MenuItem.ItemsPanel>
<MenuItem Header="_New" IsCheckable="true"/>
<MenuItem Header="_Open" IsCheckable="true"/>
<MenuItem Header="_Close" IsCheckable="true"/>
<Separator/>
<MenuItem Header="Menu with Submenu">
<MenuItem Header="_submenuitem1" IsCheckable="true"/>
<MenuItem Header="_submenuitem2" IsCheckable="true">
<MenuItem Header="_submenuitem2.1" IsCheckable="true"/>
</MenuItem>
</MenuItem>
</MenuItem>
<MenuItem Header="Struttura" ItemsSource="{Binding Themes}"
Style="{StaticResource ThemeMenuItemStyle}"
MouseEnter="MenuItem_MouseEnter" MouseLeave="MenuItem_MouseLeave">
<MenuItem.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</MenuItem.ItemsPanel>
<MenuItem Header="Alimenti" IsCheckable="true"/>
<MenuItem Header="_Open" IsCheckable="true"/>
<MenuItem Header="_Close" IsCheckable="true"/>
<Separator/>
<MenuItem Header="Menu with Submenu">
<MenuItem Header="_submenuitem1" IsCheckable="true"/>
<MenuItem Header="_submenuitem2" IsCheckable="true">
<MenuItem Header="_submenuitem2.1" IsCheckable="true"/>
</MenuItem>
</MenuItem>
</MenuItem>
</Menu>
</DockPanel>

</Window>






using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace cookinfamily
{
/// <summary>
/// Logica di interazione per Menu.xaml
/// </summary>
public partial class Menu : Window
{
public Menu()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
}


private void MenuItem_MouseEnter(object sender, MouseEventArgs e)
{
MenuItem mi = (MenuItem)sender;

if (mi.Role == MenuItemRole.TopLevelHeader) mi.IsSubmenuOpen = true;

}



private void MenuItem_MouseLeave(object sender, MouseEventArgs e)
{
MenuItem mi = (MenuItem)sender;

if (mi.Role == MenuItemRole.TopLevelHeader)
{
mi.IsSubmenuOpen = false;
//Prova.Items.DeferRefresh();
}
}

private void Menu_MouseLeave(object sender, MouseEventArgs e)
{

foreach (MenuItem mi in menu_prog.Items) mi.IsSubmenuOpen = false;

}

}
}
in effetti la cosa (alquanto fastidiosa) si presenta anche a me, faccio qualche prova poi ti so dire...

Creazione Siti Vicenza
Posizionamento Siti - SEO
18 messaggi dal 20 ottobre 2010
esatto è fastidiosa,grazie intando per l'interessamento, spero non sia un BUG irrisolvibile..
private void MenuItem_MouseLeave(object sender, MouseEventArgs e)
{
    MenuItem mi = (MenuItem)sender;

    if (mi.Role == MenuItemRole.TopLevelHeader)
    {
        mi.IsSubmenuOpen = false;
        <b>this.Focus();</b>
    }
}


HTH
18 messaggi dal 20 ottobre 2010
Fantastico, grazie mille, però come al solito i problemi sono sempre infiniti. Ora rimane il problema quando ho una finestra aperta con il menu e sotto una pagina, se passo sul menù e poi torno con il mouse sulla pagina devo anche in questo caso fare il doppio clic prima di poter effettuare un'azione esempio chiudere la stessa. Come posso risolvere in questo caso? ovviamente intanto grazie mille per l'aiuto

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.