سؤال

أنا حاليًا قادر على تحديد ملفات متعددة ولكن عندما أقوم بالنقر فوق فتح ، لا يتم عرض الصور المحددة. بدلاً من ذلك ، "windows.ui.xaml.media.imaging.bitmapimage" يظهر كنص. ال FlipView الوظيفة لا تزال هناك رغم ذلك. ما الخطأ الذي افعله؟

XAML.

<FlipView x:Name="flpView" Grid.Row="1" Margin="10, 10, 10, 10">
    <Image x:Name="images" Stretch="UniformToFill" />
</FlipView>

وراء الكود.

public async Task flipviewload()
{
    // Add code to perform some action here.
    Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
    openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
    openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

    // Filter to include a sample subset of file types.
    openPicker.FileTypeFilter.Clear();
    openPicker.FileTypeFilter.Add(".bmp");
    openPicker.FileTypeFilter.Add(".png");
    openPicker.FileTypeFilter.Add(".jpeg");
    openPicker.FileTypeFilter.Add(".jpg");
    var files = await openPicker.PickMultipleFilesAsync();

    var images = new List<BitmapImage>();
    if (files != null)
    {
        //foreach (StorageFile Images in files)
        foreach (var file in files)
        {
            Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
            using (Windows.Storage.Streams.IRandomAccessStream filestream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
            {
                BitmapImage bitmapImage = new BitmapImage();
                await bitmapImage.SetSourceAsync(fileStream);
                //Images.Source = bitmapImage;
                images.Add(bitmapImage);
            }
        }
    }
    flpView.ItemsSource = images;
}

أضفت أيضا Task foo = flipviewload(); في علني MainPage();

هل كانت مفيدة؟

المحلول

تحصل على هذه النتيجة لأن مكالمات تقديم الافتراضية ToString() على العنصر ، الذي يطبع اسم الفصل. إذا كنت ترغب في عرض الصورة عليك توفير ItemTemplate:

<FlipView x:Name="flpView" Grid.Row="1" Margin="10, 10, 10, 10">
    <FlipView.ItemTemplate>
        <DataTemplate>
            <Image Stretch="UniformToFill" Source="{Binding}" />
        </DataTemplate>
    </FlipView.ItemTemplate>
</FlipView>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top