【发布时间】:2011-01-23 22:58:20
【问题描述】:
您好,我无法访问资源中的图像。首先,我将一张 png 图像(心脏名称)添加到资源中。
在 app.xaml 中,将 XAML 中的资源作为静态资源。
<Application x:Class="Spirit.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Spirit.BootStraper"
xmlns:Converters="clr-namespace:Spirit.Converters"
xmlns:Controls="clr-namespace:Spirit.Controls"
xmlns:props="clr-namespace:Spirit.Properties" >
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<local:MefBootStrapper x:Key="bootstrapper" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<props:Resources x:Key="Res"/>
</ResourceDictionary>
</Application.Resources>
</Application>
And use on image from resources on image source.
<Image Name="TroubleImage"
Style="{StaticResource InfoIcon}"
Source="{Binding Source={StaticResource Res},
Path=heart,
Converter={StaticResource imageToGrayConverter}}">
If I run app I get this error:
在类型“Spirit.Properties.Resources”上找不到匹配的构造函数。您可以使用 Arguments 或 FactoryMethod 指令来构造此类型。
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at Spirit.Views.ChatView.InitializeComponent() in c:\Users\Jan\Documents\Visual Studio 2010\Projects\C#\Pokec_Messenger_Project\Pokec_Messenger\Spirit_Caliburn_Micro_v1.0\Views\ChatView.xaml:line 1
at Spirit.Views.ChatView..ctor() in C:\Users\Jan\Documents\Visual Studio 2010\Projects\C#\Pokec_Messenger_Project\Pokec_Messenger\Spirit_Caliburn_Micro_v1.0\Views\ChatView.xaml.cs:line 23
什么不好?
已编辑:
ChatView.XAML
<Window x:Class="Spirit.Views.ChatView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:Spirit.Controls"
xmlns:Micro="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
Icon="/Spirit;component/Images/Logo/Icons/Ico/32.ico"
Height="545" Width="763"
Background="{StaticResource LightGrayBackground}">
<Grid Margin="4,4,4,4">
<Grid Grid.Column="1" Margin="2,2,2,2">
<Grid.RowDefinitions>
<!--<RowDefinition Height="{Binding ElementName=InfoExpander,
Path=IsExpanded, Converter={StaticResource expandedToGridLengthConverter}}"
MaxHeight="220"/>-->
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="80"></RowDefinition>
</Grid.RowDefinitions>
<Image Name="TroubleImage"
Style="{StaticResource InfoIcon}"
Source="{Binding Source={StaticResource Res},
Path=heart,
Converter={StaticResource imageToGrayConverter}
}"/>
</Grid>
</Grid>
</Window>
chatview.xaml 中的第 23 行是 Path=heart 图像名称是 heart.png
这是我资源中的屏幕,我不知道我做错了什么?
【问题讨论】:
标签: wpf image resources static