wpf - Binding DataTemplates (or another aproach) -


I have a problem trying to generate dynamic data after generating data in WWF.

I have the following scenario: TabControl - Dynamically generated tab through data template- In tabs, I have dynamic content generated by the Datatappletlet which I want to bind (ListBox).

The code is as follows:

: TabControl

  & lt; TabControl height = "252" horizontal align = "left" name = "tab control 1" vertical alignment = "top" width = "458" margin = "12,12,12, 12" content-template = "{static resource tab element content}" & Gt; & Lt; / TabControl & gt;  

:: tab to generate tabItems template for control

  & gt; Datamapplet x: Key = "TabTime Content" & gt; & Lt; Grid & gt; & Lt; Grid.ColumnDefinitions & gt; & Lt; Column width = "*" /> & Lt; /Grid.ColumnDefinitions> & Lt; Grid.RowDefinitions & gt; & Lt; Roadfinion height = "*" /> & Lt; /Grid.RowDefinitions> & Lt; ListBox ItemTemplate = "{StaticResource listBoxContent}" item source = "{binding}" & gt; & Lt; / ListBox & gt; & Lt; / Grid & gt; & Lt; / DataTemplate & gt;  

:: Template for ListBox inside each tab item

  DataTemplate x: key = "listbox content" & gt; & Lt; Grid & gt; & Lt; Grid.ColumnDefinitions & gt; & Lt; Column width = "22" /> & Lt; Column width = "*" /> & Lt; /Grid.ColumnDefinitions> & Lt; Image grid. Column = "0" source = "{binding path = plugin mark}" /> & Lt; Text block grid Column = "1" text = "{binding path = text}" /> & Lt; / Grid & gt; & Lt; / DataTemplate & gt;  

Therefore, when I try to make tabs on code within a loop:

  TabItem tabitem = tabControl1.Items [catIndex ] As TabItem; Tabitem.DataContext = plugins.ToList ();  

Where 'plugins' are countable

The list box is not bound. I tried to set the item sources to find the ListBox inside TabItem but did not get any success.

Anyone have an idea on how to do this? thank you in advanced.

The template for tab control uses a ContentPresenter to present SelectedContent, such as:

  & lt; ContentPresenter Content = "{TemplateBinding SelectedContent}" content template = "{TemplateBinding ContentTemplate}" />  

The job of a ContentPresenter in life is to expand a DataTemplate as it happens, while its content sets the visual code of the visual tree in Datacentax, in which the selected content Is connected to.

The selected content is set from the property of the tabitim's content, setting the DataContext to not its DataContext then TabItem does not set the DataContext on the view tree of the content area.

What do you want:

  tabItem.Content = plugins.ToList ();  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -