0
MVVM 프로젝트에서 내 디자이너에 문제가 있습니다. IOException : 디자인 타임에만 리소스를 찾을 수 없음
내가 정의DataTemplate
와
TreeView
있습니다
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Name="img" Width="20" Height="20" Stretch="Fill"
Source="{Binding
RelativeSource={RelativeSource
Mode=FindAncestor,
AncestorType={x:Type TreeViewItem}},
Path=Header,
Converter={StaticResource HeaderToImageConverter}}"
/>
<TextBlock Text="{Binding}" Margin="5,0" />
</StackPanel>
</DataTemplate>
자원 선언 :
<Window x:Class="BlobWorld.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Core="clr-namespace:BlobWorld;assembly="
xmlns:helper="clr-namespace:BlobWorld.Helper"
mc:Ignorable="d"
Title="MainWindow" Height="350.459" Width="746.561"
DataContext="{DynamicResource MainWindowViewModel}">
<Window.Resources>
<helper:HeaderToImageConverter x:Key="HeaderToImageConverter"/>
</Window.Resources>
내 변환기는 다음과 같습니다
public class HeaderToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((value as string).Contains(@"."))
{
Uri uri = new Uri("pack://application:,,,/images/File.png");
BitmapImage source = new BitmapImage(uri);
return source;
}
else
{
if (!(value as string).Contains(@":"))
{
Uri uri = new Uri("pack://application:,,,/images/folder.png");
BitmapImage source = new BitmapImage(uri);
return source;
}
else
{
Uri uri = new Uri("pack://application:,,,/images/diskdrive.png");
BitmapImage source = new BitmapImage(uri);
return source;
}
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException("Cannot convert back");
}
}
그것은 런타임에서 완벽하게 작동하지만, Visual Studio에서 xaml "디자인"창을 사용할 때 내 Windows의 모습을보고, 전 단지 가지고 IOException : Cannot locate resource 'images/folder.png'
어디에서 오는 내 문제는 무엇입니까? 어떻게 해결할 수 있습니까?
가장 쉬운 수정 프로그램입니다 컨버터 (http://stackoverflow.com/a/834332/1997232) [디자인 모드를 감지]와 같은 경우 이미지를 해결하려고하지 않습니다 (귀국일'null'에). – Sinatr
http://stackoverflow.com/a/11948876/3955716 – Rom
@Sinatr 작동하는 경우 okayish, 이제 내 Windows를 볼 수 있지만 (null을 반환하면 ...) 내 이미지가 표시되지 않으므로 여전히 성가신 상태입니다. 내 렌더링의 아이디어. 디자인 모드와 관련된 코드로 이미지를 반환 할 수있는 방법이 있다면 대답으로 받아 들일 것입니다. – Belterius