silverlight
发布时间:2022-05-04 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了稳扎稳打Silverlight(29) - 2.0Tip/Trick之Cookie, 自定义字体, 为程序传递参数, 自定义鼠标右键, 程序常用配置参数,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
概述
[索引页] [源码下载] 稳扎稳打Silverlight(2
9) - 2.0Tip/Trick之Cookie, 自定义字体, 为程序传递参数, 自定义鼠标右键, 程序常用配置参数 作者: webabcd 介绍 Silverlight 2.0 提示和技巧系列 Cookie - 通过 JavaScript 操作 Cookie 自定义字体 -
在程序中使用自定字体 为程序传递参数 - 为 Silve
[索引页]
[源码下载]
稳扎稳打Silverlight(2
9) - 2.0Tip/Trick之Cookie,
自定义字体,为程序传递参数,
自定义鼠标右键,程序常用配置参数
作者:
webabcd
介绍
Silverlight 2.0
提示和技巧系列
- Cookie - 通过 JavaScript 操作 Cookie
- 自定义字体 - 在程序中使用自定字体
- 为程序传递参数 - 为 Silverlight 程序传递初始化参数
- 自定义鼠标右键 - 响应并处理自定义的鼠标右键事件
- 程序常用配置参数 - object 标记的常用参数,以及对应的 Silverlight 控件的常用属性
在线DEMO
http://www.cnblogs.com/webabcd/archive/2008/10/09/1307486.html
示例
1、操作 Cookie 的演示
Cookie.xaml
<
UserControl
x:Class
="Silverlight20.Tip.Cookie"
xmlns
="http://scheR_291_11845@as.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://scheR_291_11845@as.microsoft.com/winfx/2006/xaml"
>
<
StackPanel
HorizontalAlignment
="Left"
Margin
="5"
>
<
StackPanel
Orientation
="Horizontal"
Margin
="5"
>
<
TextBlock
Text
="cookie-key: "
/>
<
TextBox
x:Name
="txtKey"
/>
</
StackPanel
>
<
StackPanel
Orientation
="Horizontal"
Margin
="5"
>
<
TextBlock
Text
="cookie-value: "
/>
<
TextBox
x:Name
="txtValue"
/>
</
StackPanel
>
<
StackPanel
Orientation
="Horizontal"
Margin
="5"
>
<
Button
x:Name
="btnSetCookie"
Content
="设置Cookie"
Click
="btnSetCookie_Click"
/>
<
Button
x:Name
="btnGetCookie"
Content
="获取Cookie"
Click
="btnGetCookie_Click"
/>
<
Button
x:Name
="btn@R_696_9421@eCookie"
Content
="清除Cookie"
Click
="btn@R_696_9421@eCookie_Click"
/>
</
StackPanel
>
<
TextBox
x:Name
="txtResult"
Margin
="5"
/>
</
StackPanel
>
</
UserControl
>
Cookie.xam
l.cs
/*
关于使用 JavaScript 操作 Cookie 参看
http://msdn.microsoft.com/en-us/library/ms533693(Vs.85).aspx
*/
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
System.Windows.browser;
using
System.Text.RegularExpressions;
namespace
Silverlight20.Tip
{
public partial class Cookie : UserControl
@H_807_696@{
public Cookie()
{
initializeComponent();
}
/// <sumMary>
/// 设置 Cookie
/// </sumMary>
private void btnSetCookie_Click(object sender, routedEventArgs E)
{
if (txtKey.Text.Trim() != "" && txtValue.Text.Trim() != "")
{
String expire = datetiR_291_11845@e.Now.AddDays(@H_419_730@1).ToString("R"); // rFC1123Pattern 日期格式
String cookie = String.Format("{0}={1};expires={2}",
txtKey.Text.Trim(),
txtValue.Text.Trim(),
expirE);
// 通过 JavaScript 设置 Cookie
// 如下语句等于在 JavaScript 中给 document.cookie 赋值
HtmlPage.Document.SetProperty("cookie", cookiE);
}
}
/// <sumMary>
/// 获取 Cookie
/// </sumMary> private void btnGetCookie_Click(object sender, routedEventArgs E)
{
txtResult.Text = "";
// 通过 JavaScript 获取 Cookie
// HtmlPage.Document.Cookies 就是 JavaScript 中的 document.cookie
String[] cookies = regex.Split(HtmlPage.Document.Cookies, "; ");
foreach (var cookie in cookies)
{
String[] keyValue = cookie.Split('=');
if (keyValue.Length == @H_419_730@2)
{
txtResult.Text += keyValue[@H_419_730@0] + " : " + keyValue[@H_419_730@1];
txtResult.Text += "\n";
}
}
}
/// <sumMary>
/// 删除 Cookie
/// </sumMary> private void btn@R_696_9421@eCookie_Click(object sender, routedEventArgs E)
{
String[] cookies = regex.Split(HtmlPage.Document.Cookies, "; ");
foreach (var cookie in cookies)
{
String[] keyValue = cookie.Split('=');
if (keyValue.Length == @H_419_730@2)
{
HtmlPage.Document.SetProperty("cookie", keyValue[@H_419_730@0] + "=;" + datetiR_291_11845@e.Now.AddDays(-@H_419_730@1).ToString("R"));
}
}
}
}
}
2、演示如何使用
自定义字体
以使用华文行楷字体为例,先将字体
文件做为资源型
文件添加到项目里
CustomFont.xaml
<
UserControl
x:Class
="Silverlight20.Tip.CustomFont"
xmlns
="http://scheR_291_11845@as.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://scheR_291_11845@as.microsoft.com/winfx/2006/xaml"
>
<
StackPanel
HorizontalAlignment
="Left"
Margin
="5"
>
<
TextBlock
x:Name
="lblMsg"
text
="自定义字体"
FontSize
="50"
/>
<!--
以声明的方式使用自定义字体
-->
<!--
FontFamily - 字体源地址#字体名称
-->
<
TextBlock
Text
="自定义字体"
FontSize
="50"
FontFamily
="/Silverlight20;component/resource/STXINGKA.TTF#STXingKai"
/>
<!--
资源型文件 - [/程序集名;component/路径]
内容型文件 - [/路径]
-->
</
StackPanel
>
</
UserControl
>
CustomFont.xam
l.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
System.Windows.resources;
namespace
Silverlight20.Tip
{
public partial class CustomFont : UserControl
{
public CustomFont()
{
initializeComponent();
this.Loaded += new routedEventHandler(CustomFont_Loaded);
}
void CustomFont_Loaded(object sender, routedEventArgs E)
{
// 以编码的方式使用自定义字体
// 以华文行楷为例
StreamresourceInfo sri = App.GetresourceStream(
new Uri("/Silverlight20;component/resource/STXINGKA.TTF", UriKind.RelativE));
// 设置需要显示的字体源
lblMsg.Fontsource = new Fontsource(sri.Stream);
// 设置需要显示的字体名称
// STXingKai - 华文行楷的字体名称
lblMsg.FontFamily = new FontFamily("STXingKai");
}
}
}
大佬总结
以上是大佬教程为你收集整理的稳扎稳打Silverlight(29) - 2.0Tip/Trick之Cookie, 自定义字体, 为程序传递参数, 自定义鼠标右键, 程序常用配置参数全部内容,希望文章能够帮你解决稳扎稳打Silverlight(29) - 2.0Tip/Trick之Cookie, 自定义字体, 为程序传递参数, 自定义鼠标右键, 程序常用配置参数所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。