XAML:
<ListView Grid.Row="0" Grid.Column="2" Width="155" Height="Auto" Margin="10" ItemsSource="{Binding MedialDictionary}"></ListView>
C# ViewModel:
private Dictionary<DateTime, decimal> _medialDictionary;
public Dictionary<DateTime, decimal> MedialDictionary
{
get => _medialDictionary;
set => SetProperty(ref _medialDictionary, value);
}
I want to have the key in one column of the list and a value in the other. I have added GridView
columns inside the ListView
, but do not how to bind the properties correctly (EffectiveDate, Value).
I have read much documentation, however it has not made any sense to me so I am looking for advice/solutions here.
CodePudding user response:
An item in a Dictionary<K,V>
is a KeyValuePair<TKey,TValue>
, which is a struct
with a Key
and a Value
property that you can bind.
In order to display a tabular layout with columns, you can use a GridView
. Each colum has a DisplayMemberPath
property that the corresponding property to display is bound to.
<ListView Grid.Row="0" Grid.Column="2" Width="155" Height="Auto" Margin="10"
ItemsSource="{Binding MedialDictionary}">
<ListView.View>
<GridView>
<GridViewColumn Header="Date"
DisplayMemberBinding="{Binding Key}"/>
<GridViewColumn Header="Value"
DisplayMemberBinding="{Binding Value}"/>
</GridView>
</ListView.View>
</ListView>