【发布时间】:2021-12-31 14:36:03
【问题描述】:
我在名为 DataTemplates.xaml 的单独文件中将 CustomDataTemplateSelector 添加到 ResourceDictionary,随后我将其链接到 App.xaml 中
当我运行应用程序时,我得到 XamlParseException 说: 键入 local:CustomDataTemplateSelector not found in xmlns clr-namespace:MyProject
另一方面,当我将 DataTemplates.xaml 的内容放到 App.xaml 中时,它工作得很好。
App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary Source="../DataTemplates.xaml"/>
DataTemplates.xaml
<?xml version="1.0" encoding="UTF-8"?>
<ResourceDictionary
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MyProject">
<DataTemplate x:Key="FirstCell">
<Label Text="Some text"/>
</DataTemplate>
<DataTemplate x:Key="SecondCell">
<Label Text="Some other text"/>
</DataTemplate>
<local:CustomDataTemplateSelector
x:Key="CustomDataTemplateSelector"
SecondTemplate="{StaticResource SecondCell}"
FirstTemplate="{StaticResource FirstCell}"/>
【问题讨论】:
标签: xamarin xamarin.forms