C# 资源项目中的图像未加载到嵌套控件中
为了简洁起见,我删除了一些代码,但我的问题是,在运行时,并没有在包含的控件中从资源项目加载图像。xaml与映像位于不同的项目中,但两者位于同一个解决方案中,并且xaml项目将资源项目作为参考 图像从Source=/ThinkVisual.Resources加载;component/Images/save.png/但其中有一个未加载的图像C# 资源项目中的图像未加载到嵌套控件中,c#,wpf,xaml,runtime,embedded-resource,C#,Wpf,Xaml,Runtime,Embedded Resource,为了简洁起见,我删除了一些代码,但我的问题是,在运行时,并没有在包含的控件中从资源项目加载图像。xaml与映像位于不同的项目中,但两者位于同一个解决方案中,并且xaml项目将资源项目作为参考 图像从Source=/ThinkVisual.Resources加载;component/Images/save.png/但其中有一个未加载的图像 <Button x:Name="btnAddOwnerDetails" ToolTip="Add Owner/Management details" Cl
<Button x:Name="btnAddOwnerDetails" ToolTip="Add Owner/Management details" Click="btnAddOwnerDetails_Click">
<Image Width="16" Height="16" Source="/ThinkVisual.Resources;component/Images/add_button.png" />
</Button>
父控件和子控件都位于同一项目和文件夹中
<lc:LayoutGroup x:Name="layoutCompanyDetails" Header="Company Details" View="GroupBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Vertical" <lc:LayoutGroup x:Name="tabCompanyDetails" View="Tabs" SelectedTabChildChanged="tabCompanyDetails_SelectedTabChildChanged">
<lc:LayoutGroup Header="Details">
<my:CompanyDetails x:Name="controlCompanyDetails" />
</lc:LayoutGroup>
<lc:LayoutGroup Header="Owner/Management Details">
<my:OwnerDetails x:Name="controlOwnerDetails" />
</lc:LayoutGroup>
</lc:LayoutGroup>
<lc:LayoutItem>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Name="btnUpdate" ToolTip="Update company details" Padding="0" Margin="0" Width="65" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave" IsEnabled="{Binding Path=AllPropertiesValid}" Click="btnUpdate_Click">
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Width="16" Height="16" Source="/ThinkVisual.Resources;component/Images/save.png"/>
<Label x:Name="lblSaveButton" Padding="2">Update</Label>
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</lc:LayoutItem>
这些图像在Visual Studio中可见,但在执行、项目生成和运行期间不会显示,不会出错。您使用了错误的
确保将自定义控件库中的映像设置为“资源生成操作”,并为“复制到输出目录”设置为“False”
然后更改图像。源为:
如果您在ThinkVisual.Resources中使用的控件使用相同的图像,则将第一个代码段用作源。是否将“复制到输出目录”属性设置为“始终复制”?XAML在ThinkVisual.Administration项目中,图像在ThinkVisual.Resources项目中。每个映像的生成操作都设置为resource,并将其设置为copy always。相同的映像显示在父控件中,但不显示在子控件中。如果映像文件的生成操作设置为“资源”,则会将其添加到输出程序集中。这样就不必将其复制到输出目录。因此,复制到输出目录应设置为“不复制”。
<Image Width="16"
Height="16"
Source="pack//application:,,,/ThinkVisual.Resources;component/Images/add_button.png" />
Source="pack//application:,,,/ThinkVisual.Adminstration;component/Images/add_button.png"