首页 > 解决方案 > XAML 绑定在发布模式下不工作,但在调试模式下工作

问题描述

我正在使用CarouselView绑定到的 aIEnumerable<T> list以在该列表中显示我的文件的预览以及文件名,并将文件路径用作图像预览。

当我调试我的应用程序时,此绑定按预期工作,文件名和图像预览根据每个文件按预期显示。但是,当我在发布模式下测试我的应用程序时,文件名的绑定失败,而我的文件路径的绑定仍然有效。

为了向您展示我的意思,以下是 Debug 和 Release 的一些屏幕截图:

发布 //调试

应用程序应该像调试屏幕截图一样运行,其中文件名在框架顶部可见。

这是我的 XAML 和代码隐藏,以便更好地了解出了什么问题:

XAML:

    <!--Carousel of files selected preview with binding to the Files variable in the codebehind-->
            <CarouselView x:Name="preview" IsVisible="True" ItemsSource="{Binding Files}" PeekAreaInsets="20" >
                <CarouselView.ItemTemplate>
                    <DataTemplate>
                        <StackLayout>
                            <Frame  HasShadow="True"
                                   IsVisible="True"
                                   BorderColor="Black"
                                   CornerRadius="5"
                                   Margin="5,10,5,10"
                                   HeightRequest="500"
                                   WidthRequest="500"
                                   HorizontalOptions="Center"
                                   VerticalOptions="Start">
                                <StackLayout>
                                    <Label TextColor="Black" Text="{Binding FileName}" IsVisible="True"></Label>
                                    <Image Source="{Binding FullPath}"
                                           Aspect="AspectFill"
                                           HeightRequest="500"
                                           WidthRequest="500"
                                           VerticalOptions="Center"/>
                                </StackLayout>
                            </Frame>
                        </StackLayout>
                    </DataTemplate>
                </CarouselView.ItemTemplate>
            </CarouselView>

代码隐藏:

    //<--Summary: Gives users a preview of the files they selected before uploading-->
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class FileView : ContentPage
    {
        public static string fileID; //Upload filename
        private IEnumerable<FileResult> pickedFiles; //List of picked files
        public IEnumerable<FileResult> Files {
            get => pickedFiles;
        }
        public string SelectedTime { get; set; } //Binding for user selected transfer time
        public bool SelectedCompression { get; set; } //Binding for user selected compression type

        public FileView( IEnumerable<FileResult> pF)
        {
            InitializeComponent();
            SelectedTime = "1"; //Sets default transfer time to 1 minute
            this.pickedFiles = pF;
            this.BindingContext = this;
        }

标签: xamlxamarinxamarin.formsdata-binding

解决方案


推荐阅读