Image 类
2013/12/13
表示显示 JPEG 或 PNG 文件格式的图像的控件。
System.Windows.DependencyObject
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Image
程序集: System.Windows(位于 System.Windows.dll 中)
XMLNS for XAML: 未映射到 xmlns。
Image 类型公开以下成员。
名称 | 说明 | |
---|---|---|
![]() | ActualHeight | 获取 FrameworkElement 的呈现高度。 (从 FrameworkElement 继承。) |
![]() | ActualWidth | 获取 FrameworkElement 的呈现宽度。 (从 FrameworkElement 继承。) |
![]() | AllowDrop | 获取或设置一个值,该值确定此 UIElement 是否可用作拖放操作的放置目标。 (从 UIElement 继承。) |
![]() | CacheMode | 获取或设置一个值,该值指示应在可能时缓存已呈现内容。 (从 UIElement 继承。) |
![]() | Clip | 获取或设置用于定义 UIElement 的内容边框的 Geometry。 (从 UIElement 继承。) |
![]() | Cursor | 基础结构。 获取或设置指针悬停在 FrameworkElement 上时所显示的光标图像。 (从 FrameworkElement 继承。) |
![]() | DataContext | 获取或设置 FrameworkElement 参与数据绑定时的数据上下文。 (从 FrameworkElement 继承。) |
![]() | DesiredSize | 获取此 UIElement 在布局过程的测量处理过程中计算的大小。 (从 UIElement 继承。) |
![]() | Dispatcher | 获取与此对象关联的 Dispatcher。 (从 DependencyObject 继承。) |
![]() | FlowDirection | 获取或设置文本和其他用户界面元素在控制其布局的任何父元素中的流动方向。 (从 FrameworkElement 继承。) |
![]() | Height | 获取或设置 FrameworkElement 的建议高度。 (从 FrameworkElement 继承。) |
![]() | HorizontalAlignment | 获取或设置在布局父级(如面板或项控件)中构成 FrameworkElement 时应用于此元素的水平对齐特征。 (从 FrameworkElement 继承。) |
![]() | IsHitTestVisible | 获取或设置此 UIElement 的包含区域是否可为命中测试返回 true 值。 (从 UIElement 继承。) |
![]() | Language | 获取或设置应用于 FrameworkElement 的本地化/全球化语言信息。 (从 FrameworkElement 继承。) |
![]() | Margin | 获取或设置 FrameworkElement 的外边距。 (从 FrameworkElement 继承。) |
![]() | MaxHeight | 获取或设置 FrameworkElement 的最大高度约束。 (从 FrameworkElement 继承。) |
![]() | MaxWidth | 获取或设置 FrameworkElement 的最大宽度约束。 (从 FrameworkElement 继承。) |
![]() | MinHeight | 获取或设置 FrameworkElement 的最小高度约束。 (从 FrameworkElement 继承。) |
![]() | MinWidth | 获取或设置 FrameworkElement 的最小宽度约束。 (从 FrameworkElement 继承。) |
![]() | Name | 获取或设置对象的标识名称。 当 XAML 处理器从标记创建对象树时,运行时代码可以使用此名称引用标记元素。 (从 FrameworkElement 继承。) |
![]() | Opacity | 获取或设置对象的不透明度。 (从 UIElement 继承。) |
![]() | OpacityMask | 获取或设置用于改变此对象区域的不透明度的画笔。 (从 UIElement 继承。) |
![]() | Parent | 获取对象树中此 FrameworkElement 的父对象。 (从 FrameworkElement 继承。) |
![]() | Projection | 获取或设置在呈现此 UIElement 时要应用的透视投影(三维效果)。 (从 UIElement 继承。) |
![]() | RenderSize | 获取 UIElement 的最终呈现大小。 (从 UIElement 继承。) |
![]() | RenderTransform | 获取或设置影响 UIElement 的呈现位置的变换信息。 (从 UIElement 继承。) |
![]() | RenderTransformOrigin | 获取或设置由 RenderTransform 声明的任何可能呈现转换的原点,相对于 UIElement 的边界。 (从 UIElement 继承。) |
![]() | Resources | 获取本地定义的资源字典。 在 XAML 中,可以通过 XAML 隐式集合语法,将资源项建立为 frameworkElement.Resources 属性元素的子对象元素。 (从 FrameworkElement 继承。) |
![]() | Source | 获取或设置图像的源。 |
![]() | Stretch | 获取或设置一个值,该值描述应如何拉伸 Image 以填充目标矩形。 |
![]() | Style | 获取或设置呈现过程中应用于此对象的实例 Style。 (从 FrameworkElement 继承。) |
![]() | Tag | 获取或设置一个可用于存储有关此对象的自定义信息的任意对象值。 (从 FrameworkElement 继承。) |
![]() | Triggers | 获取为 FrameworkElement 定义的动画的触发器的集合。 (从 FrameworkElement 继承。) |
![]() | UseLayoutRounding | 获取或设置一个值,该值确定对象及其可视化子树的呈现是否应使用将呈现与整像素对齐的舍入行为。 (从 UIElement 继承。) |
![]() | UseOptimizedManipulationRouting | 获取或设置指示系统是否应处理输入事件或是否 FrameworkElement 应处理输入事件的值。 (从 FrameworkElement 继承。) |
![]() | VerticalAlignment | 获取或设置在父对象(如面板或项控件)中构成 FrameworkElement 时应用于此元素的垂直对齐特征。 (从 FrameworkElement 继承。) |
![]() | Visibility | 获取或设置 UIElement 的可见性。不可见的 UIElement 不呈现,也不将其所需大小告知布局。 (从 UIElement 继承。) |
![]() | Width | 获取或设置 FrameworkElement 的宽度。 (从 FrameworkElement 继承。) |
名称 | 说明 | |
---|---|---|
![]() | AddHandler | 为指定的路由事件添加路由事件处理程序,并将该处理程序添加到当前元素的处理程序集合中。将 handledEventsToo 指定为 true 时,可为已标记为由其他元素在事件路由过程中处理的路由事件调用所提供的处理程序。 (从 UIElement 继承。) |
![]() | Arrange | 定位子对象并确定 UIElement 的大小。为其子元素实现自定义布局的父对象应从其布局重写实现调用此方法以形成递归布局更新。 (从 UIElement 继承。) |
![]() | ArrangeOverride | 提供 Windows Phone 布局的排列处理过程的行为。 类可以重写该方法来定义其自己的排列处理过程行为。 (从 FrameworkElement 继承。) |
![]() | CaptureMouse | 将触摸输入捕获设置为 UIElement。 (从 UIElement 继承。) |
![]() | CheckAccess | 确定调用线程是否可以访问此对象。 (从 DependencyObject 继承。) |
![]() | ClearValue | 清除依赖项属性的本地值。 (从 DependencyObject 继承。) |
![]() | Equals(Object) | 确定指定的 Object 是否等于当前的 Object。 (从 Object 继承。) |
![]() | Finalize | 允许 Object 在垃圾回收器回收该对象之前尝试释放资源并执行其他清理操作。 (从 Object 继承。) |
![]() | FindName | 检索具有指定标识符名称的对象。 (从 FrameworkElement 继承。) |
![]() | GetAnimationBaseValue | 返回为 Windows Phone 依赖项属性设置的任意基值,在动画不活动时将应用它们。 (从 DependencyObject 继承。) |
![]() | GetBindingExpression | 检索 BindingExpression 中已建立绑定的依赖项属性。 (从 FrameworkElement 继承。) |
![]() | GetHashCode | 用作特定类型的哈希函数。 (从 Object 继承。) |
![]() | GetType | 获取当前实例的 Type。 (从 Object 继承。) |
![]() | GetValue | 从 DependencyObject 返回依赖项属性的当前有效值。 (从 DependencyObject 继承。) |
![]() | InvalidateArrange | 使 UIElement 的排列状态(布局)无效。使其无效后,将会更新 UIElement 的布局(以异步方式进行)。 (从 UIElement 继承。) |
![]() | InvalidateMeasure | 使 UIElement 的测量状态(布局)无效。 (从 UIElement 继承。) |
![]() | Measure | 更新 UIElement 的 DesiredSize。一般地,实现其布局子级的自定义布局的对象从自己的 MeasureOverride 实现调用此方法以形成递归布局更新。 (从 UIElement 继承。) |
![]() | MeasureOverride | 提供 Windows Phone 布局的度量处理过程的行为。 类可以重写该方法来定义其自己的度量处理过程行为。 (从 FrameworkElement 继承。) |
![]() | MemberwiseClone | 创建当前 Object 的浅表副本。 (从 Object 继承。) |
![]() | OnApplyTemplate | 在派生类中重写后,每当应用程序代码或内部进程(如重新生成布局处理过程)调用 ApplyTemplate,都将调用此方法。 简而言之,这意味着就在 UI 元素在应用程序中显示前调用该方法。 有关更多信息,请参见“备注”。 (从 FrameworkElement 继承。) |
![]() | OnCreateAutomationPeer | 在派生类中实现时,为 Windows Phone 自动化基础结构返回类特定的 AutomationPeer 实现。 (从 UIElement 继承。) |
![]() | ReadLocalValue | 返回依赖项属性的本地值(如果设置了本地值)。 (从 DependencyObject 继承。) |
![]() | ReleaseMouseCapture | 从 UIElement 中移除触摸输入捕获。在此调用后,一般没有对象具有触摸输入捕获。 (从 UIElement 继承。) |
![]() | RemoveHandler | 从此 UIElement 中移除指定的路由事件处理程序。 (从 UIElement 继承。) |
![]() | SetBinding | 使用提供的绑定对象,将绑定附加到 FrameworkElement 上,并返回 BindingExpressionBase 以供以后使用。 (从 FrameworkElement 继承。) |
![]() | SetValue | 对 DependencyObject 设置依赖项属性的本地值。 (从 DependencyObject 继承。) |
![]() | ToString | 返回一个字符串,它表示当前的对象。 (从 Object 继承。) |
![]() | TransformToVisual | 返回一个变换对象,该变换对象可用于将 UIElement 中的坐标变换为指定的对象。 (从 UIElement 继承。) |
![]() | UpdateLayout | 请确保 UIElement 的所有子对象位置都正确地进行了布局更新。 (从 UIElement 继承。) |
名称 | 说明 | |
---|---|---|
![]() | BindingValidationError | 在绑定源报告数据验证错误时发生。 (从 FrameworkElement 继承。) |
![]() | DoubleTap | 当悬停在此 UIElement 上时使用了DoubleTap 笔势的情况下发生。 (从 UIElement 继承。) |
![]() | GotFocus | 当 UIElement 收到焦点时发生。 (从 UIElement 继承。) |
![]() | Hold | 当悬停在此 UIElement 上时使用了 Hold 笔势的情况下发生。 (从 UIElement 继承。) |
![]() | ImageFailed | 当存在与图像检索或格式相关的错误时发生。 |
![]() | ImageOpened | 在成功下载和解码图像源后发生。可在呈现图像前使用此事件确定图像的大小。 |
![]() | KeyDown | 在 UIElement 具有焦点的情况下按下键盘上的某个键时发生。 (从 UIElement 继承。) |
![]() | KeyUp | 在 UIElement 具有焦点的情况下释放键盘上的某个键时发生。 (从 UIElement 继承。) |
![]() | LayoutUpdated | 当 Windows Phone 可视化树的布局更改时发生。 (从 FrameworkElement 继承。) |
![]() | Loaded | 当已构造 FrameworkElement 并将其添加到对象树中时发生。 (从 FrameworkElement 继承。) |
![]() | LostFocus | 当 UIElement 失去焦点时发生。 (从 UIElement 继承。) |
![]() | LostMouseCapture | 在 UIElement 失去触摸屏输入捕获时发生。 (从 UIElement 继承。) |
![]() | ManipulationCompleted | 对于 UIElement 的操作和延时完毕时发生。 (从 UIElement 继承。) |
![]() | ManipulationDelta | 当输入设备在操作期间更改位置时发生。 (从 UIElement 继承。) |
![]() | ManipulationStarted | 当输入设备对 UIElement 开始操作时发生。 (从 UIElement 继承。) |
![]() | MouseEnter | 当在 UIElement 界定区域内点按屏幕时发生。 (从 UIElement 继承。) |
![]() | MouseLeave | 当在 UIElement 界定区域外发生触摸事件时发生。 (从 UIElement 继承。) |
![]() | MouseLeftButtonDown | 在点按 UIElement 时发生。 (从 UIElement 继承。) |
![]() | MouseLeftButtonUp | 当手指抬离 UIElement 时(或当 UIElement 具有触摸输入捕获时)发生。 (从 UIElement 继承。) |
![]() | MouseMove | 在以下情况下发生:当触摸 UIElement 时(或当 UIElement 具有触摸输入捕获时),手指的坐标位置位于屏幕上。 (从 UIElement 继承。) |
![]() | MouseWheel | 基础结构。 在以下情况下发生:当鼠标指针悬停在 UIElement 上时或 UIElement 具有焦点时,用户滚动鼠标滚轮。 (从 UIElement 继承。) |
![]() | SizeChanged | 当 FrameworkElement 上的 ActualHeight 或 ActualWidth 属性的值发生更改时发生。 (从 FrameworkElement 继承。) |
![]() | Tap | 当悬停在此 UIElement 上时使用了 Tap 笔势的情况下发生。 (从 UIElement 继承。) |
![]() | TextInput | 在 UI 元素以与设备无关的方式获取文本时发生。 (从 UIElement 继承。) |
![]() | TextInputStart | 在 UI 元素以与设备无关的方式最初获取文本时发生。 (从 UIElement 继承。) |
![]() | TextInputUpdate | 当通过输入方法编辑器 (IME) 继续编写文本时发生。 (从 UIElement 继承。) |
![]() | Unloaded | 当此对象不再与主对象树连接时发生。 (从 FrameworkElement 继承。) |
可以通过指定绝对 URL(例如,http://contoso.com/myPicture.jpg)来设置 Source,也可以指定相对于应用程序的 XAP 文件的 URL。
如果未设置 Height 和 Width,则 Image 将使用自然高度和其源图像文件的宽度进行显示。
如果 Source 属性设置为无效格式,或者被指定为未正确构造的 ImageSource,则将引发 ImageFailed 事件。
Image 可能具有异步行为。如果通过直接在 XAML 中指定 URI 来设置 Source,或者将其设置为正在使用 URI 新构造的 BitmapImage,则会发生这种情况。在对源进行解析和对图像源进行解码之前,如果布局未指定 Height 和 Width,将发生布局,但会将图像视为大小为 0 的元素;或者,如果指定了 Height 和 Width,则会将图像视为该大小的空白区域。在解析 URI 和对图像源进行解码之后,将启动另一个布局处理过程。
Windows Phone 使用位图缓存。因此,如果 URI 以前已请求了图像,将再次使用缓存和解码的图像,而不从 URI 启动新请求。
有关可以用于 Image 的图像源和格式的类型的信息,请参见 BitmapImage。
下图演示在 Windows Phone 上呈现的 Image 控件。

下面的示例演示如何创建图像。
<Image Source="myPicture.png" />
Image myImage = new Image(); myImage.Source = new BitmapImage(new Uri("myPicture.jpg", UriKind.RelativeOrAbsolute)); LayoutRoot.Children.Add(myImage);
在本例中,Source 属性用于指定要显示的图像的位置。可以通过指定绝对 URL(例如,http://contoso.com/myPicture.jpg)来设置 Source,也可以指定相对于应用程序的 XAP 文件的 URL。因此,对于前一示例,您需要在 myPicture.png 所在的同一个文件夹中具有 XAP 文件。