語言

TileBrush.Viewbox 屬性

定義

取得或設定內容在圖塊中 TileBrush 的位置和尺寸。

public:
 property System::Windows::Rect Viewbox { System::Windows::Rect get(); void set(System::Windows::Rect value); };
public System.Windows.Rect Viewbox { get; set; }
member this.Viewbox : System.Windows.Rect with get, set
Public Property Viewbox As Rect

屬性值

內容的位置與尺寸 TileBrush 。 預設值為矩形(Rect),其 a TopLeft 為 (0,0), a Width 和 Height 為 1。

範例

你可以透過屬性TileBrush指定內容的Viewbox大小和位置。 性質 ViewboxUnits 決定了該 Viewbox 值是相對於內容的邊界 TileBrush ,還是絕對值。

第一張插圖展示了一張 100 x 100 像素的圖片,然後用這張圖片來展示不同 Viewbox 屬性設定的影響。

一幅影像 起始取樣影像(100 x 100 裝置獨立像素)

下圖顯示使用 TileBrush a 為 0.0,0.0.0、0.25、0.5 的輸出Viewbox。 其他相關房產價值包括以下幾項:

這張圖展示了幾種不同的 Stretch 屬性設定。 性質 Stretch 決定了如何 TileBrush 拉伸 它 Viewbox 以填滿其 Viewport。

視圖框為 0,0 0.25,0.5 視筆具有相對視框 0.0,0.0.0, 0.25,0.5 的 TileBrush

下圖顯示類似 TileBrush ,但相對 Viewbox 值為0.5,0.25,0.25,0.5。

視框為 0.5,0.25 的 TileBrush 視框為 類似的 TileBrush,但 Viewbox 設定不同

下圖示相同 TileBrush ,但相對 Viewport 值為 0.0,0.0,0.5,0.5,a TileMode 為 Tile。

TiledTileBrush 視框為 0.5,0.25 0.25,0.5 類似的 TileBrush,但有平鋪和不同的 Viewport 設定

以下範例說明如何建立 a TileBrush 為 0.5、0.25、0.25、0.5 的磁磚Viewbox。

<Rectangle
 Width="100" Height="100">
  <Rectangle.Fill>
    <ImageBrush 
      ImageSource="sampleImages\testImage.gif"
      Viewbox="0.5,0.25, 0.25,0.5" 
      ViewboxUnits="RelativeToBoundingBox" 
      Viewport="0,0,0.5,0.5"
      ViewportUnits="RelativeToBoundingBox" 
      TileMode="Tile" 
      Stretch="Fill" 
      AlignmentX="Center"
      AlignmentY="Center"/>
  </Rectangle.Fill>
</Rectangle>
// Create a rectangle.
Rectangle myRectangle = new Rectangle();
myRectangle.Width = 100;
myRectangle.Height = 100;

// Load the image.
BitmapImage theImage = 
    new BitmapImage(
        new Uri("sampleImages\\testImage.gif", UriKind.Relative));   
ImageBrush myImageBrush = new ImageBrush(theImage);

myImageBrush.Viewbox = new Rect(0.5, 0.25, 0.25, 0.5);
myImageBrush.ViewboxUnits = BrushMappingMode.RelativeToBoundingBox;
myImageBrush.Viewport = new Rect(0,0,0.25,0.25);
myImageBrush.ViewportUnits = BrushMappingMode.RelativeToBoundingBox;
myImageBrush.TileMode = TileMode.Tile;
myImageBrush.Stretch = Stretch.Fill;
myImageBrush.AlignmentX = AlignmentX.Center;
myImageBrush.AlignmentY = AlignmentY.Center;

// Use the ImageBrush to paint the rectangle's background.
myRectangle.Fill = myImageBrush;
' Create a rectangle.
Dim myRectangle As New Rectangle()
myRectangle.Width = 100
myRectangle.Height = 100

' Load the image.
Dim theImage As New BitmapImage(New Uri("sampleImages\testImage.gif", UriKind.Relative))
Dim myImageBrush As New ImageBrush(theImage)
With myImageBrush
    .Viewbox = New Rect(0.5, 0.25, 0.25, 0.5)
    .ViewboxUnits = BrushMappingMode.RelativeToBoundingBox
    .Viewport = New Rect(0, 0, 0.25, 0.25)
    .ViewportUnits = BrushMappingMode.RelativeToBoundingBox
    .TileMode = TileMode.Tile
    .Stretch = Stretch.Fill
    .AlignmentX = AlignmentX.Center
    .AlignmentY = AlignmentY.Center
End With

' Use the ImageBrush to paint the rectangle's background.
myRectangle.Fill = myImageBrush

備註

當你用 來 TileBrush繪製區域時,你會使用三個元件:內容、圖塊和輸出區域。 該 Viewbox 性質指定內容的大小與位置 TileBrush 。 以下圖示展示了這三個 TileBrush 成分之間的關係。

TileBrush 元件 TileBrush 元件

拼貼圖塊的組成部分 部分

此 ViewboxUnits 性質決定該值是 Viewbox 相對值還是絕對值。 預設情況下,屬性 ViewboxUnits 設定為 RelativeToBoundingBox。

Viewbox 裁剪

TileBrush 內容絕不會被夾在 Viewbox。 然而, TileBrush 內容 會被 裁剪到 ,該 的邊緣 Viewport會設定基礎圖塊的值。

下圖展示了不同 Stretch 設定對 TileBrushViewbox a 小於其 Viewport的 的影響。 影像中 Viewbox 外面的部分呈現灰色調。

使用不同拉伸設定的 TileBrush 搭配不同的拉伸設定

相依財產資訊

Item 價值觀
識別碼欄位 ViewboxProperty
元資料屬性設為 true None

適用於

另請參閱