6

ResourceDictionary画像付きのボタンのスタイルを定義しました:

<Style x:Key="BotonIrAInicioStyle" TargetType="Button">
    <Setter Property="Margin" Value="0"/>
    <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"/>
    <Setter Property="Content">
        <Setter.Value>
            <Image Margin="2" Source="{StaticResource IconoDashboardBlanco}" MaxHeight="20" Stretch="Uniform"
                   RenderOptions.BitmapScalingMode="HighQuality"/>
        </Setter.Value>
    </Setter>
</Style>

イメージ ソースはResourceDictionary同じアセンブリ内の別のファイルで定義され、次のようにマークされていx:Shared="False"ます。

<BitmapImage x:Key="IconoDashboardBlanco" x:Shared="False"
UriSource="pack://application:,,,/QualityFramework;component/Images/dashboard64X64.png"/>

スタイルは別のアセンブリで使用するため、"pack://application:,,,"表記を使用して画像を参照しました。Build Action画像の は に設定されていますResource (Do not copy to output directory)

メイン アセンブリにはUserControls、同じスタイルのボタンを表示する2 つがあります。

<Button DockPanel.Dock="Left" Style="{StaticResource BotonIrAInicioStyle}" Click="BotonIrAInicio_Click"/> (Click event has nothing to do with the problem)

問題:

画像付きのボタンを含めて開くUserControl Aと、画像が正常に表示されます。次にUserControl B、同じボタンを含む画像を開きます。もう一度開くUserControl Aと、画像が消えています。私が開いてから、最後のものが画像を「所有」UserControl Bすると同じことが起こります。UserControl A

私はどこにでも行きましたが、すべての解決策はx:Shared="False"、 、URI notationおよびを指していBuild Actionます...それらすべてを適用しましたが、問題は引き続き発生します。また、クリーニングと再構築を試みましたが、成功しませんでした。

私は何が欠けていますか?ありがとう!

PS: 両方のボタンのコンテンツを画像に直接設定すると問題なく動作しますが、スタイリングのポイントはまさにそれを避けることです!

4

2 に答える 2