我想创建一个绑定到XAML中定义的字符串集合 .
在WPF中,我可以使用键创建 ArrayList
作为资源,准备用作绑定源(使用StaticResource) .
这可能是Xamarin Forms吗?
EDIT: 我've tried with this XAML with the solution proposed by @Stephane Delcroix, but I'获得未处理的异常:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Class="ReferenceApp.Views.GamesPage"
Title="Games">
<ContentPage.Resources>
<x:Array Type="{x:Type sys:String}" x:Key="array">
<x:String>Hello</x:String>
<x:String>World</x:String>
</x:Array>
</ContentPage.Resources>
<Grid />
</ContentPage>
但是,如果我删除 <x:Array >... </x:Array>
,则不会抛出异常
我究竟做错了什么?
2 回答
你可以使用内置的
x:Array
sys
定义为xmlns:sys="clr-namespace:System;assembly=mscorlib"
或任何你喜欢的集合,例如
List
sys
定义为之前,scg
为xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
我看到你正在使用 XF standard markup extensions . 你的错误似乎是在
Type="{x:Type sys:String}"
,而不是 sys:String 你应该写 x:String ,它出现在共同的 xmlns:x在此示例中,我使用字符串填充列表视图