• SilverlightDataGrid 示例


    <UserControl xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  x:Class="Silverlight.Common.uc_DataGrid"
        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"
        d:DesignHeight
    ="300" d:DesignWidth="400" >

        
    <Grid x:Name="LayoutRoot" Background="White">
            
    <my:DataGrid Height="300" HorizontalAlignment="Left" Name="dgList" Width="600">
                
    <my:DataGrid.Columns>
                    
    <my:DataGridTextColumn Header="ID" Binding="{Binding ID}" Width="100"></my:DataGridTextColumn>
                        
    <my:DataGridTemplateColumn Header="分类">
                            
    <my:DataGridTemplateColumn.CellTemplate>
                            
    <DataTemplate>
                                
    <StackPanel Orientation="Horizontal">
                                    
    <Image Width="{Binding Width}" Height="{Binding Height}" Source="{Binding Source}" MouseLeftButtonDown="Image_MouseLeftButtonDown"></Image>
                                
    </StackPanel>
                            
    </DataTemplate>
                            
    </my:DataGridTemplateColumn.CellTemplate>
                        
    </my:DataGridTemplateColumn>
                
    </my:DataGrid.Columns>
            
    </my:DataGrid>
        
    </Grid>
    </UserControl>
    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 Silverlight.Common
    {
        
    public partial class uc_DataGrid : UserControl
        {
            
    public uc_DataGrid()
            {
                InitializeComponent();
                Bind();
            }
            List
    <Model> list = new List<Model>();
            
    public class Model
            {
                
    public int ID { getset; }
                
    public int Width { getset; }
                
    public int Height { getset; }
                
    public string Source { getset; }
                
    public Model() { }
                
    public Model(int _ID, int _Width, int _Height, string _Source)
                {
                    ID 
    = _ID;
                    Width 
    = _Width;
                    Height 
    = _Height;
                    Source 
    = _Source;
                }
            }
            
    private void Bind()
            {
                list.Clear();
                list.Add(
    new Model(110050"icon/btnNew.jpg"));
                list.Add(
    new Model(250100"icon/btnOpen.jpg"));

                dgList.ItemsSource 
    = list;
            }

            
    private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                Model model 
    = dgList.SelectedItem as Model;
                
    //MessageBox.Show(model.ID.ToString());
                if (model.ID == 1)
                {
                    BindNew();
                }
                
    if (model.ID == 2)
                {
                    BindNew2();
                }

            }
            
    private void BindNew()
            {
                list.Clear();
                list.Add(
    new Model(110050"icon/btnNew.jpg"));
                list.Add(
    new Model(250100"icon/btnOpen.jpg"));
                list.Add(
    new Model(350100"icon/btnOpen.jpg"));

                dgList.ItemsSource 
    = list;
            }
            
    private void BindNew2()
            {
                list.Clear();
                list.Add(
    new Model(110050"icon/btnNew.jpg"));
                list.Add(
    new Model(250100"icon/btnOpen.jpg"));

                dgList.ItemsSource 
    = list;
            }
        }
    }

    说明: 示例所需图片自己添加

  • 相关阅读:
    三层架构补充
    复习三层架构
    复习DOM、JQuery
    复习HTML CSS JavaScript
    Git在新电脑拉github 上的项目
    超全的IE兼容性问题及解决方案
    JS操作iframe
    attachEvent和addEventListener
    HTTP 方法:GET 对比 POST
    原生JS+ CSS3创建loading加载动画;
  • 原文地址:https://www.cnblogs.com/xh831213/p/1780703.html
Copyright © 2020-2023  润新知