zoukankan      html  css  js  c++  java
  • Silverlight浮动窗体 floatablewindow 非模态对话框

    1.http://www.cnblogs.com/yinxiangpei/articles/2613913.html

    说明:Silverlight的ChildWindow组件给我们的开发带来了便利,比如说我们可以用它开发自定义对话框等。然而,这同时也带来了这样一个问题,ChildWindow组件只能以Modal Window(模式窗口)的形式进行应用,这也就是说同一时间只能有一个子窗体出现在应用程序中;另外,ChildWindow组件不能进行窗体大小的自定义缩放。如果我们想要开发多窗口的应用程序的话,ChildWindow显然就不能满足我们的要求了。幸运的是,Tim Heuer为我们提供了Non-Modal Used ChildWindow组件(非模式使用子窗体——Tim Heuer称之为浮动窗体[FloatableWindow])【下载】【应用程序模板】。这样我们就能轻松地开发多窗体应用了。

    组件所在的命名空间:

    System.Windows.Controls

    组件常用属性:

    [以下属性继承自ChildWindow]

    DialogResult:获取或者设置一个值用来显示子窗体的反馈内容是否被接受或是取消。

    HasCloseButton:获取或者设置一个值用来显示子窗体是否包含关闭按钮。

    OverlayBrush:获取或者设置被用于当子窗体打开时覆盖在父窗体上的遮盖层的笔刷。

    OverlayOpacity:获取或者设置被用于当子窗体打开时覆盖在父窗体上的遮盖层的笔刷的透明度。

    Title:获取或者设置子窗体的窗口标题。

    [以下属性为该组件特有属性]

    HorizontalOffset:获取或者设置浮动窗口出现位置的水平偏移量。

    IsModal:获取浮动窗体是否为模式窗体。

    ParentLayoutRoot:获取或者设置父窗体的根部布局。[使用时必须设置]

    ResizeMode:获取或者设置浮动窗体的缩放模式。

    VerticalOffset:获取或者设置浮动窗口出现位置的垂直偏移量。

    组件常用方法:

    Close:关闭子窗体。

    Show:以非模式窗口形式打开子窗体并返回而不等待该子窗体关闭。[此时,IsModal为false]

    Show(horizontalOffsetverticalOffset):设置出现位置后,以非模式窗口形式打开子窗体并返回而不等待该子窗体关闭。[此时,IsModal为false]

    ShowDialog:以模式窗口形式打开子窗体并返回而不等待该子窗体关闭。[此时,IsModal为true]

    组件常用事件:

    Closed:当子窗体关闭后发生。

    Closing:当子窗体正在关闭时发生。

    代码段:

    MainPage.xaml代码

     1 <UserControl x:Class="SilverlightClient.MainPage"
     2 
     3     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     4 
     5     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     6 
     7     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     8 
     9     mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" Width="640" Height="480">
    10 
    11   <Grid x:Name="LayoutRoot" Background="White" Width="640" Height="480">
    12 
    13     <Button x:Name="btnCreateFloatableWindow" Margin="207,30,221,0" Content="创建浮动窗体" Height="43" VerticalAlignment="Top"FontSize="16" Width="212"/>
    14 
    15   </Grid>
    16 
    17 </UserControl>
    View Code

    MainPage.xaml.cs代码:

     1 using System;
     2 
     3 using System.Collections.Generic;
     4 
     5 using System.Linq;
     6 
     7 using System.Net;
     8 
     9 using System.Windows;
    10 
    11 using System.Windows.Controls;
    12 
    13 using System.Windows.Documents;
    14 
    15 using System.Windows.Input;
    16 
    17 using System.Windows.Media;
    18 
    19 using System.Windows.Media.Animation;
    20 
    21 using System.Windows.Shapes;
    22 
    23  
    24 
    25 namespace SilverlightClient
    26 
    27 {
    28 
    29     public partial class MainPage : UserControl
    30 
    31     {
    32 
    33        
    34 
    35         public MainPage()
    36 
    37         {
    38 
    39             InitializeComponent();
    40 
    41             //注册事件触发处理
    42 
    43             this.btnCreateFloatableWindow.Click += new RoutedEventHandler(btnCreateFloatableWindow_Click);
    44 
    45         }
    46 
    47  
    48 
    49         void btnCreateFloatableWindow_Click(object sender, RoutedEventArgs e)
    50 
    51         {
    52 
    53             FloatableWindow fw = new FloatableWindow();//创建浮动窗口实例
    54 
    55             fw.ParentLayoutRoot = LayoutRoot;//指定承载浮动窗口的父窗口的根布局元素[这里为Grid x:Name="LayoutRoot"]
    56 
    57             fw.Title = "Test Floatable Window";//浮动窗口标题
    58 
    59             fw.Content = "The time is " + DateTime.Now.ToLongTimeString();//浮动窗体内容
    60 
    61             fw.Width = 300;//浮动窗口的宽度
    62 
    63             fw.Height = 200;//浮动窗口的高度
    64 
    65             fw.ResizeMode = ResizeMode.CanResize;//设置浮动窗口可自定义缩放
    66 
    67             fw.Show();//以非模式窗口形式打开窗体
    68 
    69         }
    70 
    71     }
    72 
    73 }
    View Code

    FloatableWindowDemo.xaml代码:

     1 <controls:FloatableWindow x:Class="SilverlightClient.control.FloatableWindowDemo"
     2 
     3            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     4 
     5            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     6 
     7            xmlns:controls="clr-namespace:System.Windows.Controls;assembly=FloatableWindow"
     8 
     9            Width="400" Height="300"
    10 
    11            Title="FloatableWindowDemo">
    12 
    13     <Grid x:Name="LayoutRoot" Margin="2">
    14 
    15         <Grid.RowDefinitions>
    16 
    17             <RowDefinition />
    18 
    19             <RowDefinition Height="Auto" />
    20 
    21         </Grid.RowDefinitions>
    22 
    23         <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right"Margin="0,12,0,0" Grid.Row="1" />
    24 
    25         <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right"Margin="0,12,79,0" Grid.Row="1" />
    26 
    27     </Grid>
    28 
    29 </controls:FloatableWindow>
    View Code

    FloatableWindowDemo.xaml.cs代码:

     1 using System;
     2 
     3 using System.Collections.Generic;
     4 
     5 using System.Linq;
     6 
     7 using System.Net;
     8 
     9 using System.Windows;
    10 
    11 using System.Windows.Controls;
    12 
    13 using System.Windows.Documents;
    14 
    15 using System.Windows.Input;
    16 
    17 using System.Windows.Media;
    18 
    19 using System.Windows.Media.Animation;
    20 
    21 using System.Windows.Shapes;
    22 
    23  
    24 
    25 namespace SilverlightClient.control
    26 
    27 {
    28 
    29     public partial class FloatableWindowDemo : FloatableWindow
    30 
    31     {
    32 
    33         public FloatableWindowDemo()
    34 
    35         {
    36 
    37             InitializeComponent();
    38 
    39         }
    40 
    41  
    42 
    43         private void OKButton_Click(object sender, RoutedEventArgs e)
    44 
    45         {
    46 
    47             this.DialogResult = true;
    48 
    49         }
    50 
    51  
    52 
    53         private void CancelButton_Click(object sender, RoutedEventArgs e)
    54 
    55         {
    56 
    57             this.DialogResult = false;
    58 
    59         }
    60 
    61     }
    62 
    63 }
    View Code

    http://www.cnblogs.com/Kinglee/

    2.

     1 MainManage panel = new MainManage();
     2                 FloatableWindow tempFW = new FloatableWindow();
     3                 tempFW.DialogResult = true;
     4                 tempFW.Width = width;
     5                 tempFW.Height = height;
     6                 tempFW.Title = "";                           //窗口标题 系统管理界面
     7                 tempFW.HasCloseButton = true;                            //是否显示X按钮
     8                 tempFW.ParentLayoutRoot = this.floatePanel;                   //父容器可以是Gird、Canvas等 
     9                 tempFW.Content = panel;  //窗口内容,可以是文字,也可以是UserControl等
    10                 tempFW.ResizeMode = ResizeMode.CanMinimize;
    11                 tempFW.ShowDialog();
    View Code
  • 相关阅读:
    RegExp正则表达式心得 1 -分解MIME格式
    转载:ASP.Net性能优化(作者:刘鉴平)
    asp.Net中的多文件上传[载]
    我做的程序
    C#代码执行者1.0
    wordwrap,wordbreak,whitespace,textoverflow的区别和用法[转]
    SQL里面Case的用法
    richTextBox中插入图片的方法
    关于CodeDom的测试
    关系数据库的索引技术
  • 原文地址:https://www.cnblogs.com/zxbzl/p/3769656.html
Copyright © 2011-2022 走看看