利用Silverlight DataGrID LoadingRow事件传入参数DataGrIDRowEventArgs
我们可以获取到Row对象She之其背景。
下面是一个简单示例
C# :
using System;System.Collections.Generic;
System.linq;
System.Net;
System.windows;
System.windows.Controls;
System.windows.documents;
System.windows.input;
System.windows.Media;
System.windows.Media.Animation;
System.windows.Shapes;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
MainPage()
{
InitializeComponent();
}
List < SourceModel > grIDSources = new List ();
private voID UserControl_Loaded( object sender,RoutedEventArgs e)
{
}
LoadSource( int n)
{
if (n 1 )
throw Exception( " should >=1 " );
grIDSources.Clear();
for ( i 0 ; i n; i ++ )
{
grIDSources.Add( SourceModel() { ID i.ToString(),name test + i,Group (( )( Random().NextDouble() * i)).ToString() });
}
j ;
grIDSources grIDSources.OrderBy(t => t.Group).ToList();
grIDSources.GroupBy(t t.Group).ToList().ForEach(t
{
t.ToList().ForEach(k k.BG brushs[j % brushs.Length]);
j ;
});
}
Brush[] brushs Brush[] { SolIDcolorBrush(color.FromArgb( 128 , 135 206 235 )), 255 240 140 97 )) };
test1_Click( grIDSources;
}
test2_Click( LoadSource_Click( .Parse( this .maxCount.Text));
}
dgSource_LoadingRow( (e.Row.DataContext as SourceModel).BG;
}
}
SourceModel
{
string ID { get ; set ; }
name { Group { Brush BG { ; }
}
}
XAMl:
< UserControl x:Class ="SilverlightApplication1.MainPage"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:data ="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Data"
d:DesignHeight ="300" d:DesignWIDth ="400"
xmlns:i ="http://schemas.microsoft.com/Expression/2010/interactivity"
xmlns:sdk ="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:Test ="clr-namespace:SilverlightApplication1;assembly=SilverlightApplication1" > GrID x:name ="LayoutRoot" GrID.RowDeFinitions RowDeFinition ></ RowDeFinition RowDeFinition Height ="26" </ data:DataGrID GrID.Row ="0" x:name ="dgSource" margin ="3,3,3" RowBackground ="Black" autoGenerateColumns ="False" LoadingRow ="dgSource_LoadingRow" data:DataGrID.Columns data:DataGrIDTextColumn header ="ID" Binding =" {Binding ID} " IsReadonly ="True" /> ="name" {Binding name,Mode=TwoWay} ="Group" {Binding Group,0)">
data:DataGrID StackPanel OrIEntation ="Horizontal" GrID.Row ="1" TextBox ="maxCount" WIDth Text ="100000" TextBox button ="loadSource1" Click ="LoadSource_Click" Content ="Load Source" ="test1" ="test1_Click" ="Test bind" ="test2" ="test2_Click" ="Test 2" StackPanel GrID UserControl >
http://www.cnblogs.com/whitewolf/archive/2011/07/28/2119608.html
总结以上是内存溢出为你收集整理的Silverlight DataGrid行背景分组着色全部内容,希望文章能够帮你解决Silverlight DataGrid行背景分组着色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)