silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

2、DataGrid02.xaml <UserControl x:Class="Silverlight20.Data.DataGrid02"         xmlns="http://scheR_434_11845@as.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://scheR_434_11845@as.microsoft.com/winfx
@H_696_7@

2、DataGrid02.xaml
<UserControl x:Class="Silverlight20.Data.DataGrid02"
        xmlns="@R_674_10107@://scheR_434_11845@as.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="@R_674_10107@://scheR_434_11845@as.microsoft.com/winfx/2006/xaml"
        xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
        <StackPanel HorizontalAlignment="Left">

                <StackPanel Orientation="Vertical" Margin="5">
                
                        <checkBox Content="是否只读" Margin="5"    
                                checked="chkReadOnly_Changed" Unchecked="chkReadOnly_Changed" />

                        <checkBox Content="冻结列" Margin="5"
                                checked="chkFreezecolumn_Changed" Unchecked="chkFreezecolumn_Changed"/>

                        <checkBox Content="行的选中模式,是否只能单选" Margin="5"
                                checked="chkSELEctionMode_Changed" Unchecked="chkSELEctionMode_Changed" />

                        <checkBox Content="是否允许拖动列" Ischecked="true" Margin="5"    
                                checked="chkColReorder_Changed" Unchecked="chkColReorder_Changed"/>

                        <checkBox Content="是否允许改变列的宽度" Ischecked="true" Margin="5"
                                checked="chkColResize_Changed" Unchecked="chkColResize_Changed"/>
                                
                        <checkBox Content="是否允许列的排序" Ischecked="true" Margin="5"
                                checked="chkColSort_Changed" Unchecked="chkColSort_Changed"/>

                        <checkBox Content="改变表格的垂直分隔线的 Brush" Margin="5"    
                                checked="chkCustomGridLineVertical_Changed" Unchecked="chkCustomGridLineVertical_Changed"/>
                                
                        <checkBox Content="改变表格的水平分隔线的 Brush" Margin="5"
                                checked="chkCustomGridLineHorizontal_Changed" Unchecked="chkCustomGridLineHorizontal_Changed"/>

                        <ComboBox SELEctionChanged="cboHeaders_SELEctionChanged" Width="200" HorizontalAlignment="Left">
                                <ComboBoxItem Content="列头和行头均显示" Tag="All" />
                                <ComboBoxItem Content="只显示列头(认值)" Tag="column" IsSELEcted="True" />
                                <ComboBoxItem Content="只显示行头" Tag="Row" />
                                <ComboBoxItem Content="列头和行头均不显示" Tag="None" />
                        </ComboBox>

                </StackPanel>

                <!--
                GridLinesVisibility - 表格分隔线显示方式 [System.Windows.Controls.DataGridGridLinesVisibility枚举]
                        DataGridGridLinesVisibility.None - 都不显示
                        DataGridGridLinesVisibility.Horizontal - 只显示水平分隔线
                        DataGridGridLinesVisibility.Vertical - 只显示垂直分隔线认值
                        DataGridGridLinesVisibility.All - 显示水平和垂直分隔线
                rowBACkground - 奇数数据行背景
                AlternaTingRowBACkground - 偶数数据行背景
                -->
                <data:DataGrid x:Name="DataGrid1" Margin="5"
                        Width="400" Height="200"
                        AutoGeneratecolumns="false"
                        GridLinesVisibility="All"
                        rowBACkground="White"
                        AlternaTingRowBACkground="Yellow"
                        Itemssource="{Binding}"
                >

                        <data:DataGrid.columns>
                        
                                <!--
                                IsReadOnly - 该列的单元格是否只读
                                CanUserReorder - 该列是否可以拖动
                                CanUserResize - 该列是否可以改变列宽
                                CanUserSort - 该列是否可以排序
                                SortMemberPath - 该列的排序字段
                                -->
                                <data:DataGridTextcolumn Header="姓名" Binding="{Binding NamE}"    
                                        IsReadOnly="false"
                                        CanUserReorder="True"    
                                        CanUserResize="True"    
                                        CanUserSort="True"    
                                        SortMemberPath="Name"    
                                />
                                
                                <!--
                                Width - 列宽
                                        Auto - 根据列头内容的宽度和单元格内容的宽度自动设置列宽
                                        SizeToCells - 根据单元格内容的宽度设置列宽
                                        SizeToHeader - 根据列头内容的宽度设置列宽
                                        Pixel - 像素值
                                -->
                                <data:DataGridTextcolumn Header="生日" Binding="{Binding DayOfBirth}" Width="100" />
                                <data:DataGridTextcolumn Header="年龄" Binding="{Binding AgE}" />
                                <data:DataGridcheckBoxcolumn Header="性别" Binding="{Binding MalE}" />
                                <data:DataGridTextcolumn Header="姓名" Binding="{Binding NamE}" />
                                <data:DataGridTextcolumn Header="生日" Binding="{Binding DayOfBirth}" />
                                <data:DataGridTextcolumn Header="年龄" Binding="{Binding AgE}" />
                                <data:DataGridcheckBoxcolumn Header="性别" Binding="{Binding MalE}" />
                        </data:DataGrid.columns>

                </data:DataGrid>

        </StackPanel>
