【发布时间】:2016-02-10 09:29:23
【问题描述】:
我正在尝试在Xamarin.Forms 中创建一个自定义控件并正确公开一个属性。我确信同样的原则适用于WPF
我的控制
public class ExtendedMap : Map
{
public ExtendedMap()
{
}
private IList<Pin> _staticPins;
public IList<Pin> StaticPins
{
get { return _staticPins; }
set { _staticPins = value;}
}
}
在 Xaml 中,我目前正在这样使用它:
<custom:ExtendedMap x:Name="map" Grid.Row="2" HorizontalOptions="Fill" VerticalOptions="Fill" IsVisible="{Binding CustomerSearchControlViewModel.MapIsDisplayed}">
<custom:ExtendedMap.StaticPins>
<x:Array Type="{x:Type maps:Pin}">
<maps:Pin Label="Hello" Address="{Binding CustomerSearchControlViewModel.SelectedCustomer.Address, Converter={StaticResource AddressToStringConverter}" Position="{Binding CustomerSearchControlViewModel.SelectedCustomer.Position}" Type="Place"/>
</x:Array>
</custom:ExtendedMap.StaticPins>
</custom:ExtendedMap>
如果我取出 <x:Array> 部分,我会收到错误:
序列不是 IEnumerable
但我想像这样使用它:
<custom:ExtendedMap.StaticPins>
<maps:Pin Label="Hello" Address="{Binding CustomerSearchControlViewModel.SelectedCustomer.Address, Converter={StaticResource AddressToStringConverter}" Position="{Binding CustomerSearchControlViewModel.SelectedCustomer.Position}" Type="Place"/>
</custom:ExtendedMap.StaticPins>
这可能吗?这样做的正确方法是什么?
【问题讨论】:
-
看看
IList<T> Interfacemsdn.microsoft.com/en-us/library/bb335435(v=vs.110).aspx -
@MethodMan 谢谢,但我不确定我应该去哪里看?
-
你是什么意思.. 我刚刚给了你链接.. 听起来你有一个
IEnumerable问题正在发生.. -
@MethodMan 我的意思是我可以看到 Enumerable API 文档,但我不明白它如何链接/解决我的问题?抱歉,如果我遗漏了什么
-
看看这个解决方案然后forums.xamarin.com/discussion/55473/…
标签: c# wpf xaml xamarin xamarin.forms