WPF - What conditions must be met to use data binding in a custom control's content items? -


I am in the process of creating a custom control - especially a pie chart. I want to see markup something like this example:

  & lt; C: PieChart & gt; & Lt ;! - These dependency properties are never set - & gt; & Lt; C: slice value = "{binding redacount}" /> & Lt; C: slice value = "{binding blockout}" /> & Lt; C: slice value = "{binning greencount}" /> & Lt; / C: piechart & gt; [ContentProperty ("Slice")] Public Category PieChart: Control {public}  

PieChart (Slice = New Observe Collection & lt; Slice & gt; ();} Public Observable Collection & lt; Slices & gt; Slices {Get; Private Set;}}

< P> The above example causes the XAML slice property to be populated with three examples of slices

one slice One snippet:

  Public square slice: content control {public fixed dependency property value property = dependency property. Registration ("value", typef (double), typef (slice), new property matadata (P, A) = & gt; (Slice) P) ONValue Change (A)); Private Zero on Value Changed (DependencyPerty-ChangeAventure E) {// This Code Never Called!}} < / Code> 

problem is that the value on value Ti slices is never set. If I put the dependency property on PieChart and copy the bound expression, the value is set, so I believe that I understand the basics of dependency properties and binding.

Therefore, for my dependency property, what would I have to do to determine the value on the hair object? Since these items are in my own collection, do they not get recognized in any logical tree that does magic, binding works?

A simple 'this' answer would be helpful, but I really want to understand what is going wrong, then I accept the most practical, explanatory answer.

Edit I did not specify this, but Datacontext of PieChart in which property redcode , Etc. are included. First, when I have seen the warnings on the runtime in the VS Output window, when I have a binding route (or some other fault). In this case, I do not see anything.

It looks like the slices controls not being caught up to the view tree Are there. They are only member variables, and WPF does not know that it means displaying them as the hair elements of PieChart : a pair of possible approaches:

slices PieChart call AddLogicalChild to add objects You must handle the possibility of adding or removing slices to the Runtime, too little Level is: MSDN advises, "For control authors, this level is available Manipulation of kick tree is not a recommended practice, unless any of the available base model models for your control landscape are appropriate. ContentControl , ItemsControl , And HeaderedItemsControl .

Make PieChart a panel then slices s will have children, But note that the children property is vulnerably typed, so people can add anything to PieChart There is not a bad or good thing in a spiritual form; This is a design idea (see note below). But perhaps it is not possible what you want in your case.

Make PieChart a, and override, and possibly create / honor slice control (cf. list box ) and A good feature of listboxime , combo box and combobox , etc.) is that instead of hand control by the user, a The itemsource can be used by and DataTemplate (like ListBox ). (But users can still create their own syntax in the XAML slices s, as they can create ListBoxItems in XAML.)

As far as possible, a hybrid approach, such as radial layout creates functionality in a radial rhythmpanel and a piece generation in ItemsControl which is RadialLayoutPanel < / Code> uses ItemsPanel code>.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -