XAML 使用. net MAUI中的FileResult在视图中填充DataTemplate

nkcskrwz  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(179)

我正在将Xamarin表单应用程序升级到Dotnet MAUI。我有一个控件,允许用户从设备中选择一个或多个文件,将详细信息保存在IEnumerable中,并在视图中显示列表。在Xamarin版本中,相关的XAML如下所示:

<CollectionView x:Name="AttachmentList" ItemsSource="{Binding Attachments}" SelectedItem="{Binding SelectedAttachment}" SelectionMode="Single">
    <CollectionView.ItemTemplate>
        <DataTemplate x:DataType="essentials:FileResult" >
           <StackLayout Spacing="0">
                <Frame Style="{StaticResource AttachmentBubble}">
                    <StackLayout Orientation="Horizontal">
                       <Image Source="{Binding FullPath}" HeightRequest="80" />
                       <Label Text="{Binding FileName}" HorizontalOptions="StartAndExpand"/>
                    </StackLayout>
                </Frame>
            </StackLayout>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

MAUI无法识别数据类型“essentions:FileResult”(因为在MAUI中不再有Essentials名称空间,所以这很公平)。FileResult位于Microsoft.Maui.Storage名称空间中。
我已尝试将DataTemplate条目替换为:

<DataTemplate x:DataType="FileResult" >

<DataTemplate x:DataType="storage:FileResult" >

但这两个都不起作用,并给出类型FileResult(或storage:FileResult)不存在的错误。
我需要什么MAUI等价物来使它工作?

2w3rbyxf

2w3rbyxf1#

因为FileResult与页面位于不同的程序集中,所以必须指定命名空间和程序集

xmlns:storage="clr-namespace:Microsoft.Maui.Storage;assembly=Microsoft.Maui.Essentials"

相关问题