开发者

"path" not a valid property for Image.source

开发者 https://www.devze.com 2023-01-08 04:55 出处:网络
I\'m trying to change the background image set by xaml this way: <s:SurfaceWindow.Resources> <ImageBrush x:Key=\"WindowBackground\"

I'm trying to change the background image set by xaml this way:

      <s:SurfaceWindow.Resources>
    <ImageBrush x:Key="WindowBackground" 
Stretch="None" Opacity="0.6" ImageSource="pack://application:,,,/Resources/img/bg/Default.jpg"/>
  </s:SurfaceWindow.Resources>

by using the following code in a method:

        sessionWindow.SetValue(ImageBrush.ImageSourceProperty, "..//..//Resources//im开发者_StackOverflowg//bg//Aqua.jpg");

where sessionWindow is the the actual window. It throws the exception in the title


The ImageBrush.ImageSource property is of type ImageSource.

Therefore, you need to set it to an ImageSource instance.
Also, your path is wrong.

For example:

sessionWindow.SetValue(ImageBrush.ImageSourceProperty,
     new BitmapImage(
        new Uri(@"..\..\Resources\img\bg\Aqua.jpg", UriKind.Relative)
     )
);

However, this won't actually change the background - Window doesn't have an ImageSource property.
Instead, you should set the Window's Background property, like this:

sessionWindow.Background = new ImageBrush {
     ImageSource = new BitmapImage(
        new Uri(@"..\..\Resources\img\bg\Aqua.jpg", UriKind.Relative)
     )
};
0

精彩评论

暂无评论...
验证码 换一张
取 消