【发布时间】:2020-04-15 09:25:15
【问题描述】:
我有一个位于 ContentPage 上的 ListView,我希望 ListView 的 ItemTemplate 是用户可定义的 - 即在运行时为模板解析 XAML。但是,我需要为用户提供在页面上调用命令的按钮的选项。见下文 XAML;
<SwipeView>
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem
Text = ""Delete""
BackgroundColor=""Red""
Command=""{Binding Path=ItemDeletedCommand, Source={x:Reference multiEntryPage}}""
CommandParameter=""{Binding .}"" />
</SwipeItems>
</SwipeView.RightItems>
<SwipeView.Content>
...
</SwipeView.Content>
我的内容页面在其 ContentPage 元素中有 x:Name="multiEntryPage" 属性。我用来解析 XAML 的代码如下所示:
listView.ItemTemplate = new DataTemplate(() => new ViewCell().LoadFromXaml(xaml));
但是,这会产生以下错误:
{Xamarin.Forms.Xaml.XamlParseException:位置 11:33。找不到
multiEntryPage引用的对象在 Xamarin.Forms.Xaml.ApplyPropertiesVisitor.ProvideValue (System.Object& 值,Xamarin.Forms.Xaml.ElementNode 节点,System.Object 源, Xamarin.Forms.Xaml.XmlName propertyName)...
所以我认为很明显错误正在发生,因为 SwipeView XAML 在这个阶段不知道它的父级,但我不知道如何解决这个问题。有什么想法吗?
谢谢!
【问题讨论】:
-
xaml 的值是多少?你是怎么得到的?能否提供完整代码?
-
xaml的值是第一部分代码sn-p中列出的xaml
-
问题解决了吗?
-
不,我决定以不需要 SwipeView 的不同方式解决我的问题
标签: c# xaml xamarin.forms