silverlight教程(6)——使用用户管制,以落实主/详细情况

来源:百度文库 编辑:神马文学网 时间:2024/04/28 04:56:27
基本的设计目标silverlight和wpf是为了让开发人员能够更加容易地概括UI的功能集成在可重复使用的管制。开发商可以实施新的海关管制所产生的一类由现有的一个控制班(或为控制基地班或从控制TextBox的一样,按钮等) 。此外,他们可以创建可重复使用的用户管制-这使其容易使用x aml标记档案,以组成一个控制的用户界面,以及哪些容易执行。

For our Digg application, we want to implement a master/details scenario where the application allows an end-user to search on a topic, populate a list of stories related to that topic, and then enable them to select a story to bring up details about it.  For example, selecting the below story in the list:我们digg申请时,我们要执行硕士/细节的情况下应用,使最终用户寻找一个主题,填充名单故事有关这一议题,然后,让他们选择了一个故事,以培养造就详情关于它的规定,例如,选择下面的故事,在名单:

would bring up this detailed view about the story:会带来了这个详细查看有关的故事:

We are going to implement this details view by building a "StoryDetailsView" UserControl that we'll display when a story is selected from our ListBox.我们要贯彻这一细节,以期建立一个" storydetailsview " usercontrol ,我们越能显示的时候,一个故事,选自我们的列表。

Creating a StoryDetailsView User Control 创造一个storydetailsview用户控制

We'll start by right-clicking on our DiggSample project node in Visual Studio and by selecting "Add New Item".  This will bring up a new item dialog.  We'll select the UserControl item template and name the new control we want to build "StoryDetailsView":我们也将开始通过右击我们diggsample工程节点,在Visual Studio和通过选择"添加新项目" ,这将造就一个新的项目对话框中,我们将再选择usercontrol项目模板和名称,新的控制,我们希望构筑" storydetailsview " :

This will add a new UserControl with this name to our DiggSample project:这将增加一个新的usercontrol这个名字我们diggsample项目:

Building a Basic Modal Dialog Using a User Control 建设的一个基本模态对话框中使用一个用户控制

We are going to use our StoryDetailsView control to effectively display a dialog containing story details.  When our story details user control displays we are going to want to have it appear on top of the other content on the page, and ensure that an end-user can't do other things with the page until they close the details view.我们要利用我们的storydetailsview控制,以有效地显示一个对话框,包含故事细节的时候,我们的故事细节用户控制显示器,我们会想它出现在顶部的其他内容,对网页,并确保最终用户不能做其他事情同页,直到他们接近细节的看法。

There are a couple of different ways we could implement this modal dialog-like behavior.  For this particular scenario we are going to start by opening up the StoryDetailsView.xaml user control and adding the below XAML content to it:有一对夫妇的不同方式,我们可以执行这个模态对话框样行为,基于这个特定场景,我们将会首先开放了storydetailsview.xaml用户控制,并加入下面xaml内容:

The first control above is configured to stretch to take up all of the available space on the screen.  Its background fill color is a somewhat transparent gray (because its Opactity is .765 you can see a little of what is behind it).  The second control will then be layered on top of this Rectangle control, and take up a fixed width on the screen.  It has a blue background color, and contains a Close button.第一控制上述配置,以舒展采取了所有的可用空间在屏幕上,其背景填充颜色是有点透明的灰色(因为其opactity是0.765你可以看到一点点的背后到底是什么,它) 。第二控制,然后层层再加上这个矩形控制,并采取了固定宽度在屏幕上,它有一个蓝色背景颜色,并包含一个关闭按钮。

When visible, our StoryDetailsView user control will currently display a UI like below:当看得见的,我们storydetailsview用户控制,将目前显示的UI像如下:

We can implement the "CloseBtn_Click" event handler method in the code-behind file of the user control.  When pressed, the close button event handler will set the Visibility of the UserControl to "Collapsed" - which will cause it to disappear from the screen and return the user to the content below it:我们可以执行" closebtn_click "事件处理法在代号后面文件的用户控制,当按下,关闭按钮的事件处理,将设置能见度的usercontrol ,以"崩溃" -这将导致它消失,从屏幕并返回用户的内容如下:

Displaying our StoryDetailsView Control 展示我国storydetailsview控制

An easy way to cause our StoryDetailsView user control to appear on the screen would be to simply add it to the bottom of our Page.xaml file, and set its default visibility to Collapsed (which means it is not visible when the application first loads):一种简单的方法来使我们的storydetailsview用户控制出现在屏幕上,将简单地将它添加到的底部我们page.xaml档案,并设置其默认能见度崩溃(这意味着它是不可见时,首先应用负载) :

We can then handle the "SelectionChanged" event from our ListBox control within the Page.xaml's code-behind class:我们便可以处理" selectionchanged "活动,从我们的列表控制内部page.xaml奇摩代号背后的班级:

