wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

Binding support to NotifyIcon

Open Tinekk opened this issue 2 years ago • 2 comments

I am creating an application that has dynamic tray icon (both icon and tooltip). So far I was able to do this using hardcodet. It would be cool to have such ability for wpfui. Also MenuItem commands are not working.

To Reproduce

        <ui:TitleBarHeader="{x:Static resx:Resources.AppTitle}">
            <ui:TitleBar.Tray>
                <ui:NotifyIcon 
                    FocusOnLeftClick="True"
                    MenuOnRightClick="True"
                    TooltipText="{Binding Test}"
                    Icon="{Binding TrayIcon}"
                >
                    <ui:NotifyIcon.Menu>
                        <ContextMenu>
                            <MenuItem Header="{Binding Test}" >
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <i:InvokeCommandAction Command="{Binding ShowApp}" PassEventArgsToCommand="True" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </MenuItem>
                            <Separator />
                           <MenuItem Command="{Binding ShowApp}" Header="{x:Static resx:Resources.OpenButton}" />
                        </ContextMenu>
                    </ui:NotifyIcon.Menu>
                </ui:NotifyIcon>
            </ui:TitleBar.Tray>
        </ui:TitleBar>

Expected behavior

  • Ability to bind Tooltip and Icon
  • Commands called

Desktop:

  • OS: Windows 10
  • .NET: net6.0
  • Version: 2.0.1

Additional context Working Hardcodet taskabar icon

        <tb:TaskbarIcon
                    IconSource="{Binding TrayIcon}"
                    ToolTipText="{Binding TrayTooltip}"
                    LeftClickCommand="{Binding ShowApp}"
                    MenuActivation="RightClick" >
            <tb:TaskbarIcon.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="{Binding ShowApp}" Header="{x:Static resx:Resources.OpenButton}" />
                </ContextMenu>
            </tb:TaskbarIcon.ContextMenu>
        </tb:TaskbarIcon>

Tinekk avatar Jul 18 '22 12:07 Tinekk

Not just the NotifyIcon, most of the controls with click handler in general. E.g ButtonRightClick & ButtonLeftClick in messagebox & dialog would be great to have an option to use those as Command using binding

jasmeet21 avatar Jul 20 '22 01:07 jasmeet21

NotifyIcon does support binding. So does the context menu. Its just that the context menu isn't part of the same visual tree and therefore doesn't have the same DataContext. This goes for any context menu, not specific to wpfui. One can fix this by setting the DataContext of the context menu in the code behind (i.e. this.notifyIcon.Menu.DataContext = viewModel).

jackBonadies avatar Feb 17 '24 17:02 jackBonadies