【发布时间】:2020-04-14 07:00:27
【问题描述】:
我以前从未见过这种情况。如果我这样设置画布的背景:
<Canvas.Background>
<ImageBrush ImageSource="Combined Victorian.png" Stretch="None" AlignmentX="Left" AlignmentY="Top" />
</Canvas.Background>
在运行时看起来像这样:
太棒了!正是我想要的。但后来,按下按钮,我在 2 张画布背景图像之间切换。当我像这样加载完全相同的图像时:
ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri(@"Images\Combined Victorian.png", UriKind.Relative));
MainCanvas.Background = brush;
它被压扁了,看起来像这样:
我该如何解决这个问题?
【问题讨论】:
-
您是否尝试使用
BitmapCache.None禁用BitmapCache选项 -
没有。我会在哪里做呢?加载之前还是之后?
-
尝试使用此示例:stackoverflow.com/questions/32456183/… 没有变化。
标签: c# wpf canvas background png