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.
source share