Silverlight ComboBox with two fields per item
I want to display a myItem.title
and myItem.url
per each item in the comboBox.ItemsSource
observable collection that gets shown in the comboBox. In other words, I'd like to see each row in the combo box hold and display both pieces of information.
Not sure how to do this or if it's possible.
How would I go about writing the xaml and then make itemSource.Add()
accept 2 items per actual item?
Thanks for any help!
EDIT: (solved)
I've come up with this xaml but I have no idea how to access FiledOne
and FieldTwo
from code.
<ComboBox Canvas.Left="410" Canvas.Top="174" Height="23" Name="addresses_combo" Width="408" SelectionChanged="address_changed">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FieldOne, Mode=OneWay}" />
<TextBlock Text="{Binding FieldTwo, Mode=OneWay}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
EDIT2: (solved)
How can I insert a new line between the two TextBlock
nodes?
<TextBlock Text="{Binding FieldOne, Mode=OneWay}" />
<TextBlock Text=" \n <--this doesn't wor开发者_高级运维k obviously" />
<TextBlock Text="{Binding FieldTwo, Mode=OneWay}" />
-Or at least make one of them bold and the other regular. So that there would be a clear difference between the two Fields...
With the XAML you provided you would need something like this:
itemSource.Add(new ItemClass(title,url));
Define the ItemClass as something like this:
public class ItemClass
{
public string FieldOne {get;set;}
public string FieldTwo {get;set;}
}
精彩评论