稳扎稳打Silverlight(4) - 2.0控件之DataGrid, DatePicker, Grid, GridSplitter, HyperlinkButton, Image...

[索引页]
[源码下载]


稳扎稳打Silverlight(4) - 2.0控件之DataGrid, DatePicker, Grid, GridSplitter, HyperlinkButton, Image


作者: webabcd


介绍
Silverlight 2.0 控件一览:DataGrid, DatePicker, Grid, GridSplitter, HyperlinkButton, Image 


在线DEMO
http://webabcd.blog.51cto.com/1787395/342779 


示例 
1、DataGrid.xaml
<UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"    x:Class="Silverlight20.Control.DataGrid" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
        <StackPanel HorizontalAlignment="Left"> 
                 
                <!-- 
                后台邦定方式,自动生成列 
                --> 
                <data:DataGrid x:Name="dgrd" AutoGenerateColumns="True"></data:DataGrid> 
                 
        </StackPanel> 
</UserControl>
 
DataGrid.xaml.cs
InBlock.gif using System; 
InBlock.gif using System.Collections.Generic; 
InBlock.gif using System.Linq; 
InBlock.gif using System.Net; 
InBlock.gif using System.Windows; 
InBlock.gif using System.Windows.Controls; 
InBlock.gif using System.Windows.Documents; 
InBlock.gif using System.Windows.Input; 
InBlock.gif using System.Windows.Media; 
InBlock.gif using System.Windows.Media.Animation; 
InBlock.gif using System.Windows.Shapes; 
InBlock.gif 
InBlock.gif namespace Silverlight20.Control 
InBlock.gif
InBlock.gif         public partial  class DataGrid : UserControl 
InBlock.gif        { 
InBlock.gif                 public DataGrid() 
InBlock.gif                { 
InBlock.gif                        InitializeComponent(); 
InBlock.gif 
InBlock.gif                        BindData(); 
InBlock.gif                } 
InBlock.gif 
InBlock.gif                 void BindData() 
InBlock.gif                { 
InBlock.gif                        var source =  new Data.SourceData(); 
InBlock.gif 
InBlock.gif                         // 设置 DataGrid 的数据源 
InBlock.gif                        dgrd.ItemsSource = source.GetData().Take(10); 
InBlock.gif                } 
InBlock.gif        } 
InBlock.gif}
 
 
2、DatePicker.xaml
<UserControl x:Class="Silverlight20.Control.DatePicker" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
        xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"> 
        <StackPanel HorizontalAlignment="Left"> 
                 
                <!-- 
                TextBox 结合 Calendar,经典的选择日期的方式 
                SelectedDateFormat - 被选中的日期的显示格式 [System.Windows.Controls.DatePickerFormat枚举] 
                        SelectedDateFormat.Short - 简短格式。默认值。如2008-10-10 
                        SelectedDateFormat.Long - 非简短格式。如2008年10月10日 
                --> 
                <basics:DatePicker Width="200" SelectedDateFormat="Short"></basics:DatePicker> 
                 
        </StackPanel> 
</UserControl>
 
 
3、Grid.xaml
<UserControl x:Class="Silverlight20.Control.Grid" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
        Width="Auto" Height="500"> 
         
        <!-- 
        Grid - 表格式布局模式 
                Grid.RowDefinitions - 用于定义 Grid 中的行 
                Grid.ColumnDefinitions - 用于定义 Grid 中的列 
                Grid.ShowGridLines - 显示网格 
         
                Grid.Row - 控件所在的 Grid 的行的索引 
                Grid.Column - 控件所在的 Grid 的列的索引 
                Grid.RowSpan - 合并行。 控件所在行,以及控件所在行之后的需要连续合并的行的总行数 
                Grid.ColumnSpan - 合并列。 控件所在列,以及控件所在列之后的需要连续合并的列的总列数 
         
                Width - 宽度 
                MinWidth - 最小宽度 
                MaxWidth - 最大宽度 
                Height - 高度 
                MinHeight - 最小高度 
                MaxHeight - 最大高度 
         
        Width 和 Height 的可用值 
        Auto - 自动设置为一个合适的值。默认值 
        Pixel - 像素值 
        * - 比例值。如 * 就是全部,2* & 8* 就是分别占20%和80% 
        --> 
        <Grid x:Name="LayoutRoot" Background="White" ShowGridLines="True"> 
                 
                <Grid.RowDefinitions> 
                        <RowDefinition Height="50" /> 
                        <RowDefinition Height="3*" /> 
                        <RowDefinition Height="7*" /> 
                        <RowDefinition Height="*" MinHeight="200" MaxHeight="500" /> 
                        <RowDefinition Height="Auto" /> 
                </Grid.RowDefinitions> 
                 
                <Grid.ColumnDefinitions> 
                        <ColumnDefinition /> 
                        <ColumnDefinition /> 
                        <ColumnDefinition /> 
                </Grid.ColumnDefinitions> 
                 
                <TextBox Grid.Row="0" Grid.Column="0" Background="red" Text="abc" /> 
                <TextBox Grid.Row="0" Grid.Column="1" Background="red" Text="abc" Grid.ColumnSpan="2" HorizontalAlignment="Center" /> 
                <TextBox Grid.Row="1" Grid.Column="0" Background="red" Text="abc" /> 
                <TextBox Grid.Row="1" Grid.Column="1" Background="red" Text="abc" Grid.ColumnSpan="2" HorizontalAlignment="Center" /> 
                <TextBox Grid.Row="2" Grid.Column="0" Background="red" Text="abc" /> 
                <TextBox Grid.Row="2" Grid.Column="1" Background="red" Text="abc" Grid.RowSpan="2" VerticalAlignment="Bottom" /> 
                <TextBox Grid.Row="2" Grid.Column="2" Background="red" Text="abc" /> 
                <TextBox Grid.Row="3" Grid.Column="2" Background="red" Text="abc" /> 
                <TextBox Grid.Row="4" Grid.Column="2" Background="red" Text="abc" /> 
                 
        </Grid> 
         
