[索引页]
[源码下载]
作者:webabcd
介绍
Silverlight 2.0 提示和技巧系列
在线DEMO
http://www.voidcn.com/article/p-ounmxjds-tq.html
示例
1、操作 Cookie 的演示
Cookie.xaml
[源码下载]
作者:webabcd
介绍
Silverlight 2.0 提示和技巧系列
- Cookie - 通过 JavaScript 操作 Cookie
- 自定义字体 - 在程序中使用自定字体
- 为程序传递参数 - 为 Silverlight 程序传递初始化参数
- 自定义鼠标右键 - 响应并处理自定义的鼠标右键事件
- 程序常用配置参数 - object 标记的常用参数,以及对应的 Silverlight 控件的常用属性
在线DEMO
http://www.voidcn.com/article/p-ounmxjds-tq.html
示例
1、操作 Cookie 的演示
Cookie.xaml
<UserControl x:Class="Silverlight20.Tip.Cookie"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.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="btnDeleteCookie" Content="清除Cookie" Click="btnDeleteCookie_Click" />
</StackPanel>
<TextBox x:Name="txtResult" Margin="5" />
</StackPanel>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.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="btnDeleteCookie" Content="清除Cookie" Click="btnDeleteCookie_Click" />
</StackPanel>
<TextBox x:Name="txtResult" Margin="5" />
</StackPanel>
</UserControl>
Cookie.xaml.cs
<UserControl x:Class="Silverlight20.Tip.CustomFont"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.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>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.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.xaml.cs
<asp:Silverlight ID="Xaml1" runat="server" InitParameters="key1=value1,key2=value2" />
App.xaml.cs
InitParams.xaml
<UserControl x:Class="Silverlight20.Tip.InitParams"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Margin="5">
<TextBlock x:Name="lblMsg" />
<!--以声明的方式读取应用程序级别的资源-->
<TextBlock Text="{StaticResource key2}" />
</StackPanel>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Margin="5">
<TextBlock x:Name="lblMsg" />
<!--以声明的方式读取应用程序级别的资源-->
<TextBlock Text="{StaticResource key2}" />
</StackPanel>
</UserControl>
InitParams.xaml.cs
4、演示如何响应并处理鼠标右键事件
为 Silverlight 插件配置参数,windowless="true"
为 Silverlight 插件配置参数,windowless="true"
<param name="windowless" value="true" />
RightClick.xaml
<UserControl x:Class="Silverlight20.Tip.RightClick"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Border BorderBrush="Black" BorderThickness="4" Background="Bisque" Width="100" HorizontalAlignment="Left">
<!--右键菜单的内容-->
<StackPanel>
<TextBlock Margin="5">我是右键菜单1</TextBlock>
<TextBlock Margin="5">我是右键菜单2</TextBlock>
<TextBlock Margin="5">我是右键菜单3</TextBlock>
</StackPanel>
<!--右键菜单的位置-->
<Border.RenderTransform>
<TranslateTransform x:Name="tt" />
</Border.RenderTransform>
</Border>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Border BorderBrush="Black" BorderThickness="4" Background="Bisque" Width="100" HorizontalAlignment="Left">
<!--右键菜单的内容-->
<StackPanel>
<TextBlock Margin="5">我是右键菜单1</TextBlock>
<TextBlock Margin="5">我是右键菜单2</TextBlock>
<TextBlock Margin="5">我是右键菜单3</TextBlock>
</StackPanel>
<!--右键菜单的位置-->
<Border.RenderTransform>
<TranslateTransform x:Name="tt" />
</Border.RenderTransform>
</Border>
</UserControl>
RightClick.xaml.cs
5、Silverlight 程序的常用配置参数的说明
ParamDemo.html
ParamDemo.html
<
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< title >Silverlight20 </title>
< style type ="text/css" >
html,body
{
height: 100%;
overflow: auto;
}
body
{
padding: 0;
margin: 0;
}
#silverlightControlHost
{
height: 100%;
}
</style>
< script type ="text/javascript" src ="../Silverlight.js" > </script>
</head>
< body >
< div id ="silverlightControlHost" >
<!--
注:括号里为 Silverlight 控件所对应的属性
source(Source) - xap 文件的路径
minRuntimeVersion(MinimumVersion) - 所需的最低 Silverlight 插件版本
autoUpgrade(AutoUpgrade) - Silverlight 插件是否要自动升级。默认值 true
initParams(InitParameters) - 为 Silverlight 程序传递初始化参数。用“,”分隔
enableFrameRateCounter(EnableFrameRateCounter) - 是否在宿主浏览器的状态栏中显示当前呈现的 Silverlight 内容的每秒帧数(fps),用于调试用。默认值 false
maxFrameRate(MaxFrameRate) - 每秒要呈现的最大帧数。默认值 0 (表示未指定最大帧数)
enableRedrawRegions(EnableRedrawRegions) - 是否显示每个帧所重绘的区域。默认值 false
enableHtmlAccess(HtmlAccess) - 是否允许 HTML DOM 访问
对于 object 标记的 param : value="true" - 允许;value="false" - 不允许;无此 param - 同域允许
对于 Silverlight 控件的 HtmlAccess 属性 : Enabled - 允许;disabled - 不允许;SameDomain - 同域允许
windowless(windowless) - 指定 Silverlight 插件是否为无窗口插件
-->
<object id="xaml1" data="data:application/x-silverlight-2," type="application/x-silverlight-2"
width="100%" height="100%">
< param name ="source" value ="../ClientBin/Silverlight20.xap" />
< param name ="minRuntimeVersion" value ="2.0.31005.0" />
< param name ="autoUpgrade" value ="true" />
< param name ="initParams" value ="key1=value1,key2=value2" />
< param name ="enableFrameRateCounter" value ="true" />
< param name ="maxFrameRate" value ="30" />
< param name ="enableRedrawRegions" value ="false" />
< param name ="enableHtmlAccess" value ="true" />
< param name ="windowless" value ="true" />
</object>
< iframe style ='visibility: hidden; height: 0; width: 0; border: 0px' > </iframe>
< ! --iframe 元素和其他附加到 HTML 的元素有助于确保跨浏览器兼容性。iframe 的存在可避免 Safari 浏览器缓存页面。当用户向后导航到以前访问过的 Silverlight 页面时,Safari 缓存可避免重新加载 Silverlight 插件-- >
</div>
</body>
</html>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< title >Silverlight20 </title>
< style type ="text/css" >
html,body
{
height: 100%;
overflow: auto;
}
body
{
padding: 0;
margin: 0;
}
#silverlightControlHost
{
height: 100%;
}
</style>
< script type ="text/javascript" src ="../Silverlight.js" > </script>
</head>
< body >
< div id ="silverlightControlHost" >
<!--
注:括号里为 Silverlight 控件所对应的属性
source(Source) - xap 文件的路径
minRuntimeVersion(MinimumVersion) - 所需的最低 Silverlight 插件版本
autoUpgrade(AutoUpgrade) - Silverlight 插件是否要自动升级。默认值 true
initParams(InitParameters) - 为 Silverlight 程序传递初始化参数。用“,”分隔
enableFrameRateCounter(EnableFrameRateCounter) - 是否在宿主浏览器的状态栏中显示当前呈现的 Silverlight 内容的每秒帧数(fps),用于调试用。默认值 false
maxFrameRate(MaxFrameRate) - 每秒要呈现的最大帧数。默认值 0 (表示未指定最大帧数)
enableRedrawRegions(EnableRedrawRegions) - 是否显示每个帧所重绘的区域。默认值 false
enableHtmlAccess(HtmlAccess) - 是否允许 HTML DOM 访问
对于 object 标记的 param : value="true" - 允许;value="false" - 不允许;无此 param - 同域允许
对于 Silverlight 控件的 HtmlAccess 属性 : Enabled - 允许;disabled - 不允许;SameDomain - 同域允许
windowless(windowless) - 指定 Silverlight 插件是否为无窗口插件
-->
<object id="xaml1" data="data:application/x-silverlight-2," type="application/x-silverlight-2"
width="100%" height="100%">
< param name ="source" value ="../ClientBin/Silverlight20.xap" />
< param name ="minRuntimeVersion" value ="2.0.31005.0" />
< param name ="autoUpgrade" value ="true" />
< param name ="initParams" value ="key1=value1,key2=value2" />
< param name ="enableFrameRateCounter" value ="true" />
< param name ="maxFrameRate" value ="30" />
< param name ="enableRedrawRegions" value ="false" />
< param name ="enableHtmlAccess" value ="true" />
< param name ="windowless" value ="true" />
</object>
< iframe style ='visibility: hidden; height: 0; width: 0; border: 0px' > </iframe>
< ! --iframe 元素和其他附加到 HTML 的元素有助于确保跨浏览器兼容性。iframe 的存在可避免 Safari 浏览器缓存页面。当用户向后导航到以前访问过的 Silverlight 页面时,Safari 缓存可避免重新加载 Silverlight 插件-- >
</div>
</body>
</html>
OK
[源码下载]
[源码下载]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。