Viewbox 类
TOC
折叠目录
展开目录

Viewbox Class

定义一个内容修饰器,该修饰器可拉伸和缩放单个子元素以填满可用空间。

继承

Object
  DependencyObject
    UIElement
      FrameworkElement
        Viewbox

语法


public sealed class Viewbox : FrameworkElement


<ViewBox .../>
-or-
<ViewBox ...>
  child
</ViewBox>


XAML Values

child

派生自 UIElement 且包含在此 Viewbox 中的类型的单个对象元素。请参见 Child

特性

[ContentProperty("Name=Child")]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

成员

Viewbox类 具有这些类型的成员:

构造函数

Viewbox类 具有这些构造函数。

构造函数说明
Viewbox Initializes a new instance of the Viewbox class.

 

事件

Viewbox类 具有这些事件。

事件说明
DataContextChanged Occurs when the value of the FrameworkElement.DataContext property changes. (继承自FrameworkElement)
DoubleTapped Occurs when an otherwise unhandled DoubleTap interaction occurs over the hit test area of this element. (继承自UIElement)
DragEnter Occurs when the input system reports an underlying drag event with this element as the target. (继承自UIElement)
DragLeave Occurs when the input system reports an underlying drag event with this element as the origin. (继承自UIElement)
DragOver Occurs when the input system reports an underlying drag event with this element as the potential drop target. (继承自UIElement)
Drop Occurs when the input system reports an underlying drop event with this element as the drop target. (继承自UIElement)
GotFocus Occurs when a UIElement receives focus. (继承自UIElement)
Holding Occurs when an otherwise unhandled Hold interaction occurs over the hit test area of this element. (继承自UIElement)
KeyDown Occurs when a keyboard key is pressed while the UIElement has focus. (继承自UIElement)
KeyUp Occurs when a keyboard key is released while the UIElement has focus. (继承自UIElement)
LayoutUpdated Occurs when the layout of the visual tree changes, due to layout-relevant properties changing value or some other action that refreshes the layout. (继承自FrameworkElement)
Loaded Occurs when a FrameworkElement has been constructed and added to the object tree, and is ready for interaction. (继承自FrameworkElement)
LostFocus Occurs when a UIElement loses focus. (继承自UIElement)
ManipulationCompleted Occurs when a manipulation on the UIElement is complete. (继承自UIElement)
ManipulationDelta Occurs when the input device changes position during a manipulation. (继承自UIElement)
ManipulationInertiaStarting Occurs when the input device loses contact with the UIElement object during a manipulation and inertia begins. (继承自UIElement)
ManipulationStarted Occurs when an input device begins a manipulation on the UIElement. (继承自UIElement)
ManipulationStarting Occurs when the manipulation processor is first created. (继承自UIElement)
PointerCanceled Occurs when a pointer that made contact abnormally loses contact. (继承自UIElement)
PointerCaptureLost Occurs when pointer capture previously held by this element moves to another element or elsewhere. (继承自UIElement)
PointerEntered Occurs when a pointer enters the hit test area of this element. (继承自UIElement)
PointerExited Occurs when a pointer leaves the hit test area of this element. (继承自UIElement)
PointerMoved Occurs when a pointer moves while the pointer remains within the hit test area of this element. (继承自UIElement)
PointerPressed Occurs when the pointer device initiates a Press action within this element. (继承自UIElement)
PointerReleased Occurs when the pointer device that previously initiated a Press action is released, while within this element. (继承自UIElement)
PointerWheelChanged Occurs when the delta value of a pointer wheel changes. (继承自UIElement)
RightTapped Occurs when a right-tap input stimulus happens while the pointer is over the element. (继承自UIElement)
SizeChanged Occurs when either the ActualHeight or the ActualWidth property changes value on a FrameworkElement. (继承自FrameworkElement)
Tapped Occurs when an otherwise unhandled Tap interaction occurs over the hit test area of this element. (继承自UIElement)
Unloaded Occurs when this object is no longer connected to the main object tree. (继承自FrameworkElement)

 

方法

The Viewbox 类 具有这些方法。 它还继承方法于Object 类.

