添加图像到状态栏不起作用 [英] Add Image to Statusbar not working

查看:92
本文介绍了添加图像到状态栏不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一个例子,但没有工作

将图像添加到状态栏

< Window xmlns =   http: //schemas.microsoft.com/winfx/2006/xaml/presentation 
xmlns:x = http://schemas.microsoft.com/winfx/2006/xaml
x:Class = StatusBarSimple.Window1
Title = StatusBar >
< Window.Resources>
< Style x:Key = StatusBarSeparatorStyle TargetType = 分隔符 >
< Setter Property = 背景值= LightBlue />
< Setter Property = Control.Width Value = 1 />
< Setter Property = Control.Height Value = 20 />
< / 风格 >
< / Window.Resources >
< StatusBar Name = sbar Grid.Column = 0 Grid.Row = 2 Grid.ColumnSpan = 2
VerticalAlignment = 底部已删除= 米色 >
< StatusBarItem>
< Button Content = 点击 Click = MakeProgressBar />
< / StatusBarItem >
< StatusBarItem>
< Separator Style = {StaticResource StatusBarSeparatorStyle} />
< / StatusBarItem >
< / StatusBar >
< / 窗口 >
// 文件:Window.xaml.cs
使用系统;
使用 System.Windows;
使用 System.Windows.Controls;
使用 System.Windows.Controls.Primitives;
使用 System.Windows.Data;
使用 System.Windows.Documents;
使用 System.Windows.Media;
使用 System.Windows.Media.Animation;
使用 System.Windows.Media.Imaging;
使用 System.Windows.Shapes;

命名空间 StatusBarSimple
{
public partial class Window1:Window
{
private void MakeProgressBar( object sender,RoutedEventArgs e)
{
sbar.Items.Clear();
DockPanel dpanel = new DockPanel();
TextBlock txtb = new TextBlock();
txtb.Text = 打印;
dpanel.Children.Add(txtb);
Image printImage = new Image();
printImage.Width = 20 ;
printImage.Height = 20 ;
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri( @ 包://应用:,,, /图像/ print.bmp);
bi.EndInit();
printImage.Source = bi;
dpanel.Children.Add(printImage);
TextBlock txtb2 = new TextBlock();
txtb2.Text = 5pgs;
dpanel.Children.Add(txtb2);
StatusBarItem sbi = new StatusBarItem();
sbi.Content = dpanel;
sbi.Horizo​​ntalAlignment = Horizo​​ntalAlignment.Right;
ToolTip ttp = new ToolTip();
ttp.Content = 发送给打印机。;
sbi.ToolTip =(ttp);
sbar.Items.Add(sbi);
}
}
}

解决方案

我知道这可能不是这么简单,但是你试过这个吗?

 <   StatusBarItem  >  
< 图片 高度 = 16 来源 = abacus.png 拉伸 = 填写 宽度 = 16 / >
< / StatusBarItem >


I found an example but not works
Add Image to Statusbar

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="StatusBarSimple.Window1"
    Title ="StatusBar">
  <Window.Resources>
    <Style x:Key="StatusBarSeparatorStyle" TargetType="Separator">
      <Setter Property="Background" Value="LightBlue" />
      <Setter Property="Control.Width" Value="1"/>
      <Setter Property="Control.Height" Value="20"/>
    </Style>    
  </Window.Resources>
        <StatusBar Name="sbar" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" 
                   VerticalAlignment="Bottom" removed="Beige" > 
             <StatusBarItem>
                <Button Content="click" Click="MakeProgressBar"/>
             </StatusBarItem>
             <StatusBarItem>
               <Separator Style="{StaticResource StatusBarSeparatorStyle}"/>
             </StatusBarItem>
        </StatusBar>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace StatusBarSimple
{
    public partial class Window1 : Window
    {
        private void MakeProgressBar(object sender, RoutedEventArgs e)
        {
            sbar.Items.Clear();
            DockPanel dpanel = new DockPanel();
            TextBlock txtb = new TextBlock();
            txtb.Text = "Printing  ";
            dpanel.Children.Add(txtb);
            Image printImage = new Image();
            printImage.Width = 20;
            printImage.Height = 20;
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.UriSource = new Uri(@"pack://application:,,,/images/print.bmp");
            bi.EndInit();
            printImage.Source = bi;
            dpanel.Children.Add(printImage);
            TextBlock txtb2 = new TextBlock();
            txtb2.Text = "  5pgs";
            dpanel.Children.Add(txtb2);
            StatusBarItem sbi = new StatusBarItem();
            sbi.Content = dpanel;
            sbi.HorizontalAlignment = HorizontalAlignment.Right;
            ToolTip ttp = new ToolTip();
            ttp.Content = "Sent to printer.";
            sbi.ToolTip = (ttp);
            sbar.Items.Add(sbi);
        }
    }
}

解决方案

I know it probably isn't this simple, but have you tried this?

<StatusBarItem>
   <Image Height="16" Source="abacus.png" Stretch="Fill" Width="16"/>
</StatusBarItem>


这篇关于添加图像到状态栏不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