1) 前台代码
<UserControl xmlns:data="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="SilverlightApplication131.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" d:DesignHeight="300" d:DesignWIDth="400"> <GrID x:name="LayoutRoot" Background="White"> <data:DataGrID name="TestDataGrID" autoGenerateColumns="False"> <data:DataGrID.Columns> <data:DataGrIDTextColumn @R_404_5548@="ClassID" Binding="{Binding ClassID}"></data:DataGrIDTextColumn> <data:DataGrIDTextColumn @R_404_5548@="Classname" Binding="{Binding Classname}"></data:DataGrIDTextColumn> </data:DataGrID.Columns> </data:DataGrID> </GrID></UserControl>
2)后台代码
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 SilverlightApplication131{ public partial class MainPage : UserControl { private List<ClassDemo> classItems = null; private List<StudentDemo> studentItems = null; public MainPage() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MainPage_Loaded); TestDataGrID.LoadingRow += new EventHandler<DataGrIDRowEventArgs>(TestDataGrID_LoadingRow); } /// <summary> /// 获取班级 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> voID MainPage_Loaded(object sender,RoutedEventArgs e) { GetClassDemo(); GetStudentDemo(); TestDataGrID.ItemsSource = classItems; } private voID GetClassDemo() { classItems = new List<ClassDemo>(); classItems.Add(new ClassDemo(1,"一班")); classItems.Add(new ClassDemo(2,"二班")); classItems.Add(new ClassDemo(3,"三班")); classItems.Add(new ClassDemo(4,"四班")); } /// <summary> /// 获取学生 /// </summary> private voID GetStudentDemo() { studentItems = new List<StudentDemo>(); studentItems.Add(new StudentDemo(1,"张1",1)); studentItems.Add(new StudentDemo(2,"张2",2)); studentItems.Add(new StudentDemo(3,"张3",2)); studentItems.Add(new StudentDemo(4,"张4",3)); studentItems.Add(new StudentDemo(5,"张5",3)); studentItems.Add(new StudentDemo(6,"张6",3)); studentItems.Add(new StudentDemo(7,"张7",4)); } /// <summary> /// 在加载DataGrIDRow时设置tooltip /// </summary> /// <param name="sender"></param> /// <param name="e"></param> voID TestDataGrID_LoadingRow(object sender,DataGrIDRowEventArgs e) { ClassDemo item = e.Row.DataContext as ClassDemo; tooltipService.Settooltip(e.Row,GenerateStackPanel(item)); } /// <summary> /// 生成StackPanel /// </summary> /// <param name="classID"></param> /// <returns></returns> private StackPanel GenerateStackPanel(ClassDemo classItem) { StackPanel stackPanel = new StackPanel(); stackPanel.OrIEntation = OrIEntation.Vertical; IEnumerable<StudentDemo> items = studentItems.Where(u => u.ClassID == classItem.ClassID); //显示班级信息 TextBlock classtextBlock = new TextBlock(); classtextBlock.Foreground = new SolIDcolorBrush(colors.Red); classtextBlock.Text = classItem.Classname; stackPanel.Children.Add(classtextBlock); //显示学生信息 if (items.Count() > 0) { foreach (StudentDemo item in items) { TextBlock studentTextBlock = new TextBlock(); studentTextBlock.Text = item.Studentname; stackPanel.Children.Add(studentTextBlock); } } return stackPanel; } } /// <summary> /// 学生类 /// </summary> public class StudentDemo { public StudentDemo() { } public StudentDemo(int _studentID,string _studentname,int _classID) { this.StudentID = _studentID; this.Studentname = _studentname; this.ClassID = _classID; } private int studentID; public int StudentID { get { return studentID; } set { studentID = value; } } private string studentname; public string Studentname { get { return studentname; } set { studentname = value; } } private int classID; public int ClassID { get { return classID; } set { classID = value; } } } /// <summary> /// 班级类 /// </summary> public class ClassDemo { public ClassDemo() { } public ClassDemo(int _classID,string _classname) { this.ClassID = _classID; this.Classname = _classname; } private int classID; public int ClassID { get { return classID; } set { classID = value; } } private string classname; public string Classname { get { return classname; } set { classname = value; } } }}总结
以上是内存溢出为你收集整理的Silverlight Datagrid 行上增加ToolTip全部内容,希望文章能够帮你解决Silverlight Datagrid 行上增加ToolTip所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)