WPF工具栏图标托盘图标的添加方法

1.找寻合适的图标

网上的图标资源很多,也有专门的图标资源站点。我是在http://www.easyicon.net找的,很方便。注意图标的让人能读图知意,美观大方,并注意图标的大小尺寸。

2.像WPF中添加图标资源

在工程项目里新建文件夹Resources。右击Resources文件夹,选择添加->新建项,在VC#下选择资源文件模板,后缀名是.resx(VS2013),选择添加。


会出现如图的界面。注意,我用红色椭圆圈起来的部分。

然后,点击添加资源,


选择添加现有文件。


双击图标进行编辑,保存即可。

在xaml代码中引用图标,代码

    <Window.Resources>
        <ResourceDictionary>
            <BitmapImage x:Key="OpenPng" 
                         UriSource="D:\Documents\Visual Studio 2013\Projects\DmdSimAppV1.0\DmdSimAppV1.0\Resources\open.png">
            </BitmapImage>
            <BitmapImage x:Key="SavePng" 
                         UriSource="D:\Documents\Visual Studio 2013\Projects\DmdSimAppV1.0\DmdSimAppV1.0\Resources\save.png">
            </BitmapImage>
            <BitmapImage x:Key="MeasurePng" 
                         UriSource="D:\Documents\Visual Studio 2013\Projects\DmdSimAppV1.0\DmdSimAppV1.0\Resources\measure.png">
            </BitmapImage>
            <BitmapImage x:Key="RunPng" 
                         UriSource="D:\Documents\Visual Studio 2013\Projects\DmdSimAppV1.0\DmdSimAppV1.0\Resources\run.png">
            </BitmapImage>
            <BitmapImage x:Key="ConfigurePng" 
                         UriSource="D:\Documents\Visual Studio 2013\Projects\DmdSimAppV1.0\DmdSimAppV1.0\Resources\configure.png">
            </BitmapImage>
            <BitmapImage x:Key="ParaPng" 
                         UriSource="D:\Documents\Visual Studio 2013\Projects\DmdSimAppV1.0\DmdSimAppV1.0\Resources\para.png">
            </BitmapImage>
            <BitmapImage x:Key="BmpPng" 
                         UriSource="D:\Documents\Visual Studio 2013\Projects\DmdSimAppV1.0\DmdSimAppV1.0\Resources\bmp.png">
            </BitmapImage>
        </ResourceDictionary>
    </Window.Resources>

        <ToolBar Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="9" Background="White">
            <Image Name="OpenFile" Source="{StaticResource OpenPng}" MouseDown="OpenFile_MouseDown"></Image>
            <Image Name="SaveFile" Source="{StaticResource SavePng}"></Image>
            <Image Name="ConfigurationFile" Source="{StaticResource ConfigurePng}"></Image>
            <Image Name="Measure" Source="{StaticResource MeasurePng}"></Image>
            <Image Name="Run" Source="{StaticResource RunPng}"></Image>
        </ToolBar>
        private void OpenFile_MouseDown(object sender, MouseButtonEventArgs e) {
            string file = null;
            var dlg = new OpenFileDialog();
            dlg.InitialDirectory = "E:";
            dlg.Filter = "*.bmp|*.bmp";
            Nullable<bool> result = dlg.ShowDialog();
            if (result == true) {
                file = dlg.FileName;
            }
            Uri resourceUri = new Uri(file);
            ImgInBox.Source = new BitmapImage(resourceUri);
        }
3.添加托盘图标

只要修改Window的Icon属性即可在运行时,看到APP在托盘上呈现的图标。
运行结果:



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值