Windows Store App设计时数据的应用

想象这么一个场景:我们在做开发的时候写了一个GirdView并且对GridView的DataTemplate做了布局以及绑定,于是VS设计器中出现了一个框,但是开发人员并不能很好的预料到如果数据填充进去会有什么样的结果,举个例子来说可能长度或者高度设计的不够,导致某个远程图片被缩放变形,同时后期修改会产生大量的项目延迟。 这个时候我们需要使用VS来显示一些设计时数据。 情况一,数据源为本地数据 这种情况是最好的,绑定完成之后debug就可以看到数据显示是否符合需求,稍作修改便可。请参考如何绑定到分层数据并创建主视图/详细信息视图。 情况二,数据源为远程数据 当然你可以使用本地数据作为测试,下面这段代码可以在测试时帮助调用一些本地的测试数据 Fake Date if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) {       GetSampleData(); } else GetRealData(); 同样的,这种方式也仅仅只能在Debug下才能看到数据显示是否正确,如果想在设计时看到数据,那么我们需要其他的一些代码。 情况三,设计时显示测试数据  上图所示就是在设计时候显示的数据,而作为对比,下图为运行时数据 我们需要做的就是 Step1, 定义设计时所需要的数据,我这里创建了一个叫DesignTimeDataCenter的类专门用于放置测试数据 Step2,完善绑定,在此声明下,具有 d: 前缀的属性仅在设计时被解释,而在运行时被忽略。所以绑定的属性可以用d:Source 来实现。 Step3,修改排版,让界面看起来更完美。 具体的代码我贴一部分在这里,其他的大家可以在我的SkyDrive上下载,地址为:http://1drv.ms/1cwIj2c MainPage.XAML文件: <Page  x:Class=”DesignTimeData.MainPage”    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”    xmlns:local=”using:DesignTimeData”      xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″    xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″     DataContext=”{Binding RelativeSource={RelativeSource Self}}”     d:DataContext=”{Binding Source={d:DesignInstance Type=local:DesignTimeDataCenter, IsDesignTimeCreatable=True}}”     mc:Ignorable=”d”>      <Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>         <GridView ItemsSource=”{Binding News}”>             <GridView.ItemTemplate>…

0

RenderTargetBitmap 在windows store app 中的应用

前言  RenderTargetBitmap 是windows 8.1中一个新的类,它可以将任意的UIElement以bitmap的形式呈现。这篇博客的第一部分将介绍如何在windows 8.1中使用RenderTargetBitmap。第二部分将介绍在windows store app与WPF中RenderTargetBitmap大小调整方式的差异。UIElement以bitmap的形式呈现时,RenderTargetBitmap如何调整原来的UIElement大小对于你的项目来说是一个难题,但幸运的是这篇文章将会提出一个解决方案,使您可以在windows store app中得到与WPF相同的结果。让我们开始这篇博客的介绍吧。 怎么在windows 8.1中使用RenderTargetBitmap 在windows store app,你可以分以下两种情况来使用RenderTargetBitmap 将它当成一个ImageSources使用(用一个image-Element来显示或者通过ImageBrush来显示) 使用它的pixels值(比如说将一个bitmap存储到硬盘或者与其他的app进行分享) 本节只是介绍一些基础的知识,在MSDN的相关文档里面有详尽的描述: RenderTargetBitmap-class (这个网站有关于RenderTargetBitmap的详细描述 ) XAML render to bitmap sample (一个很好的例子,可以学习如何通过ImageSources和pixels来使用RenderTargetBitmap) 接下来我们来看一个简单的例子以及开始学习如何将一个UIElement以bitmap的方式呈现。 UIElement的呈现 在接下来的章节中,我们将通过下面的代码来定义一个Grid并将它作为RenderTargetBitmap的输入.在这个Grid中包含一个image和TextBlock控件。由于这个Grid没有定义任何的行或列,所以TextBlock的内容呈现在图片的上方。 <Grid x:Name=”elementToRender” Width=”500″ Height=”500″>             <Image Source=”Assets/image.jpg” Stretch=”UniformToFill”/>             <TextBlock Text=”This text is on top of the image” FontSize=”40″ TextWrapping=”Wrap” Margin=”50″/> </Grid> 上段代码的结果如下:   需要注意的是在上面代码中,将Grid的名称定义为elementToRender,我们接下来可以在C#代码中通过该名称来访问Grid。现在我们来看看如何使用该Grid来定义一个RenderTargetBitmap。 用UIElement来定义一个RenderTargetBitmap 你可以通过调用RenderAsync这个方法来定义一个RenderTargetBitmap,该方法的输入参数是一个UIElement,下面的代码是通过将名为elementToRender的Grid来作为该方法的输入参数从而来定义一个RenderTargetBitmap对象:…

0

How to use new controls in Windows 8.1 (1)

Author: James He   Before developing an app, you should know which tools can be usedto help with design and layout. As Windows 8.1 released on Oct.18th,some new features are introduced accordingly. Within this article, we willshare our experience on using these new controls and try to “hack” thesecontrols from layout and design. DatePicker &…

1

Using Free-COM DLL in Windows Store C++ Project

It is generally known that migrating Desktop App to Windows Store App is quite a headache. In .NET, some namespace cannot be used in Windows Store App, so it is very difficult to deal with when you want to migrate code related to these namespaces. In C++, native code cannot be referenced directly as DLL…

1

How to do data conversion in Windows Store app

Q: How to convert streams in .NET? A: Here is the list to show the different stream types conversion. Conversion between Stream and IRandomAccessStream // stream to IRandomAccessStream var randomAccessStream = new InMemoryRandomAccessStream(); var outputStream = randomAccessStream.GetOutputStreamAt(0); await RandomAccessStream.CopyAsync(stream.AsInputStream(), outputStream);   // IRandomAccessStream to stream Stream stream = WindowsRuntimeStreamExtensions.AsStreamForRead(randomStream.GetInputStreamAt(0));   Conversion between IBuffer and Stream…

0

Using database in Windows Store apps (I)

Author: Aaron Xue Introduction There are lots of discussions about using database in Windows Store apps in MSDN forum. These discussions mainly focus on the usage of SQL database. Based on this scenario, we developed a series of articles along with sample code and demos used to demonstrate how to access both local database and…

16

Using HTML5/Javascript in Windows Store apps: Data access and storage mechanism (III)

Introduction Windows Store app offers lots of methods for data access and storage. And this article will only focus on HTML5/JavaScript programming. In this tutorial, we’ll go over Application Data, File API , HTML5 Web Storage, Indexed Database API and remote data access. With these you can store more data – and store it more…

0

Using HTML5/Javascript in Windows Store apps: Data access and storage mechanism (II)

  Introduction Windows Store app offers lots of methods for data access and storage. And this article will only focus on HTML5/JavaScript programming. In this tutorial, we’ll go over Application Data, File API , HTML5 Web Storage, Indexed Database API and remote data access. With these you can store more data – and store it…

0

Using HTML5/Javascript in Windows Store apps: Data access and storage mechanism (I)

 Author: Roy Tian Introduction Windows Store app offers lots of methods for data access and storage. And this article will only focus on HTML5/JavaScript programming. In this tutorial, we’ll go over Application Data, File API , HTML5 Web Storage, Indexed Database API and remote data access. With these you can store more data – and…

0