SaveFileDialog, HeaderedItemsControl, VirtualizingStackPanel

SaveFileDialog, HeaderedItemsControl, VirtualizingStackPanel,第1张

概述SaveFileDialog, HeaderedItemsControl, VirtualizingStackPanel 介绍 Silverlight 3.0 控件一览: ·         ChildWindow - 用于在父窗体前d出一个的子窗体 ·         SaveFileDialog - 用户发起的保存文件对话框(OpenFileDialog - 打开文件对话框) ·       

SavefileDialog,headeredItemsControl,VirtualizingStackPanel

介绍
Silverlight 3.0 
控件一览:

·         ChilDWindow - 用于在父窗体前d出一个的子窗体

·         SavefileDialog - 用户发起的保存文件对话框(OpenfileDialog - 打开文件对话框)

·         headeredItemsControl - 呈现标题和集合数据的控件

·         VirtualizingStackPanel - 虚拟化的 StackPanel(即仅生成需要显示的 UI 元素。当绑定了大量数据,而某时仅显示其中一小部分的时候,使用此控件则可大幅提高呈现效率) 


示例
1
、演示 ChilDWindow 的应用
ChilDWindowDemo.xaml

<navigation:Page x:Class="Silverlight30.Control.ChilDWindowDemo" 
           xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d
="http://schemas.microsoft.com/Expression/blend/2008"
           xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable
="d"
           xmlns:navigation
="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Navigation"
           d:DesignWIDth
="640" d:DesignHeight="480"
           Title
="ChilDWindowDemo Page">
    
<GrID x:name="LayoutRoot">
        
<StackPanel>

            
<button x:name="btnChilDWindow" Content="Show ChilDWindow" Click="btnChilDWindow_Click" />
            
<button x:name="btnCustomChilDWindow" Content="Show CustomChilDWindow" Click="btnCustomChilDWindow_Click" />
    
            
<TextBlock x:name="lblResult" />
            
        
</StackPanel>
    
</GrID>
</navigation:Page>

 
ChilDWindowDemo.xaml.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.Navigation;

namespace Silverlight30.Control
@H_404_406@{
    
public partial class ChilDWindowDemo : Page
    
@H_404_406@ {
        
public ChilDWindowDemo()
        
@H_404_406@ {
            InitializeComponent();
        }

        
private voID btnChilDWindow_Click(object sender, RoutedEventArgs e)
        
@H_404_406@ {
            
/**//*
             * ChilDWindow - 
在父窗体前显示的子窗体
             *     Title - 
子窗体的标题
             *     Content - 
子窗体的内容
             *     HasClosebutton - 
子窗体上是否要有关闭按钮(右上角的 ×
             *     OverlayBrush - 
子窗体打开后,覆盖在父窗体上的 Brush
             *     OverlayOpacity - 
子窗体打开后,覆盖在父窗体上的 Brush 的不透明度
             *     WIDth - 
子窗体的宽
             *     Height - 
子窗体的高
             *     Closed
事件 - 子窗体关闭后所触发的事件
             *     Show() - 
打开(显示)子窗体
             */


            ChilDWindow child = 
new ChilDWindow();
            child.Title = 
"标题";
            child.Content = 
"内容";
            child.HasClosebutton = 
true;
            child.OverlayBrush = 
new SolIDcolorBrush(colors.Red);
            child.OverlayOpacity = 
0.3;
            child.WIDth = 
320;
            child.Height = 
240;
            
            child.Show();
        }

        
voID child_Closed(object sender, EventArgs e)
        
@H_404_406@ {
            
/**//*
             * ChilDWindow.DialogResult - 
子窗体传递回来的一个 bool? 值(可以用来描述在子窗体中是单击了确定按钮还是取消按钮)
             * ChilDWindow.DataContext - 
子窗体传递回来的数据上下文
             */


            CustomChilDWindow child = sender 
as CustomChilDWindow;
            MessageBox.Show(
string.Format("DialogResult:{0}; DataContext:{1}", child.DialogResult, child.DataContext));
        }

        
private voID btnCustomChilDWindow_Click(object sender, RoutedEventArgs e)
        
@H_404_406@ {
            CustomChilDWindow child = 
new CustomChilDWindow();
            child.Closed += 
new EventHandler(child_Closed);
            child.Show();
        }
    }
}


CustomChilDWindow.xaml
(自定义子窗体)

<controls:ChilDWindow x:Class="Silverlight30.Control.CustomChilDWindow"
           xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:controls
="clr-namespace:System.windows.Controls;assembly=System.windows.Controls"
           WIDth
="320" Height="240" 
           Title
="我是标题">
    
<GrID x:name="LayoutRoot" margin="2">
        
<GrID.RowDeFinitions>
            
<RowDeFinition />
            
<RowDeFinition Height="auto" />
        
</GrID.RowDeFinitions>

        
<button x:name="Cancelbutton" Content="Cancel" Click="Cancelbutton_Click" WIDth="75" Height="23" HorizontalAlignment="Right" margin="0,12,0" GrID.Row="1" />
        
