【发布时间】:2016-02-12 16:31:22
【问题描述】:
我用来在 XAML 中绑定的对象只能具有字符串属性。但是在绑定中我需要其他类型。我认为我使用 IValueConverter 中的 Converter 函数,我将从字符串属性创建对象并返回它。一个字符串属性将为空,在绑定中我将从 Converter 方法返回其他对象。我试过了,但在 Convert 方法中,我来自 ObservableCollection 的主要对象为空。这是我的 XAML 的一部分
<Maps:MapItemsControl ItemsSource="{Binding}">
<Maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Background="Transparent" Tapped="ItemStckPanel">
<Image Source="/Assets/pushpin.gif" Height="30" Width="30"
Maps:MapControl.Location="{Binding Location,
Converter={StaticResource StringToGeopoint}}"
Maps:MapControl.NormalizedAnchorPoint="0.5,0.5"/>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5">
<TextBlock FontSize="20" Foreground="Black" Text="{Binding Name}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</Maps:MapItemsControl.ItemTemplate>
</Maps:MapItemsControl>
这是我的转换方法:
public object Convert(object value, Type targetType, object parameter, string language)
{
Event _event = (Event) parameter;
BasicGeoposition position = new BasicGeoposition();
position.Latitude = _event.Latitude;
position.Longitude = _event.Longitude;
return new Geopoint(position);
}
【问题讨论】: