Why is an image resource in a class library not loaded?

后端 未结 1 692
天命终不由人
天命终不由人 2020-12-12 07:06

I have strange problem, which I don\'t know how to find - I looked for similair posts here, but failed.

Problem is that I have custom control in WPF and, obviously,

相关标签:
1条回答
  • 2020-12-12 08:03

    Use a full Resource File Pack URI, including the assembly name (not the namespace) of your UserControl library, as shown below.

    Otherwise WPF resolves the Pack URI with the name of the "local" assembly, which may be that of the main application.

    Source="pack://application:,,,/SampleControls;component/Images/boxImage.png"
    

    Also make sure that the Build Action of the image file is set to Resource.


    As a note, setting Panel.ZIndex is pointless here. The elements are stacked by default in the order they are declared in XAML, so the TextBlock is always on top of the Image, even without setting ZIndex.

    0 讨论(0)
提交回复
热议问题