当前位置: 代码迷 >> Silverlight >> WPF treeview 怎么获得模板生成的控件 搜遍Google 无人能解
  详细解决方案

WPF treeview 怎么获得模板生成的控件 搜遍Google 无人能解

热度:6060   发布时间:2013-02-26 00:00:00.0
WPF treeview 如何获得模板生成的控件 搜遍Google 无人能解
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication3
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            ObservableCollection<A> a = new ObservableCollection<A>();
            a.Add(new A());
            a[0].name = "thy";
            ObservableCollection<AB> ab = new ObservableCollection<AB>();
            ab.Add(new AB());
            ab[0].abc = "38";
            a[0].ab = ab;

            Tree.DataContext = a;
        }
    }
    class A
    {
        public string name { get; set; }
        public ObservableCollection<AB> ab { get; set; }
    }
    class AB
    {
        public string abc { get; set; }
    }
}

<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:src="clr-namespace:WpfApplication3"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TreeView x:Name="Tree" ItemsSource="{Binding}">
            <TreeView.Resources>
                <DataTemplate x:Key="aTemplate" DataType="{x:Type src:AB}">
                    <TextBox Text="{Binding Path=abc}" />
                </DataTemplate>
  相关解决方案