如何将uwp gridview适配屏幕EX升级到UWP平台

用dtagridview直接修改的数据怎么更新到SQL数据库
[问题点数:40分,结帖人yilupingxing]
用dtagridview直接修改的数据怎么更新到SQL数据库
[问题点数:40分,结帖人yilupingxing]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。如何将GridViewEX升级到UWP(Universal Windows Platform)平台
上一篇文章中,我们主要讲解了如何在保证GridView控件的用户体验基础上,扩展GridView生成GridViewEx控件,增加动态添加新分组功能等,本文在上文的基础上,介绍如何在Windows10中使用GridViewEx,开发UWP应用。
GridViewLiveTiles.zip
GridViewEx.zip
GridViewDemo.zip
开发U应用程序
开发UWP应用程序最好是从创建empty项目开始,重用已开发的一些模块,这样可以提高开发效率。
本文为了创建UWP 应用程序,首先创建一些通用类如下,详细代码见附件:
Common/VisibilityConverter.cs
Common/LayoutAwarePage.cs
Common/SuspensionManager.cs
修改布局和导航
VisibilityConverter 和 SuspensionsManager暂时不需要修改,可直接在UWP中使用。主要修改布局和导航逻辑文件。
由于微软支持的设备种类越来越多,导致ApplicationViewState不再适用。UWP平台提供了其他的解决方法如AdaptiveTriggers,内置了自适应布局。因此创建UWP应用程序,首先需要删除所有ApplicationViewStates的代码。可能会导致使用LayoutAwarePage的部分会报错。因此我们需要做一些兼容性的改变。
无论是WinRT还是UWP应用,都会使用返回键导航。桌面WinRTx应用会在Xaml文件添加返回按钮。但是在UWP应用中,非常灵活,桌面应用可以在标题栏中添加返回按钮,在移动设备中不仅能使用标题栏中的返回键,也可以使用物理返回键实现导航功能。UWP的方法比较通用,且不需要编写自定义的Xaml文件。因此只需要开发一个基类,应用到不同的Xaml 页面中就可以实现轻松实现导航功能,不需要重复编写代码。修改后的LayoutAwarePage 类:
protected override void OnNavigatedTo(NavigationEventArgs e)
// subscribe on Back button event
if (IsWindowsPhoneDevice())
// use hardware button
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackP
// enable/disable window back button depending on navigation state
var currentView = SystemNavigationManager.GetForCurrentView();
currentView.AppViewBackButtonVisibility = this.Frame != null && this.Frame.CanGoBack ?
AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.C
currentView.BackRequested += backButton_T
protected override void OnNavigatedFrom(NavigationEventArgs e)
// unsubscribe from Back button event
if (IsWindowsPhoneDevice())
Windows.Phone.UI.Input.HardwareButtons.BackPressed -= HardwareButtons_BackP
// unsubscribe from window back button
var currentView = SystemNavigationManager.GetForCurrentView();
currentView.BackRequested -= backButton_T
// handle Back button events
private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
if (this.Frame != null && this.Frame.CanGoBack)
e.Handled =
this.Frame.GoBack();
private void backButton_Tapped(object sender, BackRequestedEventArgs e)
this.GoBack(this, new RoutedEventArgs());
因为需要使用物理返回键,我们需要在程序中添加引用文件&Windows Mobile Extensions for the UWP&。
现在由LayoutAwarePage派生而来的所有页面都可直接使用,无需在多个文件中添加引用。
LayoutAwarePage 类最后添加设备查询的静态方法,来检测运行时设备。
public static bool IsWindowsPhoneDevice()
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent(Windows.Phone.UI.Input.HardwareButtons))
1. 如果想保证应用程序在Windows10中具有与一致的界面风格和用户体验,可使用Windows 10 ThemeResources (主题资源)。
2. 微软也在Windows10 发布中升级了GridView控件,相对于Windows 8 版本来说,最重要的改变是添加了用户重定向检测。
3. VariableSizedWrapGrid 面板也添加了重定向检测功能。并且去掉了行和列自动展开的功能。下面是Windows8 版本的Xaml文件,在Windows10 中已经无法使用。
最好的解决方法就是将VariableSizedWrapGrid 与item的属性绑定,并将值传给自定义的GridView控件的ListViewItemPresenter 元素:
/// This class sets VariableSizedWrapGrid.ColumnSpanProperty for GridViewItem controls,
/// so that every item can have different size in the VariableSizedWrapGrid.
/// Also it sets VerticalContentAlignment and HorizontalContentAlignment to Stretch.
public class GridViewTiled : GridView
// set ColumnSpan according to the business logic (maybe some GridViewSamples.Samples.Item or group properties)
protected override void PrepareContainerForItemOverride(Windows.UI.Xaml.DependencyObject element, object item)
element.SetValue(ContentControl.HorizontalContentAlignmentProperty, HorizontalAlignment.Stretch);
element.SetValue(ContentControl.VerticalContentAlignmentProperty, VerticalAlignment.Stretch);
UIElement el = item as UIE
if (el != null)
int colSpan = Windows.UI.Xaml.Controls.VariableSizedWrapGrid.GetColumnSpan(el);
int rowSpan = Windows.UI.Xaml.Controls.VariableSizedWrapGrid.GetRowSpan(el);
if (rowSpan & 1)
// only set it if it has non-defaul value
element.SetValue(Windows.UI.Xaml.Controls.VariableSizedWrapGrid.RowSpanProperty, rowSpan);
if (colSpan & 1)
// only set it if it has non-defaul value
element.SetValue(Windows.UI.Xaml.Controls.VariableSizedWrapGrid.ColumnSpanProperty, colSpan);
base.PrepareContainerForItemOverride(element, item);
UWP中的XAML文件:
新占位符(NewGroupPlaceholder)控件
WinRT版的GridViewEx控件使用了简单border作为新分组的占位符,在拖拽项过程中外观是静态的,无法改变。为了使界面对用户更加友好,并且将拖放的位置高亮, 因此我们新建了新的&NewGroupPlaceholder&控件,在拖拽过程中有简单的状态切换逻辑。
代码很简单,见附件,系统提供的控件模板代码如下:
修改GridViewEx 控件
接下来,我们将介绍如何修改GridViewEx控件,使得其可以适应UWP。
UWP平台下运行GridViewEx大部分的功能与WinRT保持一致。只有OnDragOver中的DragEventArgs.AcceptedOperation 属性需要重写。显然UWP 中的GridView 将所有非空项的该属性都设置为None。因此,如果不重写OnDragOver 方法,Drop 事件就不会被触发。
代码如下:
protected override void OnDragOver(DragEventArgs e)
int newIndex = GetDragOverIndex(e);
if (newIndex &= 0)
e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.M
运行代码时编译器会发出很多关于ItemContainerGenerator 方法的警告,调用ItemsControl 响应方法就可以处理Warning
VariableSizedWrapGrid存在很多限制,为了解决这些限制,在上述代码中添加 PrepareContainerForItemOverride 方法。最后需要升级GridViewEx 控件自带的样式,使其支持设备重定向。
更加适应手持设备
在GridViewEx控件中添加新的PreparingContainerForItem 事件,该事件的参数即包含数据对象,也包含UI 容器,因此可根据需求设置UI属性,代码如下:
/// Set column spans depending on group id.
private void gve_PreparingContainerForItem(object sender, GridViewEx.PreparingContainerForItemEventArgs e)
Item it = e.Item as I
if (it != null)
e.Element.SetValue(Windows.UI.Xaml.Controls.VariableSizedWrapGrid.ColumnSpanProperty, it.GroupId % 2 + 1);
e.Element.SetValue(Windows.UI.Xaml.Controls.VariableSizedWrapGrid.ColumnSpanProperty, 1);
在多设备中具有良好用户体验
为了适应多种设备,需要生成自适应布局。本文中主要通过修改内容项的尺寸来实现该功能。创建了Bound ,Unbound以及Grouped 示例文件,Grouped 显示单个GridView控件,因此在移动端能够修改Tile的尺寸及边框。
Bound 和Unbound 示例是由2个GridView控件组成,小屏幕中显的内容较多,无法显示更多的细节性的内容,因此使用Pivot控件保证同一时间只显示一个GridView控件,并支持GridView之间切换。
代码如下:
public double TileSize
get { return (double)GetValue(TileSizeProperty); }
set { SetValue(TileSizeProperty, value); }
public static readonly DependencyProperty TileSizeProperty =
DependencyProperty.Register(nameof(TileSize), typeof(double), typeof(Customized), new PropertyMetadata(100));
public Customized()
if (IsWindowsPhoneDevice())
TileSize = 72;
this.InitializeComponent();
GridViewEx 和GridView 中绑定代码如下:
ItemWidth={Binding TileSize, ElementName=pageRoot}
Orientation=Horizontal MaximumRowsOrColumns=10/&
自定义GridViewEx控件扩展了GridView控件,丰富了功能,并新增适应UWP平台App的开发。
示例图片:
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'&&&&TreeGridViewEx树形控件GridView控件 v1.0
&TreeGridViewEx树形控件GridView控件 v1.0
TreeGridViewEx树形控件GridView控件 v1.0
Asp.NET扩充控件TreeGridViewEx 控件实现Tree和GridView功能的合并,控件继承自GridView
可用于ASP.NET数据显示。
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
Q.为什么我点的下载下不了,但积分却被扣了
A. 由于下载人数众多,下载服务器做了并发的限制。若发现下载不了,请稍后再试,多次下载是不会重复扣分的。
Q.我的积分不多了,如何获取积分?
A. 获得积分,详细见。
完成任务获取积分。
论坛可用分兑换下载积分。
第一次绑定手机,将获得5个C币,C币可。
关注并绑定CSDNID,送10个下载分
下载资源意味着您已经同意遵守以下协议
资源的所有权益归上传用户所有
未经权益所有人同意,不得将资源中的内容挪作商业或盈利用途
CSDN下载频道仅提供交流平台,并不能对任何下载资源负责
下载资源中如有侵权或不适当内容,
本站不保证本站提供的资源的准确性,安全性和完整性,同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
开发技术下载排行
您当前C币:0&&&可兑换 0 下载积分
兑换下载分:&
消耗C币:0&
立即兑换&&
兑换成功你当前的下载分为 。前去下载资源
你下载资源过于频繁,请输入验证码
如何快速获得积分?
你已经下载过该资源,再次下载不需要扣除积分
TreeGridViewEx树形控件GridView控件 v1.0
所需积分:1
剩余积分:0
扫描微信二维码精彩活动、课程更新抢先知
VIP会员,免积分下载
会员到期时间:日
剩余下载次数:1000
TreeGridViewEx树形控件GridView控件 v1.0
剩余次数:&&&&有效期截止到:
你还不是VIP会员VIP会员享免积分 . 专属通道极速下载
VIP下载次数已满VIP会员享免积分 . 专属通道极速下载,请继续开通VIP会员
你的VIP会员已过期VIP会员享免积分 . 专属通道极速下载,请继续开通VIP会员

我要回帖

更多关于 totolink ex300升级 的文章

 

随机推荐