XAML 绑定在发布模式下不工作,但在调试模式下工作

时间:2021-03-04 11:28:20

标签: xaml xamarin xamarin.forms data-binding

我正在使用已绑定到 CarouselViewIEnumerable<T> list 来显示该列表中我的文件的预览,其中包含文件名并使用文件路径作为图像预览。

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

为了向您展示我的意思,以下是调试和发布的一些屏幕截图:

Release // Debug

应用程序的功能应该类似于调试屏幕截图,其中文件名在框架顶部可见。

这是我的 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;
        }

0 个答案:

没有答案
相关问题