When a user selects a particular story in the list, we can use the ListBox SelectionChanged event handler to set the Visibility property of our ShowDetailsView user control to "Visible" :当使用者选择一个特别的故事,在该份名单中,我们可以利用列表selectionchanged事件处理设置能见度财产的,我们showdetailsview用户控制,以"有形" :

This will cause our modal user control dialog to appear.  When the user clicks its "Close" button, it will disappear, and the user will be free to select another story and repeat the process.这将导致我们的模态用户控制对话框出现时,用户点击"关闭"按钮,它就会消失,用户可自由选择另一个故事,并重复这个过程。

Passing Story Data to our StoryDetailsView User Control 通过故事的数据,我们storydetailsview用户控制

Ultimately we want our StoryDetailsView UserControl to display detailed information about the story that the end-user selected from the stories ListBox.最终我们希望我们的storydetailsview usercontrol显示详细资料,编造出最终用户中挑选出来的故事列表。

Within our ListBox's "SelectionChanged" event handler (which is inside our page's code-behind class), we can gain access to the DiggStory data object that corresponds to the selected ListBox row by accessing the ListBox's "SelectedItem" property.在我们列表的" selectionchanged "事件处理(这是我们内页的代号背后的阶级) ,我们可以接触到diggstory数据对象对应于选定列表连续进入列表的" selecteditem "财产。

One approach we could use to pass this DiggStory object to our StoryDetailsView UserControl would be to simply set the "DataContext" property on the User Control to the selected DiggStory data object immediately before making the user control visible:一个办法是我们可以利用通过这diggstory反对我们storydetailsview usercontrol会简单地定为" datacontext "财产上的用户控制,以选定diggstory数据对象立即,然后再作用户控制有形:

We could then write code within our UserControl to procedurally use the DataContext to display results.  Or alternatively we could use databinding expressions to bind against its values.我们便可以编写代码,我们usercontrol以程序上使用datacontext展示成果。或者我们可以利用和数据绑定表达式约束对自己的价值观。

For example, we could update our StoryDetailsView XAML to display the Title of the selected story using a databinding expression like below:举例来说,我们可以更新storydetailsview xaml要显示的标题被选中的故事,使用和数据绑定想表达如下:

And now when a user clicks a story in the list:现在当用户点击一个故事,在名单:

Our ListBox event handler will handle the selection, set the DataContext of the UserControl to the selected DiggStory object, and then make the user control visible:我们的列表事件处理一定要处理,筛选,确定了datacontext的usercontrol来选定diggstory对象,然后让用户控制可见:

Notice how the DiggStory title now appears in the user control because of the databinding expression we added to it.公告如何diggstory标题,现在看来,在用户控制,因为该和数据绑定表达我们添加进去。

Finishing our User Control Layout 整理我们的用户控制布局

Our sample above demonstrates the basics of how we can put together a simple master/details dialog workflow.  We can complete the StoryDetailsView display by adding more controls and databinding expressions to the User Control.我们的样本显示了以上的基本知识,如何能放在一起简单的主/细节对话框中的工作流程,我们可以完成storydetailsview显示器通过增加更多的管制和和数据绑定表达式给用户控制。

We could update the StoryDetailsView user control to look like above by updating its control to have the following inner content:我们可以更新storydetailsview用户控制看起来像上述通过更新其控制有以下党内内容:

No code changes are required after this.  Because we are using databinding to "pull" the values from the DataContext, we don't need to write any additional code.没有更改代码,必须经过这个,因为我们现在用的和数据绑定,以"拉"的价值观,从datacontext ,我们不需要写任何额外的代码。

silverlight教程(6)——使用用户管制,以落实主/详细情况 silverlight教程(8)——创造一个digg桌面应用程序使用wpf silverlight教程(4)---使用风格元素,以更好地概括外观与感觉 一步一步学Silverlight 2系列(10):使用用户控件 silverlight教程(7)——使用控制模板来定制一个控制的外观和感觉 silverlight教程(3)---使用Networking取回Digg故事 silverlight教程(2)--布局管理器 solaris教程-限制 Solaris 用户目录和硬盘使用空间 使用布局管理 (木野狐译) | Silverlight中文社区 如何落实“以学定教” 制度安排、制度变迁与政府管制限度—以水污染物排放许可证制度为例 制度安排、制度变迁与政府管制限度—以水污染物排放许可证制度为例 绘声绘影软件使用教程(6-10) 黑莓手机模拟器使用教程,以7系列为例 落实,落实,还是落实(民生观) 使用 Networking取回数据并填充DataGrid | Silverlight中文社... Windows Vista使用教程-第三章 UAC(用户帐户控制) | Vista天地 Samplitude使用系列教程6 沙盘(Sandboxie)使用教程 We Media下的使用与满足理论——MSN SPACE用户行为研究 刻录光盘不求人——Nero刻录軟件使用教程(视频) 刻录光盘不求人——Nero刻录軟件使用教程(视频) 刻录光盘不求人——Nero7刻录軟件使用教程(图文) 刻录光盘不求人——Nero7刻录軟件使用教程(图文)