如何在通用 Windows 应用程序中设计响应式 UI [英] How can I design responsive UI in universal windows app

查看:43
本文介绍了如何在通用 Windows 应用程序中设计响应式 UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始开发通用应用.我已经在 Windows 8 商店应用程序中开发了应用程序,还开发了 Windows Phone 8 和 Windows Phone 8.1 (SilverLight) 应用程序.问题与 Windows 中的通用应用程序和在应用程序中创建的单一 UI 有关.共享文件夹.

I have just started to develop in universal app. I have developed app in Windows 8 store apps and also developing Windows Phone 8 and Windows Phone 8.1 (SilverLight) Apps. Question is related to universal app in Windows and Single UI which is created in App. Share folder.

1 对于 web,有类似响应式 UI 这样的词.创建有媒体查询来编写css.我知道 css 与我们可以使用 为 xaml 创建 资源相同.我可以从 c# 中获取分辨率,我可以为不同的分辨率创建不同的 UI,我可以根据分辨率显示折叠状态,但是有没有任何一种方法可以根据设计自动调整.?(这个问题专门和数据绑定控件有关...)

1 For web there is word like responsive UI. to create there is media query to write css. I know css is same as we can create resource with for xaml . I can get resolution form c# and I can create different UI for different resolution and I can visible collapsed according to resolution but is there any single way which automatically adjust according to design.? ( this question is related to data binding controls specially...)

推荐答案

有多种技术可以根据窗口的大小、形状和分辨率调整页面设计.这些通常一起使用.

There are several techniques to adjust the page's design to the size, shape, and resolution of the window. These are usually used together.

首先是使用动态布局控件而不是硬编码位置.例如,使用带有 * 列的 Grid 控件按百分比拆分屏幕,或使用 StackPanel 来堆叠控件以使其适合.GridViews 可以缩放以填满屏幕(甚至更远).这将使应用程序流动以使用可用空间.

The first is to use dynamic layout controls instead of hard-coding positions. For example, use a Grid control with * columns to split the screen by percentages, or a StackPanel to stack controls so they as they fit. GridViews can scale to fill the screen (and beyond). This will let the app flow to use the available space.

MSDN 在快速入门:定义布局

对于更大规模的更改,应用应该进行更大的更改以适应更大的更改,例如纵向模式、横向模式和对齐模式,您可以使用视觉状态.视觉状态允许应用程序设置特定状态(例如横向"),该状态会自动更改页面控件的属性.对于动态布局,视觉状态通常会隐藏和显示不同的控件,例如从横向模式下的水平方向 GridView 切换到纵向模式下的垂直方向 ListView.通过将两个控件数据绑定到相同的数据,代码隐藏不需要知道在任何特定时间使用哪些控件的任何详细信息.

For larger scale changes where the app should make bigger changes to adjust to larger changes such as portrait vs. landscape vs. snapped modes you can use Visual States. Visual States allow the app to set a specific state (e.g. "Landscape") which automatically changes properties of the page's controls. For dynamic layout the visual states will typically hide and show different controls, for example to switch from a horizontally oriented GridView in Landscape mode to a vertically oriented ListView in Portrait mode. By data-binding both controls to the same data the code-behind doesn't need to know any details about which controls are used at any specific time.

MSDN 在快速入门:设计应用程序不同的窗口大小

Blend 有一个非常好的视觉状态编辑器,您可以使用它来直观地定义和设置不同的视觉状态.

Blend has a very good Visual States editor that you can use to define and set up different visual states visually.

相同的技术和代码适用于 Windows 应用商店应用和 Windows Phone 应用商店应用,但确切的布局可能会有所不同,以满足不同的设备尺寸.Windows 应用商店应用程序在各种显示尺寸上运行,用户可以自由调整 Windows 应用商店应用程序的大小,因此 Windows 应用商店应用程序需要支持比 Windows Phone 应用商店应用程序更灵活的布局.Windows Phone 商店应用需要考虑显示分辨率,但以相当一致的纵横比运行,仅针对纵向或横向变化.

The same techniques and code apply to Windows Store apps and for Windows Phone Store apps, but the exact layouts are likely to be different to cater to the different device sizes. Windows Store apps run on a wide range of display sizes and users can resize Windows Store apps freely, so Windows Store apps need to support much more flexible layouts than Windows Phone Store apps. Windows Phone Store apps need to take display resolution into account, but run on fairly consistent aspect ratios which change only for portrait or landscape.

对于非常简单的应用程序,您可以在通用应用程序的共享项目中共享单个 Xaml 页面,但在大多数情况下,您最好使用 Windows 应用商店和 Windows Phone 应用程序的单独页面设计.除了屏幕尺寸差异之外,还有一些控件差异需要单独的 Xaml.Xaml 不支持条件编译,因此共享 Xaml 文件需要在两者中完全相同.

For very simple apps you may be able get away with sharing a single Xaml page in the Shared project of a Universal app, but in most cases you'll be better off with separate page designs for Windows Store and Windows Phone apps. In addition to the screen size differences, there are a few control differences that will require separate Xaml. Xaml doesn't support conditional compilation, so a Shared Xaml file would need to be exactly the same in both.

这篇关于如何在通用 Windows 应用程序中设计响应式 UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