Reusing a list of custom object in a ComboBox
I have an application in which the user can select various colors to customize the visual appearance of their UI.
I want to use a combo box control to display a list of the named Windows colors for them to choose from. For each combo box item I would like a small preview of the color followed by the text name for the color. So my combo box item contains a stack panel开发者_Python百科 with a rectangle that is filled with the color and a text block that contains the text portion.
I tried building this list of 140+ colors when they open the drop down portion, but this creates a perceivable delay since there is some processing in creating 140+ preview boxes with different fill colors. I could load all 4 combo box upon entry to the screen to remove the latency when opening the drop down, but that makes creates an even more perceivable delay when the screen initially loads.
Ideally what I would like to do is create a single static list of color items that can be reused by all of the combo boxes that are used for the user selecting a color.
You cannot assign a list to more than one control. How can I get around this?
I'm not sure what you mean by "you cannot assign a list to more than one control". Assuming you have a ColorList property in your data context that exposes your static list, and selected color properties for each combo box , you can simply bind the combo boxes as follows:
<ComboBox x:Name="One" ItemsSource="{Binding ColorList}" SelectedItem = "{Binding SelectedColorOne}"/>
<ComboBox x:Name="Two" ItemsSource="{Binding ColorList}" SelectedItem = "{Binding SelectedColorTwo}"/>
etc.
精彩评论