<button x:name="OKbutton" Content="OK" Click="OKbutton_Click" WIDth="75" Height="23" HorizontalAlignment="Right" margin="0,79,0" GrID.Row="1" />
    
</GrID>
</controls:ChilDWindow>


CustomChilDWindow.xaml.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;

namespace Silverlight30.Control
@H_404_406@{
    
public partial class CustomChilDWindow : System.windows.Controls.ChilDWindow
    
@H_404_406@ {
        
public CustomChilDWindow()
        
@H_404_406@ {
            InitializeComponent();
        }

        
private voID OKbutton_Click(object sender, RoutedEventArgs e)
        
@H_404_406@ {
            
/**//*
             * ChilDWindow.DialogResult - 
传递给父窗体的一个 bool? 值(可以用来描述在子窗体中是单击了确定按钮还是取消按钮)
             * ChilDWindow.DataContext - 
传递给父窗体的数据上下文
             */


            
this.DataContext = "点击了 OK 按钮";
            
this.DialogResult = true;
        }

        
private voID Cancelbutton_Click(object sender, RoutedEventArgs e)
        
@H_404_406@ {
            
this.DataContext = "点击了 Cancel 按钮";
            
this.DialogResult = false;
        }
    }
}



2
SavefileDialog OpenfileDialog 的演示
SavefileDialogDemo.xaml

<navigation:Page x:Class="Silverlight30.Control.SavefileDialogDemo" 
           xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d
="http://schemas.microsoft.com/Expression/blend/2008"
           xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable
="d"
           xmlns:navigation
="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Navigation"
           d:DesignWIDth
="640" d:DesignHeight="480"
           Title
="SavefileDialog Page">
    
<GrID x:name="LayoutRoot">
        
<StackPanel>
        
            
<TextBox x:name="txtInfo" />
            
<button x:name="btnSave" Content="保存" Click="btnSave_Click" />
            
<button x:name="btnLoad" Content="载入" Click="btnLoad_Click" />
            
        
</StackPanel>
    
</GrID>
</navigation:Page>


SavefileDialogDemo.xaml.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.Navigation;

using System.IO;
using System.Text;

namespace Silverlight30.Control
@H_404_406@{
    
public partial class SavefileDialogDemo : Page
    
@H_404_406@ {
        
public SavefileDialogDemo()
        
@H_404_406@ {
            InitializeComponent();
        }

        
private voID btnSave_Click(object sender, RoutedEventArgs e)
        
@H_404_406@ {
            
/**//*
             * SavefileDialog - 
用户发起的保存文件对话框
             *     Filter - 
指定保存文件的描述信息及文件类型(出现在对话框的保存类型下拉列表中)
             *     DefaultExt - 
当指定保存文件类型为 *.* 时的默认扩展名
             *     FilterIndex - 
默认的保存类型在 Filter 中的索引(注意:索引从 1 开始)
             *     ShowDialog() - 
显示保存文件对话框。用户在对话框中单击保存则返回 true;单击取消或关闭对话框则返回 false
             *     Openfile() - 
打开用户选择的文件,并返回文件流
             */


            SavefileDialog dialog = 
new SavefileDialog();
            dialog.Filter = 
"Text files|*.txt|Log files|*.log|All files|*.*";
            dialog.FilterIndex = 
1;

            
bool? result = dialog.ShowDialog();
            
if (result == true)
            
@H_404_406@ {
                
using (Stream stream = dialog.Openfile())
                
@H_404_406@ {
                    
byte[] info = EnCoding.UTF8.GetBytes(txtInfo.Text);
                    stream.Write(info, 
0, info.Length);
                }

                txtInfo.Text = 
"";
            }
        }

        
private voID btnLoad_Click(object sender, RoutedEventArgs e)
        
@H_404_406@ {
            
/**//*
             * OpenfileDialog - 
打开文件对话框
             *     Filter - 
 SavefileDialog
             *     FilterIndex - 
 SavefileDialog
             *     ShowDialog() - 
显示打开文件对话框。用户在对话框中单击打开则返回 true;单击取消或关闭对话框则返回 false
             *     file - 
返回用户所选择文件的的 fileInfo 对象
             *     Multiselect - 
选择文件时可否多选
             *     files - 
返回用户所选择文件的的 fileInfo 对象集合
             */


            OpenfileDialog dialog = 
new OpenfileDialog();
            dialog.Filter = 
"Text files|*.txt";
            
            
if (dialog.ShowDialog() == true)
            
@H_404_406@ {
                
using (fileStream fs = dialog.file.OpenRead())
                
@H_404_406@ {
                    
byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, buffer.Length);

                    txtInfo.Text = EnCoding.UTF8.GetString(buffer, buffer.Length);                }            }        }    }}

总结

以上是内存溢出为你收集整理的SaveFileDialog, HeaderedItemsControl, VirtualizingStackPanel全部内容,希望文章能够帮你解决SaveFileDialog, HeaderedItemsControl, VirtualizingStackPanel所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1029042.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存