我在绑定我的字典的元素时遇到问题。我的字典包含一个对象作为键和一个整数作为值。我必须在 ListView 中绑定这个字典。问题是我需要访问我的对象的属性来绑定它们在 listview.Properties 类型是字符串。我没有找到解决方案,这都是关于 wpf 但我正在使用带有 MVVM Light 的 Windows8。
有我的代码:
我的列表 :
<ListView ItemsSource="{Binding Path=MotDansTweet}"
HorizontalAlignment="Left"
Height="570"
Margin="64,28,0,0"
VerticalAlignment="Top"
Width="350"
Background="#FF009BB4"
Grid.Column="1">
<StackPanel Height="118"
Width="340">
<Grid Height="100">
<Grid HorizontalAlignment="Left"
Height="122"
VerticalAlignment="Top"
Width="330"
Margin="0,0,0,-22">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="137*" />
<ColumnDefinition Width="193*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding Path=Key.ProfileImageUrl }"
HorizontalAlignment="Left"
Height="112"
VerticalAlignment="Top"
Width="127" />
<TextBlock Text="{Binding Path=Key.Username}"
Grid.Column="1"
HorizontalAlignment="Left"
Margin="10,10,0,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
Height="46"
Width="173" />
<TextBlock Text="{Binding Path=Values}"
Grid.Column="1"
HorizontalAlignment="Left"
Margin="10,61,0,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
Height="41"
Width="154" />
</Grid>
</Grid>
</StackPanel>
</ListView>
我的字典:
private Dictionary<ObjetFollowingFollowerFinal,int> _motDansTweet ;
public Dictionary<ObjetFollowingFollowerFinal, int> MotDansTweet
{
get { return _motDansTweet; }
set
{
_motDansTweet = value;
RaisePropertyChanged("MotDansTweet");
}
}
我的对象:
public class ObjetFollowingFollowerFinal
{
public string Username { get; set; } // I need it
public string Description { get; set; }
public string ProfileImageUrl { get; set; } //I need it
public int StatusesCount { get; set; }
public int FollowerCount { get; set; }
public int FriendsCount { get; set; }
public int ListedCount { get; set; }
public List<User> ListeFollower = new List<User>();
public ObjetFollowingFollowerFinal()
{
}
}
谢谢。