活动介绍

Silverlight4:Out-of-BrowserModeandLocalDataCaching

立即解锁
发布时间: 2025-08-26 00:48:30 阅读量: 4 订阅数: 15
PDF

Silverlight 4商业应用开发指南

### Silverlight 4: Out-of-Browser Mode and Local Data Caching #### 1. Uninstalling Applications Applications can be uninstalled using tools like Windows Vista/7’s Programs and Features tool. The application will show up as an entry in this tool, and you can uninstall it just like any other application. Note that it's not possible to uninstall the application through code. #### 2. Toast Notifications Silverlight 4 introduced the ability to display “toast” notifications. These are small windows that pop up for a few seconds, usually in the bottom right - hand corner of the screen, to notify users of events in the application. For example, Microsoft Outlook shows a toast when a new email arrives, and TweetDeck shows one when a new tweet appears. To display a toast notification: 1. **Display an empty notification**: ```csharp NotificationWindow toastWindow = new NotificationWindow(); toastWindow.Width = 280; toastWindow.Height = 100; toastWindow.Show(4000); ``` This code will make a small window appear in the bottom right - hand side of the screen, which will disappear after 4 seconds. The maximum display time for these notifications is 30 seconds (30000 milliseconds). Also, attempting to create a `NotificationWindow` instance inside the browser will throw an exception, so always check if the application is in OOB mode before showing a toast. 2. **Display content in the notification**: The easiest way is to create a user control in your project, design its content in the XAML file, and then assign an instance of the user control to the `NotificationWindow`’s `Content` property. ```csharp toastWindow.Content = new MessageArrivedNotification(); ``` 3. **Activate the main window on click**: If the application is in the background, you can activate the main window when the notification is clicked. Handle the `MouseLeftButtonDown` event of the `LayoutRoot` and activate the main window in the event handler. ```csharp private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Application.Current.MainWindow.Activate(); } ``` 4. **Close the notification window**: The `NotificationWindow` has a `Close` method. To use it from the user control, pass the `NotificationWindow` object to the user control’s constructor. ```csharp toastWindow.Content = new MessageArrivedNotification(toastWindow); ``` You can then call the `Close` method on this object from within the user control as needed. The process of creating a toast notification can be summarized in the following mermaid flowchart: ```mermaid graph TD; A[Check OOB mode] --> B[Create NotificationWindow instance]; B --> C[Set window size]; C --> D{Empty or with content?}; D -- Empty --> E[Call Show method]; D -- With content --> F[Create user control]; F --> G[Assign user control to Content property]; G --> E; E --> H[Optional: Handle click event to activate main window]; H --> I[Optional: Provide close functionality]; ``` #### 3. Caching Data Locally In scenarios where the server connection is unavailable, it's beneficial to allow users to continue working as much as possible. This is known as “occasionally connected applications”. The solution is to download and cache commonly used data from the server locally, keep it updated, and synchronize changes back to the server when the connection is restored. Additionally, caching data that rarely changes on the client can reduce network traffic. #### 4. Caching to Isolated Storage Silverli
corwn 最低0.47元/天 解锁专栏
赠100次下载
继续阅读 点击查看下一篇
profit 400次 会员资源下载次数
profit 300万+ 优质博客文章
profit 1000万+ 优质下载资源
profit 1000万+ 优质文库回答
复制全文

相关推荐

张诚01

知名公司技术专家
09级浙大计算机硕士,曾在多个知名公司担任技术专家和团队领导,有超过10年的前端和移动开发经验,主导过多个大型项目的开发和优化,精通React、Vue等主流前端框架。
最低0.47元/天 解锁专栏
赠100次下载
百万级 高质量VIP文章无限畅学
千万级 优质资源任意下载
千万级 优质文库回答免费看