【发布时间】:2015-10-25 17:33:38
【问题描述】:
我有一个 ListView,其中我在 viewcell 中有一个图像和一个文本,我的要求是更改所选行上的图像,我实现了它,
var listView = new MyQuestionView(listData);
listView.ItemSelected += (sender, e) => {
listView.ItemsSource = null;
//Update the IconSource here in listData
var s = e.SelectedItem as MenuItem;
s.IconSource = "foo.png";
listView.ItemsSource = listData; //Updated List
};
但是,像这样更新时,屏幕会闪烁一秒钟。是否有更新行元素的正确方法。
这是我的 Listview 的代码:
public class MyQuestionView : ListView
{
public MyQuestionView (ObservableCollection<MySelectedQuestions> Qdata)
{
ObservableCollection<MySelectedQuestions> data = Qdata;
ItemsSource = data;
HasUnevenRows = true;
VerticalOptions = LayoutOptions.FillAndExpand;
BackgroundColor = Color.Transparent;
SeparatorVisibility = SeparatorVisibility.Default;
SeparatorColor = Color.FromHex("#4Dffffff");
VerticalOptions = LayoutOptions.FillAndExpand;
HorizontalOptions = LayoutOptions.FillAndExpand;
ItemTemplate = new DataTemplate (() => {
// Create views with bindings for displaying each property.
Label titleLabel = new Label ();
titleLabel.FontSize = Device.GetNamedSize(NamedSize.Medium,typeof(Label));
titleLabel.SetBinding (Label.TextProperty, "Text");
Image image = new Image ();
image.SetBinding(Image.SourceProperty, "IconSource");
return new ViewCell {
View = new StackLayout {
Padding = new Thickness (5),
Orientation = StackOrientation.Horizontal,
Children = {
image,
new StackLayout {
VerticalOptions = LayoutOptions.Center,
Spacing = 0,
Children = {
titleLabel
}
}
}
}
};
});
}
}
提前致谢。
【问题讨论】:
-
在更改之前不将 ImageSource 设置为 null 是否仍然有效?
-
@WilliamCorncobDecker 是的,我可以,更新了更改 Imagesource 的代码..
标签: c# android listview xamarin.forms