static void OnTypePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            DependencyPropertyListView lstvue = obj as DependencyPropertyListView;

            Type type = args.NewValue as Type;

            lstvue.ItemsSource = null;

            if (type != null)
            {
                SortedList <string, DependencyProperty> list = new SortedList <string, DependencyProperty>();
                FieldInfo[] infos = type.GetFields();   //获取类型中的所有字段信息

                //提取字段类型是DependencyProperty类型的字段
                foreach (FieldInfo info in infos)
                {
                    if (info.FieldType == typeof(DependencyProperty))
                    {
                        list.Add(info.Name, (DependencyProperty)info.GetValue(null));
                    }
                }

                lstvue.ItemsSource = list.Values;
            }
        }
Exemple #2
0
        void Init()
        {
            this.Title = "Explore Dependency Properties";

            Grid grid = new Grid();

            this.Content = grid;

            ColumnDefinition col = new ColumnDefinition();

            col.Width = new GridLength(1, GridUnitType.Star);
            grid.ColumnDefinitions.Add(col);

            col       = new ColumnDefinition();
            col.Width = GridLength.Auto;
            grid.ColumnDefinitions.Add(col);

            col       = new ColumnDefinition();
            col.Width = new GridLength(3, GridUnitType.Star);
            grid.ColumnDefinitions.Add(col);

            ClassHierarchyTreeView treevue = new ClassHierarchyTreeView(typeof(DependencyObject));

            grid.Children.Add(treevue);
            Grid.SetColumn(treevue, 0);

            GridSplitter split = new GridSplitter();

            split.HorizontalAlignment = HorizontalAlignment.Center;
            split.VerticalAlignment   = VerticalAlignment.Stretch;
            split.Width = 6;
            grid.Children.Add(split);
            Grid.SetColumn(split, 1);

            DependencyPropertyListView lstvue = new DependencyPropertyListView();

            grid.Children.Add(lstvue);
            Grid.SetColumn(lstvue, 2);

            lstvue.SetBinding(DependencyPropertyListView.TypeProperty, "SelectedItem.Type");          //SelectedItem是TypeTreeViewItem的类型,TypeTreeViewItem中含有Type属性
            lstvue.DataContext = treevue;
        }