hardcodet / wpf-notifyicon

NotifyIcon (aka system tray icon or taskbar icon) for the WPF platform
MIT License
830 stars 130 forks source link

Command ability to execute doesn't seem possible to refresh #66

Closed viraptor closed 2 years ago

viraptor commented 2 years ago

I've got two entries in the tray (based on the sample):

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:tb="http://www.hardcodet.net/taskbar"
                    xmlns:local="clr-namespace:EarlyBillingNotification">

    <ContextMenu x:Shared="false" x:Key="SysTrayMenu">
        <MenuItem Header="Start monitor" Command="{Binding StartMonitorCommand}"/>
        <MenuItem Header="Stop monitor" Command="{Binding StopMonitorCommand}"/>
        <Separator />
        <MenuItem Header="Exit" Command="{Binding ExitApplicationCommand}"/>
    </ContextMenu>
    <tb:TaskbarIcon x:Key="NotifyIcon"
                    Visibility="Visible"
                    ToolTipText="Billing checks"
                    IconSource="foo.ico"
                    ContextMenu="{StaticResource SysTrayMenu}"
                    MenuActivation="LeftOrRightClick">
        <tb:TaskbarIcon.DataContext>
            <local:NotifyIconModelView/>
        </tb:TaskbarIcon.DataContext>
    </tb:TaskbarIcon>
</ResourceDictionary>

In the model I set them both using the RelayCommand:

            StartMonitorCommand = new RelayCommand(StartMonitor, () => !MonitorRunning);
            StopMonitorCommand = new RelayCommand(StopMonitor, () => MonitorRunning);

Initially the Stop Monitor entry is disabled as expected. But after running the command and the value switching, I don't get feedback, even though I'm doing manual notification:

                StartMonitorCommand.NotifyCanExecuteChanged();
                StopMonitorCommand.NotifyCanExecuteChanged();

Should this just work? Am I missing something simple?

viraptor commented 2 years ago

Of course I found the issue 5sec after posting this issue 🤷 Ignore me :D