を使用してカスタム リソースを再利用しようとしてComponentResourceKey
いますが、機能せず、次の警告が表示されます。
Warning 12 The resource "{ComponentResourceKey ResourceId=SadTileBrush, TypeInTargetAssembly={x:Type res:CustomResources}}" could not be resolved.
は次のResourceLibrary/Themes/generic.xaml
とおりです。
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ResourceLibrary">
<ImageBrush x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:CustomResources},
ResourceId=MyBrush}"
ImageSource="ResourceLibrary;component/../../myImage.jpg">
</ImageBrush>
</ResourceDictionary>
そしてResourceLibrary/CustomResources.cs
:
namespace ResourceLibrary{
public class CustomResources{}
}
使用方法は次のとおりです(SomeOtherProject/MyWindow.xaml
)。
<Button Background="{DynamicResource {ComponentResourceKey
TypeInTargetAssembly={x:Type res:CustomResources},
ResourceId=MyBrush}}"> Some text </Button>
なぜ「リソースを解決できませんでした」?
SO の質問 " Getting a ComponentResourceKey to Work? "を認識していることに注意してください。