binding - Repeated children in WPF TreeView -
It solved itself as it did the way I started the settings. All settings specifying a default collection object when registering as Defendancy Property. Adding a constructor to the range and starting the settings clearly means the problem is solved.
A class specifies a collection of category names and settings objects.
By using the system. Selection .ObjectModel; Using System.Windows; Namespace Seaside {Public Category Category: Inspectionable Collection & lt; Category & gt; {} Public Class Category: Dependency Object {Public String Caption {get {return (string) GetValue (CategoryProperty); } Set {set value (categoryproperty, value); }} Dependency for public static reading property category property = dependency property Public settings settings {Get {return (settings) GetValue (SettingsProperty);}} public static reading ("Caption", typefile, typefile, new UIPpropy metadata ("category name is not set"); Dependency Property Settings for Property = Dependency Property. Controls ("Settings", Type (Settings), Type (Category), New UIP Prototytata (New Settings ());}} The following XAML tem Defines palettes, UIs, and some test data.
Window x: class = "CasEdit.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/ 2006 / xaml / presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: ccidit =" clr-namespace: CasEdit "heading =" main window "height =" 350 "width = "525" & gt; Window.Resources & gt; Hierarchical DataTypeplate DataType = "{x: Type CasEdit: Category}" ItemsSource = "{Binding Settings}" & gt; & gt; StackPanel Orientation = "Horizontal" & gt; & lt; text block text = "{binding caption}" /> & Lt; Button content = "free button" margin = "3" click = "button_link" /> & lt; / StackPanel & gt; & Lt; / HierarchicalDataTemplate & gt; & Lt; DataTemplate DataType = "{x: Type CasEdit: Setting}" & gt; & Lt; StackPanel Orientation = "Horizontal" & gt; & Lt; Text block text = "{binding caption}" margin = "3" /> & Lt; Text block text = "{binding template}" margin = "3" /> & Lt; Text box text = "{binding editor}" margin = "3" /> & Lt; Textbox text = "{binding cassette}" margin = "3" /> & Lt; / StackPanel & gt; & Lt; / DataTemplate & gt; & Lt; CasEdit: Categories x: Key = "Cats" & gt; & Lt; CasEdit: Category Caption = "First Class" & gt; & Lt; CasEdit: Category.Settings & gt; & Lt; Cassidade: Setting caption = "1-1 installation" /> & Lt; Cassidade: Settings Caption = "Settings 1-2" /> & Lt; / CasEdit: Category.Settings & gt; & Lt; / CasEdit: Category & gt; & Lt; CasEdit: Category Caption = "Second Class" & gt; & Lt; CasEdit: Category.Settings & gt; & Lt; CasEdit: Setting caption = "Settings 2-1" /> & Lt; / CasEdit: Category.Settings & gt; & Lt; / CasEdit: Category & gt; & Lt; CasEdit: Category caption = "Third category" & gt; & Lt; CasEdit: Category.Settings & gt; & Lt; Cassidade: Settings Caption = "Settings 3-1" /> & Lt; / CasEdit: Category.Settings & gt; & Lt; / CasEdit: Category & gt; & Lt; / CasEdit: Categories & gt; & Lt; /Window.Resources> & Lt; Grid & gt; & Lt; TreeView x: name = "tree" item source = "{binding source = {static resource cats}}" /> & Lt; / Grid & gt; & Lt; / Window & gt; You would expect a tree like this
- 1 square
- 1-1 set
- 1- 2
- Setting 2-1
- 2-1
- Third category
- 3-1 setting < / Li>
But what do I get
I'm astray, is that every category shows all the settings?
Here the last parameter is saying that in every instance of the class, For the same object that has been started:
Only dependencies-based settings for public static reading: property = dependencyproperty. Registration ("settings", type (settings), typef (category), new UIPprotamatata (new settings ()); Instead, do this:
Public static read-only dependency property setting: Property = Dependency Property. Registration ("Settings", Type (Settings), Type (Category) New UIPpropy Metadata (empty)); Public category () {settings = new settings (); }
Comments
Post a Comment