XAMLでImageBrush
を使用して、Grid
に背景を適用したいとします。ImageBrushを使用したグリッド背景画像
私はブラシにx:Key
を与え、私のグリッドでそれを参照したいと思います。
悲しいことに、悲しいことに、画像としては全くバックグラウンドとして登場しません。
<Window.Resources>
<ImageBrush ImageSource="/MAQButtonTest;component/images/bird_text_bg.jpg" x:Key="BackgroundSponge" />
<Style TargetType="TextBlock">
<Setter Property="OverridesDefaultStyle" Value="True"/>
</Style>
<ControlTemplate TargetType="Button" x:Key="ButtonTemplate">
<Grid Width="444" ShowGridLines="False" SnapsToDevicePixels="True" Background="{DynamicResource BackgroundSponge}">
<Grid.RowDefinitions>
<RowDefinition Height="51" />
<RowDefinition Height="36" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="#286c97">
</Grid>
<Grid Grid.Row="1" Background="#5898c0">
<ContentPresenter Grid.Row="0" />
</Grid>
</Grid>
</ControlTemplate>
</Window.Resources>
私はおそらく私がDynamicResource
とStaticResource
を試してみた、間違った方法でそれを参照すると思います。
どのようにプロジェクトにあなたの背景画像を含むされていますか? 'ImageSource =" pack:// application:,,,/component/images/bird_text_bg.jpg "' – paul
あなたが直接指定した場合、ImageSourceは次のようになります。 (リソースを使用するのではなく)表示されますか? – Tim
それは奇妙なことです。私はそれをコンテンツに設定し、Visual Studioで画像を持っています。私は単にプロパティペインの "ImageSource"のためにビジュアルスタジオ内の楕円形のボタンを使用して、自動的にそのパスを生成しました。 – Luke