方法说明
AddHandler Adds a routed event handler for a specified routed event, adding the handler to the handler collection on the current element. Specify handledEventsToo as true to have the provided handler be invoked even if the event is handled elsewhere. (继承自UIElement)
Arrange Positions child objects and determines a size for a UIElement. Parent objects that implement custom layout for their child elements should call this method from their layout override implementations to form a recursive layout update. (继承自UIElement)
ArrangeOverride Provides the behavior for the Arrange pass of layout. Classes can override this method to define their own Arrange pass behavior. (继承自FrameworkElement)
CancelDirectManipulations Cancels ongoing direct manipulation processing (system-defined panning/zooming) on any ScrollViewer parent that contains the current UIElement. (继承自UIElement)
CapturePointer Sets pointer capture to a UIElement. Once captured, only the element that has capture will fire pointer-related events. (继承自UIElement)
ClearValue Clears the local value of a dependency property. (继承自DependencyObject)
FindName Retrieves an object that has the specified identifier name. (继承自FrameworkElement)
FindSubElementsForTouchTargeting Enables a UIElement subclass to expose child elements that assist with resolving touch targeting. (继承自UIElement)
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (继承自DependencyObject)
GetBindingExpression Returns the BindingExpression that represents the binding on the specified property. (继承自FrameworkElement)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (继承自DependencyObject)
GoToElementStateCore When implemented in a derived class, enables per-state construction of a visual tree for a control template in code, rather than by loading XAML for all states at control startup. (继承自FrameworkElement)
InvalidateArrange Invalidates the arrange state (layout) for a UIElement. After the invalidation, the UIElement will have its layout updated, which will occur asynchronously. (继承自UIElement)
InvalidateMeasure Invalidates the measurement state (layout) for a UIElement. (继承自UIElement)
Measure Updates the DesiredSize of a UIElement. Typically, objects that implement custom layout for their layout children call this method from their own MeasureOverride implementations to form a recursive layout update. (继承自UIElement)
MeasureOverride Provides the behavior for the Measure pass of the layout cycle. Classes can override this method to define their own Measure pass behavior. (继承自FrameworkElement)
OnApplyTemplate Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class. (继承自FrameworkElement)
OnCreateAutomationPeer When implemented in a derived class, returns class-specific AutomationPeer implementations for the Microsoft UI Automation infrastructure. (继承自UIElement)
OnDisconnectVisualChildren Override this method to implement how layout and logic should behave when items are removed from a class-specific content or children property. (继承自UIElement)
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (继承自DependencyObject)
ReleasePointerCapture Releases pointer captures for capture of one specific pointer by this UIElement. (继承自UIElement)
ReleasePointerCaptures Releases all pointer captures held by this element. (继承自UIElement)
RemoveHandler Removes the specified routed event handler from this UIElement. Typically the handler in question was added by AddHandler. (继承自UIElement)
SetBinding Attaches a binding to a FrameworkElement, using the provided binding object. (继承自FrameworkElement)
SetValue Sets the local value of a dependency property on a DependencyObject. (继承自DependencyObject)
TransformToVisual Returns a transform object that can be used to transform coordinates from the UIElement to the specified object. (继承自UIElement)
UpdateLayout Ensures that all positions of child objects of a UIElement are properly updated for layout. (继承自UIElement)

 

属性

Viewbox类 具有这些属性。

属性访问类型说明

ActualHeight

只读Gets the rendered height of a FrameworkElement. (继承自FrameworkElement)

ActualWidth

只读Gets the rendered width of a FrameworkElement. (继承自FrameworkElement)

AllowDrop

读/写Gets or sets a value that determines whether this UIElement can be a drop target for purposes of drag-and-drop operations. (继承自UIElement)

BaseUri

只读Gets a Uniform Resource Identifier (URI) that represents the base Uniform Resource Identifier (URI) for an XAML-constructed object at XAML load time. This property is useful for Uniform Resource Identifier (URI) resolution at run time. (继承自FrameworkElement)

CacheMode

读/写Gets or sets a value that indicates that rendered content should be cached as a composited bitmap when possible. (继承自UIElement)

Child

读/写Gets or sets the single child element of a Viewbox element.

Clip

读/写Gets or sets the RectangleGeometry used to define the outline of the contents of a UIElement. (继承自UIElement)

CompositeMode

读/写Gets or sets a property that declares alternate composition and blending modes for the element in its parent layout and window. This is relevant for elements that are involved in a mixed XAML / Microsoft DirectX UI. (继承自UIElement)

DataContext

读/写Gets or sets the data context for a FrameworkElement when it participates in data binding. (继承自FrameworkElement)

DesiredSize

只读Gets the size that this UIElement computed during the measure pass of the layout process. (继承自UIElement)

Dispatcher

只读Gets the CoreDispatcher that this object is associated with. (继承自DependencyObject)

FlowDirection

读/写Gets or sets the direction in which text and other UI elements flow within any parent element that controls their layout. This property can be set to either LeftToRight or RightToLeft. Setting FlowDirection to RightToLeft on any element sets the alignment to the right, the reading order to right-to-left and the layout of the control to flow from right to left. (继承自FrameworkElement)

Height

读/写Gets or sets the suggested height of a FrameworkElement. (继承自FrameworkElement)

HorizontalAlignment

读/写Gets or sets the horizontal alignment characteristics that are applied to a FrameworkElement when it is composed in a layout parent, such as a panel or items control. (继承自FrameworkElement)

