我正在尝试创建一个带有 TreeView
元素的资源管理器应用程序,并为树的每个级别设置不同的图标,并按照此处的文章进行操作:http://www.codeproject.com/Articles/21248/A-Simple-WPF-Explorer-Tree
一切都很好,除了我还想有不同的大小图标。
我的图像元素的 XAML
在这里:
<Image Name="img"
Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type TreeViewItem}},
Path=Header,
Converter={x:Static local:HeaderToImageConverter.Instance}}"
/>
决定返回哪个图标的代码在这里:
if ((value as string).Contains(@"\""))
{
Uri uri = new Uri ("pack://application:,,,/Images/DeployWiz_Network.png");
BitmapImage source = new BitmapImage(uri);
return source;
}
如何更改返回图像的尺寸?更改位图图像对象的尺寸似乎不起作用。我可以返回哪些其他图像对象作为源?
最佳答案
好的,我想出了我的问题。哎呀,真是个假人。下面是我更改的代码,它让我得到了我想要的结果:
Uri uri = new Uri("pack://application:,,,/Images/DeployWiz_Network.png");
BitmapImage source = new BitmapImage();
source.BeginInit();
source.UriSource = uri;
source.DecodePixelHeight = 10;
source.DecodePixelWidth = 10;
source.EndInit();
return source;
关于c# - 在 WPF 中更改 BitMapImage 的尺寸,我可以在 <Image> 元素中放置什么样的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17072775/