المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Adding multiple controls to a ListBox without using WPF



C# Programming
03-23-2012, 12:00 PM
I'm trying to create a ListBox on the fly without using any XAML code. I got it working - almost. What I have is an array of TextBoxes of 'Zone Descriptions'. I can put those into the ListBox as ListBoxItems, and it works great - no problem. I want to add at the front of the TextBox a TextBlock or header that says 'Zone 1' or whatever the zone is along with the TextBox, which is user changeable. I have an array of TextBlocks (I probably could have had strings just as well). But, I can't (or don't know how to) adjust the ListBoxItem.Content to hold both the TextBlock and TextBox combo. LBI[i].Content = TBlkZoneDesc[i] + TBxZoneDesc[i] is what I want to do, but that syntax is not allowed. Doing either one separately works fine, but not both. Do anyone have a suggestion on how to do that? ListBox LBZoneDesc = new ListBox(); LBZoneDesc.Width = 300; LBZoneDesc.Height = 240; Grid.SetColumn(LBZoneDesc,0); Grid.SetRow(LBZoneDesc,2); ListBoxItem[] LBI = new ListBoxItem[64]; for (byte i = 0; i < 5; i++) { LBI[i] = new ListBoxItem(); LBI[i].Padding = new Thickness(2); // LBI[i].Content = TBlkZoneDesc[i]; LBI[i].Content = TBxZoneDesc[i]; LBZoneDesc.Items.Add(LBI[i]); } C0Grid.Children.Add(LBZoneDesc);