我希望在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
。
你怎麼包括項目中的背景圖片?如果它被包含爲'Content',那麼我會期望你的ImageSource看起來更像這樣:''ImageSource =「pack:// application:,,,/component/images/bird_text_bg.jpg」' – paul
如果你直接指定它(而不是使用資源)是否顯示? – Tim
這是奇怪的事情。我已將它設置爲內容並在Visual Studio中具有圖像。我只是在Visual Studio中使用屬性窗格中的「ImageSource」的橢圓按鈕,然後它爲我自動生成該路徑。 – Luke