我有一个模型:
public class GYPushpin : GYEntity
{
private GeoCoordinate _coordinate;
public GeoCoordinate Coordinate
{
get
{
return _coordinate;
}
set
{
if (value != _coordinate)
{
_coordinate = value;
NotifyPropertyChanged("Coordinate");
}
}
}
//.............
}
和MapItemsControl
:
<toolkit:MapItemsControl>
<toolkit:MapItemsControl.ItemTemplate>
<DataTemplate>
<toolkit:Pushpin
GeoCoordinate="{Binding Coordinate}"
Background="{Binding Background}"
Content="{Binding ContentPushpin}"
Tag="{Binding Tag}"
Tap="userPushpin_Tap">
</toolkit:Pushpin>
</DataTemplate>
</toolkit:MapItemsControl.ItemTemplate>
</toolkit:MapItemsControl>
我在 UI 线程中使用 DataBinding 和填充列表:
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
foreach (GYUser friend in friends)
{
ImageBrush image = new ImageBrush()
{
ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("http://my_url" + string.Format(friend.Avatar)))
};
Brush markerColor = friend.Sex == 1 ? new SolidColorBrush(Color.FromArgb(alpha, 71, 188, 225)) : new SolidColorBrush(Color.FromArgb(alpha, 246, 109, 128));
var content = new System.Windows.Shapes.Rectangle()
{
Fill = image,
StrokeThickness = 10,
Height = 50,
Width = 50
};
var pin = new GYPushpin()
{
Coordinate = new GeoCoordinate()
{
Longitude = friend.Longitude,
Latitude = friend.Latitude,
},
ContentPushpin = content,
Background = markerColor,
};
//add pin in binding collection
}
}
我有很多用户,我必须在 UI 线程中工作,因为我使用ImageBrush
,Shapes
等。我可以在后台工作吗?我的意思是用另一种方式绑定 Content 和 Background 属性。毕竟,MVVM 应该允许在后台使用 UI 工作。