IsDoubleTapEnabled

读/写Gets or sets a value that determines whether the DoubleTapped event can originate from that element. (继承自UIElement)

IsHitTestVisible

读/写Gets or sets whether the contained area of this UIElement can return true values for hit testing. (继承自UIElement)

IsHoldingEnabled

读/写Gets or sets a value that determines whether the Holding event can originate from that element. (继承自UIElement)

IsRightTapEnabled

读/写Gets or sets a value that determines whether the RightTapped event can originate from that element. (继承自UIElement)

IsTapEnabled

读/写Gets or sets a value that determines whether the Tapped event can originate from that element. (继承自UIElement)

Language

读/写Gets or sets localization/globalization language information that applies to a FrameworkElement, and also to all child elements of the current FrameworkElement in the object representation and in UI. (继承自FrameworkElement)

ManipulationMode

读/写Gets or sets the ManipulationModes value used for UIElement behavior and interaction with gestures. Setting this value enables handling the manipulation events from this element in app code. (继承自UIElement)

Margin

读/写Gets or sets the outer margin of a FrameworkElement. (继承自FrameworkElement)

MaxHeight

读/写Gets or sets the maximum height constraint of a FrameworkElement. (继承自FrameworkElement)

MaxWidth

读/写Gets or sets the maximum width constraint of a FrameworkElement. (继承自FrameworkElement)

MinHeight

读/写Gets or sets the minimum height constraint of a FrameworkElement. (继承自FrameworkElement)

MinWidth

读/写Gets or sets the minimum width constraint of a FrameworkElement. (继承自FrameworkElement)

Name

读/写Gets or sets the identifying name of the object. When a XAML processor creates the object tree from XAML markup, run-time code can refer to the XAML-declared object by this name. (继承自FrameworkElement)

Opacity

读/写Gets or sets the degree of the object's opacity. (继承自UIElement)

Parent

只读Gets the parent object of this FrameworkElement in the object tree. (继承自FrameworkElement)

PointerCaptures

只读Gets the set of all captured pointers, represented as Pointer values. (继承自UIElement)

Projection

读/写Gets or sets the perspective projection (3-D effect) to apply when rendering this element. (继承自UIElement)

RenderSize

只读Gets the final render size of a UIElement. (继承自UIElement)

RenderTransform

读/写Gets or sets transform information that affects the rendering position of a UIElement. (继承自UIElement)

RenderTransformOrigin

读/写Gets or sets the origin point of any possible render transform declared by RenderTransform, relative to the bounds of the UIElement. (继承自UIElement)

RequestedTheme

读/写Gets or sets the UI theme that is used by the UIElement (and its child elements) for resource determination. The UI theme you specify with RequestedTheme can override the app-level RequestedTheme. (继承自FrameworkElement)

Resources

读/写Gets the locally defined resource dictionary. In XAML, you can establish resource items as child object elements of a frameworkElement.Resources property element, through XAML implicit collection syntax. (继承自FrameworkElement)

Stretch

读/写Gets or sets the Stretch mode, which determines how content fits into the available space.

StretchDirection

读/写Gets or sets the StretchDirection, which determines how scaling is applied to the contents of a Viewbox.

StretchDirectionProperty

只读Identifies the StretchDirection dependency property.

StretchProperty

只读Identifies the Stretch dependency property.

Style

读/写Gets or sets an instance Style that is applied for this object during layout and rendering. (继承自FrameworkElement)

Tag

读/写Gets or sets an arbitrary object value that can be used to store custom information about this object. (继承自FrameworkElement)

Transitions

读/写Gets or sets the collection of Transition style elements that apply to a UIElement. (继承自UIElement)

Triggers

只读Gets the collection of triggers for animations that are defined for a FrameworkElement. Not commonly used. (继承自FrameworkElement)

UseLayoutRounding

读/写Gets or sets a value that determines whether rendering for the object and its visual subtree should use rounding behavior that aligns rendering to whole pixels. (继承自UIElement)

VerticalAlignment

读/写Gets or sets the vertical alignment characteristics that are applied to a FrameworkElement when it is composed in a parent object such as a panel or items control. (继承自FrameworkElement)

Visibility

读/写Gets or sets the visibility of a UIElement. A UIElement that is not visible is not rendered and does not communicate its desired size to layout. (继承自UIElement)

Width

读/写Gets or sets the width of a FrameworkElement. (继承自FrameworkElement)

 

示例

下面的示例显示当更改 StretchDirectionViewboxStretch 属性时会发生什么情况。该示例包含三个大小不同的 Viewbox 控件。相同的图像显示在 Viewbox 控件中,以使您可以比较这些差异。可以通过单击对应于 StretchStretchDirection 枚举的值的按钮操作图像的拉伸和缩放。


