我已使用此 XAML 将一些项目数据绑定到我的 listView:
<ListView x:Name="itemListView" ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<Slider Value="{Binding Intensity}" Width="300" Tag="{Binding Name}" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
而这个 C# 代码:
public static ObservableCollection<PoliticalRegion> GetRegions()
{
ObservableCollection<PoliticalRegion> politicalRegions = new ObservableCollection<PoliticalRegion>()
{
new PoliticalRegion() {Name = "Algeria", Intensity = 0},
new PoliticalRegion() {Name = "Angola", Intensity = 0},
new PoliticalRegion() {Name = "Benin", Intensity = 0},
new PoliticalRegion() {Name = "Chad", Intensity = 0},
new PoliticalRegion() {Name = "Cote_d_Ivoire", Intensity = 0},
new PoliticalRegion() {Name = "Djibouti", Intensity = 0},
new PoliticalRegion() {Name = "Egypt", Intensity = 0},
};
return politicalRegions;
}
itemListView.DataContext = GetRegions();
当我运行它并移动一些滑块时,其他一些滑块会自行偶尔移动。为什么是这样??