2021-08-08 WPF控件专题 Image控件详解

举报
愚公搬代码 发表于 2021/10/19 01:18:10 2021/10/19
【摘要】 1.Image控件介绍 属性介绍 Stretch StretchDirection Source 代码指定图像源 相对路径 绝对路径 pack uRI URiKind SourceUpdate 2...

1.Image控件介绍

属性介绍 Stretch StretchDirection Source

代码指定图像源 相对路径 绝对路径 pack uRI URiKind

SourceUpdate

2.具体案例

<Grid>
    <!--Stretch 默认 uniform StretchDirection 默认 Both-->
    <Image Name="imgPic" HorizontalAlignment="Left" Height="238" Margin="128,67,0,0" Stretch="Fill"  VerticalAlignment="Top" Width="357"  />
    <Button Content="指定图像" HorizontalAlignment="Left" Margin="427,352,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>

</Grid>

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
private void Button_Click(object sender, RoutedEventArgs e)
{
    //相对路径
    //imgPic.Source = new BitmapImage(new Uri("imgs/1111.jpg",UriKind.Relative));//Source ---  ImageSource
    //WPF 支持两种授权:application:/// 和 siteoforigin:///。
    // pack URI 方案 pack://授权/路径
    //授权 指定包含部件的程序包的类型,而路径 则指定部件在程序包中的位置。
    //siteoforigin  图片文件  生成:内容     application---资源、内容
    //imgPic.Source = new BitmapImage(new Uri("pack://application:,,,/imgs/1111.jpg", UriKind.Absolute));
    imgPic.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory+"/imgs/1111.jpg", UriKind.Absolute));
   
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

文章来源: codeboy.blog.csdn.net,作者:愚公搬代码,版权归原作者所有,如需转载,请联系作者。

原文链接:codeboy.blog.csdn.net/article/details/119518738

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200