</UserControl>
 
DataGrid02.xaml.cs

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Collections.Generic;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Linq;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Net;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Controls;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Documents;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Input;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Media;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Media.Animation;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Shapes;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

namespace Silverlight20.Data

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

{

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

         public partial class DataGrid02 : UserControl

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

        {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 public DataGrid02()

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        initializeComponent();

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        BindData();

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 void BindData()

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        var source = new Data.sourceData();

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         // 设置 DataGrid 的数据源

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        DataGrid1.DataContext = source.GetData();

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 private void chkReadOnly_Changed( object sender,RoutedEventArgs E)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        checkBox chk = sender as checkBox;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         // IsReadOnly - 单元格是否只读。认值 false

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        DataGrid1.IsReadOnly = ( bool)chk.Ischecked;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 private void chkFreezecolumn_Changed( object sender,RoutedEventArgs E)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        checkBox chk = sender as checkBox;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         // FrozencolumnCount - 表格所冻结的列的总数(从左边开始数)。认值 0

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         if (chk.Ischecked == true)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                DataGrid1.FrozencolumnCount = 1;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         else if (chk.Ischecked == false)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                DataGrid1.FrozencolumnCount = 0;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 private void chkSELEctionMode_Changed( object sender,RoutedEventArgs E)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        checkBox chk = sender as checkBox;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         // SELEctionMode - 行的选中模式 [System.Windows.Controls.DataGridSELEctionMode枚举]

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         //         DataGridSELEctionMode.Single - 只能单选

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         //         DataGridSELEctionMode.Extended - 可以多选(通过Ctrl或Shift的配合)。认值

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         if (chk.Ischecked == true)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                DataGrid1.SELEctionMode = DataGridSELEctionMode.Single;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         else if (chk.Ischecked == false)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                DataGrid1.SELEctionMode = DataGridSELEctionMode.Extended;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 private void chkColReorder_Changed( object sender,RoutedEventArgs E)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        checkBox chk = sender as checkBox;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         // CanUserReordercolumns - 是否允许拖动列。认值 true

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         if (DataGrid1 != null)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                DataGrid1.CanUserReordercolumns = ( bool)chk.Ischecked;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 private void chkColResize_Changed( object sender,RoutedEventArgs E)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        checkBox chk = sender as checkBox;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         // CanUserResizecolumns - 是否允许改变列的宽度。认值 true

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         if (DataGrid1 != null)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                DataGrid1.CanUserResizecolumns = ( bool)chk.Ischecked;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 private void chkColSort_Changed( object sender,RoutedEventArgs E)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        checkBox chk = sender as checkBox;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         // CanUserSortcolumns - 是否允许列的排序。认值 true

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         if (DataGrid1 != null)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                DataGrid1.CanUserSortcolumns = ( bool)chk.Ischecked;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 private void chkCustomGridLineVertical_Changed( object sender,RoutedEventArgs E)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        checkBox chk = sender as checkBox;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         if (DataGrid1 != null)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 // VerticalGridLinesBrush - 改变表格的垂直分隔线的 Brush

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 if (chk.Ischecked == true)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                        DataGrid1.VerticalGridLinesBrush = new SolidColorBrush(Colors.bluE);

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 else

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                        DataGrid1.VerticalGridLinesBrush = new SolidColorBrush(Color.FromArgb(255,223,227,230));

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 private void chkCustomGridLineHorizontal_Changed( object sender,RoutedEventArgs E)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        checkBox chk = sender as checkBox;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         if (DataGrid1 != null)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 // HorizontalGridLinesBrush - 改变表格的水平分隔线的 Brush

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 if (chk.Ischecked == true)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                        DataGrid1.HorizontalGridLinesBrush = new SolidColorBrush(Colors.bluE);

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 else

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                        DataGrid1.HorizontalGridLinesBrush = new SolidColorBrush(Color.FromArgb(255,230));

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 private void cboHeaders_SELEctionChanged( object sender,RoutedEventArgs E)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        ComboBoxItem cbi = ((ComboBox)sender).SELEctedItem as ComboBoxItem;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         if (DataGrid1 != null)

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 // HeadersVisibility - 表头(包括列头和行头)的显示方式 [System.Windows.Controls.DataGridHeadersVisibility枚举]

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 //         DataGridHeadersVisibility.All - 列头和行头均显示

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 //         DataGridHeadersVisibility.column - 只显示列头。认值

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 //         DataGridHeadersVisibility.Row - 只显示行头

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 //         DataGridHeadersVisibility.None - 列头和行头均不显示

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 if (cbi.Tag.ToString() == "All")

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                        DataGrid1.HeadersVisibility = DataGridHeadersVisibility.All;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 else if (cbi.Tag.ToString() == "column")

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                        DataGrid1.HeadersVisibility = DataGridHeadersVisibility.column;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 else if (cbi.Tag.ToString() == "Row")

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                        DataGrid1.HeadersVisibility = DataGridHeadersVisibility.Row;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                 else if (cbi.Tag.ToString() == "None")

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                                        DataGrid1.HeadersVisibility = DataGridHeadersVisibility.None;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

        }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

}
 
 
3、ListBox.xaml
<UserControl x:Class="Silverlight20.Data.ListBox"
        xmlns="@R_674_10107@://scheR_434_11845@as.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="@R_674_10107@://scheR_434_11845@as.microsoft.com/winfx/2006/xaml">
        <StackPanel HorizontalAlignment="Left">

                <!--
                ListBox.ItemTemplate - ListBox 的选项模板
                        DataTemplate - 手工定义 ListBox 的选项数据
                -->
                <ListBox x:Name="ListBox1" Margin="5" Width="200" Height="100">
                        <ListBox.ItemTemplate>
                                <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="{Binding NamE}" Margin="5" />
                                                <TextBlock Text="{Binding AgE}" Margin="5" />
                                        </StackPanel>
                                </DataTemplate>
                        </ListBox.ItemTemplate>
                </ListBox>
                
        </StackPanel>
</UserControl>
 
ListBox.xaml.cs

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Collections.Generic;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Linq;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Net;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Controls;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Documents;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Input;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Media;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Media.Animation;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

using System.Windows.Shapes;

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

namespace Silverlight20.Data

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

{

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

         public partial class ListBox : UserControl

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

        {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 public ListBox()

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        initializeComponent();    

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        BindData();

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                 void BindData()

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                {

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        var source = new Data.sourceData();

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox


上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                         // 设置 ListBox 的数据源

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                        ListBox1.Itemssource = source.GetData();

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

                }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

        }

上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

}
 
 
@H_489_1494@

大佬总结

以上是大佬教程为你收集整理的上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox全部内容,希望文章能够帮你解决上接稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。