前面研究过不同窗体间传值的方法,觉得有点委曲的用法,又有不少朋友问怎么窗体传值,下面用个最简单的方法:

1.在需要获取传来的值的那个页的后台(.CS)的构造函数(如MainPage.xaml.cs的是MainPage()方法)添加传值的接收形参:

private Class getclassname;
MainPage(Class classname)
{
   InitializeComponent();
   getclassname
=classname;//两个参数变量类型必须相同
  .............
}  

2.在抛出外传值的那个页面(ThrowValuePage或ThrowValueUserControl)定义这个接受值页面(GetValuePage或GetValueUserControl):

 

public Class ThrowValueToMainPage:UserControl/Page/.....
{
   
public ThrowValueToMainPage()
   {
      
string throwvalue="the value that mainpage need";//随意定义类型
      this.Content=new MainPage(throwvalue);//最基本的传值方法,相信现在不明白的朋友知道了吧,下面顺便介绍下Content属性
   }
}

 

Content 类型公开以下成员。

  名称 说明
Silverlight最简单的页面传值方法 ActualHeight 获取 Silverlight 插件内容区域的浏览器确定的高度。
Silverlight最简单的页面传值方法 ActualWidth 获取 Silverlight 插件内容区域的浏览器确定的宽度。
Silverlight最简单的页面传值方法 IsFullScreen 获取或设置一个值,该值指示 Silverlight 插件是否正以全屏模式显示。
Silverlight最简单的页面传值方法 ZoomFactor 获取一个系数,当前浏览器窗口将按照该系数来调整其内容大小。
  名称 说明
Silverlight最简单的页面传值方法 FullScreenChanged 在承载的 Silverlight 插件进入或退出全屏模式时发生。
Silverlight最简单的页面传值方法 Resized 在 Silverlight 插件的 ActualWidth 更改时发生。
Silverlight最简单的页面传值方法 Zoomed 当宿主浏览器窗口中的缩放设置更改或初始化时发生。

 

Content..::.FullScreenChanged 事件

在承载的 Silverlight 插件进入或退出全屏模式时发生。

命名空间:  System.Windows.Interop
程序集:  System.Windows(在 System.Windows.dll 中)
public event EventHandler FullScreenChanged

事件本身不报告状态。在您处理该事件后,立即检查 IsFullScreen

下面的代码示例演示如何使用此事件。

 
new Page();
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = rootPage;
rootPage.LayoutRoot.MouseLeftButtonDown +=
delegate(Object s, MouseButtonEventArgs args) {
this.Host.Content.IsFullScreen =
!this.Host.Content.IsFullScreen;
};
this.Host.Content.FullScreenChanged +=
new EventHandler(DisplaySizeInformation);
this.Host.Content.Resized +=
new EventHandler(DisplaySizeInformation);
}
private void DisplaySizeInformation(Object sender, EventArgs e)
{
String message = String.Format(
"ActualWidth={0}, ActualHeight={1}",
this.Host.Content.ActualWidth,
this.Host.Content.ActualHeight);
rootPage.LayoutRoot.Children.Clear();
rootPage.LayoutRoot.Children.Add(
new TextBlock { Text = message });
}

 

 

Content..::.Resized 事件

在 Silverlight 插件的 ActualWidth 更改时发生。

命名空间:  System.Windows.Interop
程序集:  System.Windows(在 System.Windows.dll 中)
public event EventHandler Resized

在开始加载 Silverlight 插件时此事件将发生。在发生该事件后,ActualWidth 的值不可靠。

下面的代码示例演示如何使用此事件。

复制代码

new Page();
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = rootPage;
rootPage.LayoutRoot.MouseLeftButtonDown +=
delegate(Object s, MouseButtonEventArgs args) {
this.Host.Content.IsFullScreen =
!this.Host.Content.IsFullScreen;
};
this.Host.Content.FullScreenChanged +=
new EventHandler(DisplaySizeInformation);
this.Host.Content.Resized +=
new EventHandler(DisplaySizeInformation);
}
private void DisplaySizeInformation(Object sender, EventArgs e)
{
String message = String.Format(
"ActualWidth={0}, ActualHeight={1}",
this.Host.Content.ActualWidth,
this.Host.Content.ActualHeight);
rootPage.LayoutRoot.Children.Clear();
rootPage.LayoutRoot.Children.Add(
new TextBlock { Text = message });
}
Content..::.Zoomed 事件

当宿主浏览器窗口中的缩放设置更改或初始化时发生。

命名空间:  System.Windows.Interop
程序集:  System.Windows(在 System.Windows.dll 中)
 

可以通过 ZoomFactor 属性访问当前浏览器窗口的缩放设置。

浏览器缩放设置可能影响依赖于宿主网页内插件的精确大小调整或位置的任何代码。不同的浏览器以不同方式响应缩放设置。操作系统的每英寸点数 (DPI) 显示设置也可能影响缩放设置。如果应用程序使用自定义大小调整逻辑,请确保在不同的浏览器中使用高的 DPI 设置来测试它。

以上部分来自MSDN

相关文章: