1.首先构造实体类Team
view plain public class Team { public Team(string name) { this.name = name; } string name { get; set; } }2.构造实体类 class division { public division( { this.Teams = new ObservableCollection<Team>(); } set; } public ObservableCollection<Team> Teams { }
3.构造实体类League class League public League( this.divisions = new ObservableCollection<division>(); } string name { get; set; public ObservableCollection<division> divisions get; set; }
4.构造一个提供数据的类RadTreeVIEwSampleData class RadTreeVIEwSampleData public RadTreeVIEwSampleData() this.InitializeLeaguesDataSource(); public ObservableCollection<League> LeaguesDataSource private voID InitializeLeaguesDataSource() this.LeaguesDataSource = new ObservableCollection<League>(); League l; division d; this.LeaguesDataSource.Add(l = new League("League A")); l.divisions.Add((d = new division("division A"))); d.Teams.Add(new Team("Team I")); d.Teams.Add(new Team("Team II")); new Team("Team III")); new Team("Team IV")); new Team("Team V")); new division("division B"))); new Team("Team Blue")); new Team("Team Red")); new Team("Team Yellow")); new Team("Team Green")); new Team("Team Orange")); new division("division C"))); new Team("Team East")); new Team("Team West")); new Team("Team north")); new Team("Team South")); new League("League B")); new Team("Team 1")); new Team("Team 2")); new Team("Team 3")); new Team("Team 4")); new Team("Team 5")); new Team("Team Diamond")); new Team("Team Heart")); new Team("Team Club")); new Team("Team Spade")); l.divisions.Add((d = new division("division C"))); new Team("Team Alpha")); new Team("Team Beta")); new Team("Team Gamma")); new Team("Team Delta")); new Team("Team Epsilon")); }
5.定义页面
<UserControl.Resources> <sampleData:RadTreeVIEwSampleData x:Key="DataSource"/> <DataTemplate x:Key="Team"> <TextBlock Text="{Binding name}"/> </DataTemplate> <telerik:HIErarchicalDataTemplate x:Key="division" ItemsSource="{Binding Teams}" ItemTemplate="{StaticResource Team}"> <TextBlock Text="{Binding name}"/> </telerik:HIErarchicalDataTemplate> <telerik:HIErarchicalDataTemplate x:Key="League" ItemsSource="{Binding divisions}" ItemTemplate="{StaticResource division}"> <TextBlock Text="{Binding name}"/> </telerik:HIErarchicalDataTemplate> <DataTemplate x:Key="ListBoxDataTemplate"> <TextBlock Text="{Binding name}"/> </DataTemplate> </UserControl.Resources> <GrID x:name="LayoutRoot" Background="White" margin="8"> <GrID.ColumnDeFinitions> <ColumnDeFinition WIDth="120"/> <ColumnDeFinition WIDth="100"/> <ColumnDeFinition WIDth="*"/> </GrID.ColumnDeFinitions> <GrID.RowDeFinitions> <RowDeFinition Height="auto"/> <RowDeFinition/> </GrID.RowDeFinitions> <TextBlock Text="RadTreeVIEw" FontSize="16" margin="5" VerticalAlignment="Bottom" /> <TextBlock Text="TextBox" FontSize="16" GrID.Column="1" VerticalAlignment="Bottom" margin="5" /> <TextBlock Text="RadGrIDVIEw" FontSize="16" GrID.Column="2" VerticalAlignment="Bottom" margin="5" /> <telerik:RadTreeVIEw x:name="radTreeVIEw" IsDragDropEnabled="True" margin="0,8,0" IsDragtooltipEnabled="False" GrID.Row="1" ItemsSource="{Binding Source={StaticResource DataSource},Path=LeaguesDataSource}" ItemTemplate="{StaticResource League}"/> <TextBox x:name="textBox" GrID.Column="1" GrID.Row="1" VerticalAlignment="top" HorizontalAlignment="left" WIDth="90" margin="0,0"/> <telerik:RadGrIDVIEw x:name="radGrIDVIEw" GrID.Column="2" GrID.Row="1" Height="280" margin="0,0" VerticalAlignment="top" autoGenerateColumns="False" ItemsSource="{Binding Source={StaticResource DataSource},Path=EmptyTeamDataSource}" SelectionChanged="radGrIDVIEw_SelectionChanged"> <telerik:RadGrIDVIEw.Columns> <telerik:GrIDVIEwDataColumn DataMemberBinding="{Binding ID}"/> <telerik:GrIDVIEwDataColumn DataMemberBinding="{Binding name}"/> <telerik:GrIDVIEwDataColumn DataMemberBinding="{Binding ImageUrl}"/> </telerik:RadGrIDVIEw.Columns> </telerik:RadGrIDVIEw> </GrID>
6.定义变量与构造函数,其中设置textBox,radgrIDVIEw允许拖拉并绑定drop的命令
private ObservableCollection<Team> aaa=new ObservableCollection<Team>(); public Tree2() { InitializeComponent(); //radGrIDVIEw. RadDragAndDropManager.SetAllowDrop(textBox,true); RadDragAndDropManager.SetAllowDrop(radGrIDVIEw,true); RadDragAndDropManager.AddDropqueryHandler(textBox,new EventHandler<DragDropqueryEventArgs>(this.TextBox_OnDropquery)); RadDragAndDropManager.AddDropInfoHandler(textBox,new EventHandler<DragDropEventArgs>(this.TextBox_OnDropInfo)); RadDragAndDropManager.AddDropqueryHandler(radGrIDVIEw,new EventHandler<DragDropqueryEventArgs>(this.RadGrIDVIEw_OnDropquery)); RadDragAndDropManager.AddDropInfoHandler(radGrIDVIEw,new EventHandler<DragDropEventArgs>(this.RadGrIDVIEw_OnDropInfo)); }
private voID TextBox_OnDropquery(object sender,DragDropqueryEventArgs e) { e.queryResult = true; e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue(); } private voID TextBox_OnDropInfo(object sender,DragDropEventArgs e) { if (e.Options.Status == DragStatus.DropComplete) { object item = (e.Options.Payload as Collection<Object>)[0]; PropertyInfo info = item.GetType().GetProperty("name"); textBox.Text = info == null ? String.Empty : info.GetValue(item,null).ToString(); } } private voID RadGrIDVIEw_OnDropquery(object sender,DragDropqueryEventArgs e) { e.queryResult = true; } private voID RadGrIDVIEw_OnDropInfo(object sender,DragDropEventArgs e) { if (e.Options.Status == DragStatus.DropComplete) { foreach (object dropItem in e.Options.Payload as Collection<Object>) { Team team = dropItem as Team; if (team != null) { aaa.Add(team); } this.radGrIDVIEw.ItemsSource = aaa; //(this.radGrIDVIEw.ItemsSource as ObservableCollection<Team>).Add(team); } } }总结
以上是内存溢出为你收集整理的在Telerik for silverlight控件radtreeview、textBox、RadGridView中实现拖拉控件的 *** 作全部内容,希望文章能够帮你解决在Telerik for silverlight控件radtreeview、textBox、RadGridView中实现拖拉控件的 *** 作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)