2013-06-12 2 views
3

은 내가 TreeView 요소 탐색기 응용 프로그램을 만들려고하고 트리의 각 수준에 대해 서로 다른 아이콘이 있고, 여기에 기사를 다음입니다 : http://www.codeproject.com/Articles/21248/A-Simple-WPF-Explorer-TreeWPF에서 BitMapImage의 크기를 변경하고 어떤 종류의 객체를 <Image> 요소에 넣을 수 있습니까?

그것은 모두 내가 다른 갖고 싶어하는 것을 제외하고 큰 노력하고 있습니다 크기는입니다. 이미지 요소에 대한 나의 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; 
} 

가 어떻게 이미지의 크기가되는 바꿀 것 돌아왔다? 비트 맵 이미지의 크기를 변경해도 효과가없는 것 같습니다. 소스로 되돌릴 수있는 다른 이미지 개체는 무엇입니까?

+1

단순히'Image' 컨트롤의'Width'와'Height'를 설정하지 않으십니까? – Clemens

+0

당신이 속한 나무의 수준에 따라 다르니까. – Dbloom

답변

11

좋아, 나는 내 질문을 알아 냈다. 젠장, 어떡해. 아래 코드는 제가 바꾼 결과입니다.

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; 
+4

'DecodePixelWidth'와'DecodePixelHeight' 두 가지를 설정해서는 안됩니다. 이미지의 가로 세로 비율을 망칠 수 있습니다. – Clemens

+1

그것은 단지 화장품 일 뿐이지 만 팁을 주셔서 감사합니다. – Dbloom

+1

@Dbloom : Windows 7 및 Windows 10에서 작동하지만 decodePixelHeight 및 Decodepixelwidth 속성은 Windows 8에서 작동하지 않습니다. – secretgenes