首页 > 解决方案 > 安装安装程序 vb.net 后系统托盘图标不显示

问题描述

我创建了一个带有通知图标的 WPF 应用程序。通知图标出现在托盘中,通过 BIN 文件夹 exe 运行应用程序。在为应用程序创建设置之后。安装程序安装成功。但是通知图标没有出现在任务栏托盘中。

**NotifyIconResources.xaml**


 <tb:TaskbarIcon x:Key="NotifyIcon"
                    IconSource="/Image/icon.ico"
                    ToolTipText="Notification"
                    LeftClickCommand="{Binding ShowWindowCommand}" 
                   >
        <tb:TaskbarIcon.DataContext>
            <local:NotifyIconViewModel />
        </tb:TaskbarIcon.DataContext>


**application.xaml**
StartupUri="MainWindow.xaml"

<ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="NotifyIconResources.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

**Application.xaml.vb**

Class Application
    Dim notifyIcon As TaskbarIcon


    Protected Overrides Sub OnStartup(ByVal e As StartupEventArgs)
        MyBase.OnStartup(e)
        notifyIcon = CType(FindResource("NotifyIcon"), TaskbarIcon)

    End Sub

    Protected Overrides Sub OnExit(ByVal e As ExitEventArgs)
        notifyIcon.Dispose()
        MyBase.OnExit(e)
    End Sub
End Class


**NotifyIconViewModel.vb**

 Public ReadOnly Property ShowWindowCommand As ICommand
        Get
            Return New DelegateCommand With {
                .CanExecuteFunc = Function() Application.Current.MainWindow Is Nothing,
                .CommandAction = Sub()                              
                                     Dim window As New MainWindow()
                                     Application.Current.MainWindow = window
                                     Application.Current.MainWindow.Show()

                                 End Sub
            }
        End Get
    End Property

标签: vb.neticonstaskbarsystem-trayinvisible

解决方案


推荐阅读