0
我有一個模型:結合性質的內容,背景等,在MapItemsControl圖釘
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線程:
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
等。我可以在後臺工作嗎?我的意思是以另一種方式綁定內容和背景屬性。畢竟,MVVM應該允許在UI的背景下工作。
多謝多謝,多謝!偉大的答案! – Alexandr
很高興我能幫上忙! –