</UserControl>
 
 
4、GridSplitter.xaml
<UserControl x:Class="Silverlight20.Control.GridSplitter" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"> 
        <Grid x:Name="LayoutRoot" Background="White"> 
                 
                <Grid.RowDefinitions> 
                        <RowDefinition Height="100" /> 
                        <RowDefinition Height="5" /> 
                        <RowDefinition Height="100" /> 
                </Grid.RowDefinitions> 
                 
                <Grid.ColumnDefinitions> 
                        <ColumnDefinition Width="100" /> 
                        <ColumnDefinition Width="5" /> 
                        <ColumnDefinition Width="100" /> 
                </Grid.ColumnDefinitions> 
                 
                <Rectangle Grid.Row="0" Grid.Column="0" Fill="Red"/> 
                <Rectangle Grid.Row="0" Grid.Column="2" Fill="Green" /> 
                <Rectangle Grid.Row="2" Grid.Column="0" Fill="Blue" /> 
                <Rectangle    Grid.Row="2" Grid.Column="2" Fill="Yellow" /> 
                 
                <!-- 
                ShowsPreview - 拖动 GridSplitter 时,是要即时显示拖动结果(false 默认值),还是要先预览GridSplitter被拖动的位置(true) 
                --> 
                <basics:GridSplitter Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" ShowsPreview="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
                <basics:GridSplitter Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
                 
        </Grid> 
</UserControl>
 
 
5、HyperlinkButton.xaml
<UserControl x:Class="Silverlight20.Control.HyperlinkButton" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
        <StackPanel HorizontalAlignment="Left"> 

                <!-- 
                NavigateUri - 超级链接的目标地址 
                TargetName - 目标名 
                --> 
                <HyperlinkButton Content="http://webabcd.cnblogs.com" NavigateUri="http://webabcd.cnblogs.com/" HorizontalContentAlignment="Center" TargetName="_blank" Background="Black" Foreground="White" Margin="5" Width="200" /> 

                <!-- 
                HyperlinkButton.Content - 超级链接所显示的内容 
                --> 
                <HyperlinkButton NavigateUri="http://webabcd.cnblogs.com/" TargetName="_blank" Margin="5" Width="200"> 
                        <HyperlinkButton.Content> 
                                <Image Source="/Silverlight20;component/Images/Logo.jpg" /> 
                        </HyperlinkButton.Content> 
                </HyperlinkButton> 

        </StackPanel> 
</UserControl>
 
 
6、Image.xaml
<UserControl x:Class="Silverlight20.Control.Image" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
        <StackPanel HorizontalAlignment="Left"> 
                 
                <!-- 
                Source - 程序目录下的图片文件地址 
                --> 
                <Image Source="/Logo.jpg" Margin="5" Width="100"    /> 
                 
                <!-- 
                Source - 程序集内的图片文件地址 [/程序集名;component/图片路径] 
                --> 
                <Image Source="/Silverlight20;component/Images/Logo.jpg" Margin="5" Width="200" /> 

                <!-- 
                Source - 互联网的图片文件地址 
                --> 
                <Image Source="http://silverlight.net/Themes/silverlight/images/logo.jpg" Margin="5" Width="100" /> 

                <!-- 
                Source - 后台方式设置Image的Source 
                --> 
                <Image x:Name="img" Margin="5" Width="100" /> 
                <Image x:Name="img2" Margin="5" Width="100" /> 

        </StackPanel> 
</UserControl>
 
Image.xaml.cs
InBlock.gif using System; 
InBlock.gif using System.Collections.Generic; 
InBlock.gif using System.Linq; 
InBlock.gif using System.Net; 
InBlock.gif using System.Windows; 
InBlock.gif using System.Windows.Controls; 
InBlock.gif using System.Windows.Documents; 
InBlock.gif using System.Windows.Input; 
InBlock.gif using System.Windows.Media; 
InBlock.gif using System.Windows.Media.Animation; 
InBlock.gif using System.Windows.Shapes; 
InBlock.gif 
InBlock.gif using System.Windows.Media.Imaging; 
InBlock.gif using System.Windows.Resources; 
InBlock.gif 
InBlock.gif namespace Silverlight20.Control 
InBlock.gif
InBlock.gif         public partial  class Image : UserControl 
InBlock.gif        { 
InBlock.gif                 public Image() 
InBlock.gif                { 
InBlock.gif                        InitializeComponent(); 
InBlock.gif 
InBlock.gif                         // 后台方式设置Image的Source 
InBlock.gif                        img.Source =  new BitmapImage( new Uri( "/Silverlight20;component/Images/Logo.jpg", UriKind.Relative)); 
InBlock.gif 
InBlock.gif                        StreamResourceInfo sri = Application.GetResourceStream( 
InBlock.gif                                 new Uri( "/Silverlight20;component/Images/Logo.jpg", UriKind.Relative)); 
InBlock.gif                        BitmapImage imageSource =  new BitmapImage(); 
InBlock.gif                        imageSource.SetSource(sri.Stream); 
InBlock.gif                        img2.Source = imageSource; 
InBlock.gif                } 
InBlock.gif        } 
InBlock.gif}
 
 
 


     本文转自webabcd 51CTO博客,原文链接:http://blog.51cto.com/webabcd/342806 ,如需转载请自行联系原作者

内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值