コード例 #1
0
        public PropertySheetTest()
        {
            InitializeComponent();

            Loaded += (s, e) =>
            {
                var exampleType = GetType();

                var properties = exampleType.GetProperties();

                var categories = new List <string> {
                    string.Empty
                };
                foreach (var property in properties)
                {
                    var categoryName = GetCategory(property);
                    if (!string.IsNullOrEmpty(categoryName) && !categories.Contains(categoryName))
                    {
                        categories.Add(categoryName);
                    }
                }
                categories = categories.OrderBy(c => c).ToList();

                foreach (var category in categories)
                {
                    var first = true;
                    foreach (var property in properties.OrderBy(p => p.Name))
                    {
                        if (GetCategory(property) != category)
                        {
                            continue;
                        }
                        var text = new TextBlock {
                            Text = property.Name
                        };
                        SimpleView.SetGroupTitle(text, !string.IsNullOrEmpty(category) ? category : " -- Uncategorized");
                        if (first)
                        {
                            SimpleView.SetGroupBreak(text, true);
                        }
                        first = false;
                        var nativeValue = property.GetValue(this, null);
                        var editText    = nativeValue == null ? string.Empty : nativeValue.ToString();
                        var edit        = new TextBox {
                            Text = editText
                        };
                        PropertySheet.Children.Add(text);
                        PropertySheet.Children.Add(edit);
                    }
                }
            };
        }