<Grid Height="600" Width="600">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="auto" />
        <RowDefinition />
    </Grid.RowDefinitions>
    
    <StackPanel Grid.Row="0" Grid.Column="0" Margin="5,5,5,5" Orientation="Vertical">
        <TextBlock Text="Stretch" FontWeight="Bold" FontSize="12" />
        <Button Name="btn1" Click="stretchNone" Content="None" />
        <Button Name="btn2" Click="stretchFill" Content="Fill" />
        <Button Name="btn3" Click="stretchUni" Content="Uniform" />
        <Button Name="btn4" Click="stretchUniFill" Content="UniformToFill" />
    </StackPanel>

    <StackPanel Grid.Row="0" Grid.Column="1" Margin="5,5,5,5" Orientation="Vertical">
        <TextBlock Text="StretchDirection" FontWeight="Bold" FontSize="12" />
        <Button Name="btn5" Click="sdUpOnly" Content="UpOnly" />
        <Button Name="btn6" Click="sdDownOnly" Content="DownOnly" />
        <Button Name="btn7" Click="sdBoth" Content="Both" />
    </StackPanel>

    <StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="5" 
                Orientation="Vertical">
        <TextBlock Name="txt1" FontSize="12" FontWeight="Bold" />
        <TextBlock Name="txt2" FontSize="12" FontWeight="Bold" />
    </StackPanel>   

    <StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="5" 
                Orientation="Horizontal">
        <Viewbox MaxWidth="100" MaxHeight="100" Name="vb1">
            <Image Source="flower.jpg"/>
        </Viewbox>
        <Viewbox MaxWidth="200" MaxHeight="200" Name="vb2">
            <Image Source="flower.jpg"/>
        </Viewbox>
        
        <Viewbox MaxWidth="300" MaxHeight="300" Name="vb3">
            <Image Source="flower.jpg"/>
        </Viewbox>
    </StackPanel>

</Grid>


下面的内容展示按钮单击处理程序的代码。


//Setting the Stretch property to None
private void stretchNone(object sender, RoutedEventArgs e)
{
    vb1.Stretch = Stretch.None;
    vb2.Stretch = Stretch.None;
    vb3.Stretch = Stretch.None;
    txt1.Text = "Stretch is now set to None.";
}

//Setting the Stretch property to Fill
private void stretchFill(object sender, RoutedEventArgs e)
{
    vb1.Stretch = Stretch.Fill;
    vb2.Stretch = Stretch.Fill;
    vb3.Stretch = Stretch.Fill;
    txt1.Text = "Stretch is now set to Fill.";
}

//Setting the Stretch property to Uniform
private void stretchUni(object sender, RoutedEventArgs e)
{
    vb1.Stretch = Stretch.Uniform;
    vb2.Stretch = Stretch.Uniform;
    vb3.Stretch = Stretch.Uniform;
    txt1.Text = "Stretch is now set to Uniform.";
}

//Setting the Stretch property to UniformToFill
private void stretchUniFill(object sender, RoutedEventArgs e)
{
    vb1.Stretch = Stretch.UniformToFill;
    vb2.Stretch = Stretch.UniformToFill;
    vb3.Stretch = Stretch.UniformToFill;
    txt1.Text = "Stretch is now set to UniformToFill.";
}

//Setting the StretchDirection property to UpOnly
private void sdUpOnly(object sender, RoutedEventArgs e)
{
    vb1.StretchDirection = StretchDirection.UpOnly;
    vb2.StretchDirection = StretchDirection.UpOnly;
    vb3.StretchDirection = StretchDirection.UpOnly;
    txt2.Text = "StretchDirection is now UpOnly.";
}

//Setting the StretchDirection property to DownOnly
private void sdDownOnly(object sender, RoutedEventArgs e)
{
    vb1.StretchDirection = StretchDirection.DownOnly;
    vb2.StretchDirection = StretchDirection.DownOnly;
    vb3.StretchDirection = StretchDirection.DownOnly;
    txt2.Text = "StretchDirection is now DownOnly.";
}

//Setting the StretchDirection property to Both
private void sdBoth(object sender, RoutedEventArgs e)
{
    vb1.StretchDirection = StretchDirection.Both;
    vb2.StretchDirection = StretchDirection.Both;
    vb3.StretchDirection = StretchDirection.Both;
    txt2.Text = "StretchDirection is now Both.";
}


要求

最低支持客户端

Windows 8 [仅 Windows 应用商店应用程序]

最低支持服务器

Windows Server 2012 [仅 Windows 应用商店应用程序]

命名空间

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

元数据

Windows.winmd

另请参见

FrameworkElement

 

 

显示:
© 2018 Microsoft