What kind of control do I need for a vertical display of a List<CustomObject> with a CustomTemplate?
Let's say I have a List<MyObject>
,
which stores
class MyObject
{
public String Headline {get;set;}
public DateTime MyDate {get;set;}
}
I want to display each MyObject
in a vertical order, so that it looks like a entry in a开发者_开发百科 List, with rounded corners and the values are written over the background image.
I've googled two pictures of what looks close to what kind of display control I want to have: http://assets.gearlive.com/blogimages/gallery/sonos-iphone-app/sonos-iphone-zone-menu_medium.jpg
http://iconfactory.com/twitterrific_touch/images/screenshot_list.pngWhat kind of control can I use for this? It's like a Repeater/ListView with a custom template. (Let's assume I don't have any graphic skills. How can I create a rectangle with rounded cornes and a color gradient as a background?)
(I'm new to WPF)
If you don't want selection, go for an ItemsControl
. Otherwise use ListBox
.
ListBox
inherits from Selector
which inherits from ItemsControl
and adds selection functionality.
XAML:
<ItemsControl Name="ItemsControl1">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="<Binding Headline}" />
<TextBlock Text="<Binding MyDate}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Code behind:
ItemsControl1.ItemsSource = ListOfMyObjects;
you should probably use a ListBox
. then, make a DataTemplate
for your object type--here is a nice explanation on DataTemplates. You should also make MyObject
derive from INotifyPropertyChanged
so that when you change a value in the object, it will automatically update your UI. One other thing, you should probably change from List<MyObject>
to ObservableCollection<MyObject>
so that the ListBox
will automaticaly update when you add/remove items
精彩评论