Image.Stretch 属性

定义

获取或设置一个值,该值描述应如何拉伸 Image 以填充目标矩形。

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

属性值

Stretch

Stretch 值之一。 默认值为 Uniform

示例

下面的示例演示如何使用此属性。

Image myImage1 = new Image();

// Set the stretch property.
myImage1.Stretch = Stretch.Fill;

// Set the StretchDirection property.
myImage1.StretchDirection = StretchDirection.Both;

// Create source
BitmapImage myBitmapImage1 = new BitmapImage();

// BitmapImage.UriSource must be in a BeginInit/EndInit block
myBitmapImage1.BeginInit();
myBitmapImage1.UriSource = new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg");
myBitmapImage1.EndInit();

//set image source
myImage1.Source = myBitmapImage1;
Dim myImage1 As New Image()

' Set the stretch property.
myImage1.Stretch = Stretch.Fill

' Set the StretchDirection property.
myImage1.StretchDirection = StretchDirection.Both

' Create source
Dim myBitmapImage1 As New BitmapImage()

' BitmapImage.UriSource must be in a BeginInit/EndInit block
myBitmapImage1.BeginInit()
myBitmapImage1.UriSource = New Uri("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
myBitmapImage1.EndInit()

'set image source
myImage1.Source = myBitmapImage1

注解

Fill 将导致图像拉伸以完全填充输出区域。 当输出区域和图像的纵横比不同时,图像就会因拉伸而失真。 Image若要保留图像的纵横比,请将此属性设置为Uniform (默认) 或UniformToFill

依赖项属性信息

标识符字段 StretchProperty
元数据属性设置为 true AffectsMeasure

适用于

另请参阅