Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

WPFアプリケーションに組み込んだリソースをマークアップから参照する

前回(以下のエントリー)アプリケーションに組み込んだリソースをマークアップから参照します。
リソースをWPFアプリケーションに組み込む - プログラマーな日々
リソースを3種類の方法でWPFアプリケーションに組み込みます。 ...

MainWindow.xaml

<Window x:Class="HelloWorld.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="900">
    <StackPanel Orientation="Horizontal">
        <Image Source="images/content-image.jpg" Width="300" />             <!-- OK -->
        <Image Source="images/resource-image.jpg" Width="300" />            <!-- OK -->
        <!--<Image Source="images/embedded-image.jpg" Width="300" /> -->    <!-- ビルドエラー -->
    </StackPanel>
</Window>

参考

エッセンシャル WPF P.64より引用

リソースまたはコピーされたコンテンツについては、マークアップから相対パスとして単純に参照できます。EmbeddedResource項目については、マークアップを通じて直接アクセスすることはできません。