【问题标题】:Set Background to canvas将背景设置为画布
【发布时间】:2012-08-17 02:07:06
【问题描述】:

如何在字符串路径上设置背景?

canvas1.Background = "/path/";

请帮忙!!!谢谢:)

【问题讨论】:

    标签: c# wpf xaml


    【解决方案1】:

    我认为您正在寻找 ImageBrush 类:

    ImageBrush imageBrush = new ImageBrush();
    imageBrush.ImageSource = new BitmapImage(new Uri(@"/path/", UriKind.Relative));
    canvas1.Background = imageBrush;
    

    【讨论】:

      【解决方案2】:

      使用这个

      mycanvas.Background = new ImageBrush() 
                { ImageSource = new BitmapImage((new Uri(mypath, UriKind.Absolute))) };
      

      【讨论】:

        猜你喜欢
        • 2015-11-21
        • 1970-01-01
        • 2018-01-05
        • 2018-05-30
        • 2016-12-22
        • 2023-04-11
        • 2013-03-28
        • 2019-04-27
        • 2021-11-29
        相关资源
        最近更新 更多