Itemscontrol controls and binding them to user data

I am very new to WPF. I tried to do the following:

The following is the structure of my data:

public class TokenItems {public string items {get;set;} public int quantity {get;set}} public class Token { public int tokenNo {get;set;} public string name {get;set;} public List<TokenItems> currentItems {get;set;}} public List<Token> tokenList = new List<Token>(); 

XAML:

 <ItemsControl Name="ParentControl"> .... <DataTemplate> <TextBlock Content="{Binding tokenNo}"/> <Itemscontrol Name="{Binding tokenNo}"> ?? I tried and want dynamic naming or any other solution for this {Binding name} just won't work i know.?? ... <DataTemplate> <Button> <Grid> ... <TextBlock Content="{Binding items}/> <TextBlock Content="{Binding quantity}/> </DataTemplate> </Itemscontrol> .... </DataTemplate> </Itemscontrol> 

I added all the necessary data to the token list and did the following:

 ParentControl.ItemsSource = tokenList; 

Without a doubt, everything is correctly tied to the ParentControl. Now I want to populate its child Itemcontrol with a list of currentItems. Since I needed several parent controls, I needed dynamic naming for the children of the Itemscontrol. Also, I cannot access ItemsControl children from code.

How to do it? I do not know if a child of the ItemsControl of ItemsControl exists.

Please offer me some solution or alternative solution to this problem.

EDIT: I want the user to see the Token Number, time, etc. with a list of items to be replaced by a list of interactive buttons.

Update: XAML content has changed a bit. The child itemsControl is inside the DataTemplate.

+4
source share
1 answer

You do not need to enter names in the itemscontrol control, if you want the control to run something, use the buttons in the itemtemplate:

 <ItemsControl ItemsSource="{Binding tokenList}"> <ItemsControl ItemsSource="{Binding currentItems}"> <ItemsControl.ItemTemplate> <DataTemplate> <Button Content="{Binding TokenNo}"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ItemsControl> 

You can add everything you need to show in the datatemplate tag. In my example, the text on the button will be TokenNo, which it finds in the parent object, which is the token that is shown through the token list binding.

+6
source

All Articles