Search code examples
c#wpfxamlevent-handlingwindow

MouseLeftButtonUp event works only in maximized window


I have a StatusBar in my WPF application, defined via xaml.

<StatusBar Width="Auto" x:Name="StatusStrip" Margin="1,1,0,0" Background="{x:Null}" Foreground="#FF939393">
    <StatusBarItem  Content="{Binding SelectedImpName, UpdateSourceTrigger=PropertyChanged}" x:Name="Impianto" ToolTip="{DynamicResource FiltroImpianti}"  />
    <Separator />
    <StatusBarItem Content="Utente" x:Name="ToolStripStatusLabel" ToolTip="{DynamicResource UtenteAttivo}" />
    <Separator />
    <StatusBarItem  Content="IT" x:Name="Lingua" ToolTip="{DynamicResource Lingua}" />
    <Separator />
    <StatusBarItem  Content="" x:Name="txtMessaggi" Foreground="#FFEC4F4F" />
</StatusBar>

I have assigned a method on an event, this way:

this.ToolStripStatusLabel.MouseLeftButtonUp += ToolStripStatusLabel_MouseLeftButtonUp;

and this is the method:

private void ToolStripStatusLabel_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    try
    {
        bool x = false;
        x = attivazione.mdlFunzioni.OpenMsgBox(FindResource("M0001") + " " + attivazione.mdlImpostazioni.p.UserName + "?", this, MsgBoxStyle.YesNo);
        if (x)
            logOut();
    }
    catch (Exception myException)
    {
        attivazione.mdlError.gest_errori(FindResource("E0001").ToString(), "", myException);
    }
}

the problem that it works when the window is maximized, but it doesn't work when it is normal. With "doesn't work" I mean that it is like it doesn't catch the click of the mouse. And, if I maximize again the window, it works again.

What can be the error? Can I post more code to make it clear? Maybe chaging the associated event?

UPDATE: if I use the doubleClick event... it works in both cases!!


Solution

  • Solved changing the event... I use doubleClick now. And, strange, it works.