2012-08-30 47 views
0

我有一個非常簡單的XAML的兩個變種。首先,這裏是用純色畫筆繪製畫布背景的變體。當SolidColorBrush是CanvasBackground時,爲什麼Silverlight Canvas ImageBrush不可見?

<UserControl x:Class="CanvasBackground.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    d:DesignHeight="300" d:DesignWidth="400"> 

    <Grid x:Name="LayoutRoot"> 
     <Canvas x:Name="SeedCanvas"> 
      <Canvas.Background> 
       <SolidColorBrush Color="Aquamarine" /> 
      </Canvas.Background> 
     </Canvas> 
    </Grid> 
</UserControl> 

此託管到一個相當簡單的HTML頁面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
<title>CanvasBackground</title> 
<style type="text/css"> 
    html, body { 
     height: 100%; 
     overflow: auto; 
    } 
    body { 
     padding: 0; 
     margin: 0; 
    } 
    #silverlightControlHost { 
     height: 100%; 
     text-align:center; 
    } 
</style> 
</head> 
<body> 
<form id="form1" runat="server" style="height:100%"> 
<div id="silverlightControlHost"> 
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> 
     <param name="source" value="ClientBin/CanvasBackground.xap"/> 
     <param name="background" value="transparent" /> 
    </object> 
</div> 
</form> 
</body> 
</html> 

當我編譯,並打開我看看我想到,空海藍寶石的頁面。但是,如果我將XAML更改爲使用ImageBrush代替SolidColorBrush,則此頁面爲黑色。圖像顯示在設計視圖中(大概是因爲它具有設定時間的高度和寬度),但不在頁面中。

<UserControl x:Class="CanvasBackground.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    d:DesignHeight="300" d:DesignWidth="400"> 

    <Grid x:Name="LayoutRoot"> 
     <Canvas x:Name="SeedCanvas"> 
      <Canvas.Background> 
       <ImageBrush ImageSource="/images/Autum.jpg" Stretch="Fill"/> 
      </Canvas.Background> 
     </Canvas> 
    </Grid> 
</UserControl> 

回答

0

關鍵在於Silverlight項目中圖像的屬性「構建操作」。我將它設置爲「資源」,並將其更改爲「內容」修復了此問題。

相關問題