Макет ListView не обновляется при обновлении источника данных

В этом проекте есть источник данных, который проходит через массив StorageFolders и создает ObservableCollection с определенной информацией, такой как имя, расширение и дата изменения, которая затем привязывается к ListView, Проблема в том, что программа не будет заново заполнять ListView папками (новыми элементами), основанными на выбранном элементе. Тем не менее, я заметил, что программа обращается к подпапкам элемента, на который нажали, потому что она отображает правильный путь внизу TextBlock,

Заранее благодарим за ваше постоянное стремление помочь. Если есть какой-то способ, которым я могу улучшить этот вопрос, чтобы лучше принести пользу сообществу, пожалуйста, не стесняйтесь, дайте мне знать.

[FileLoader.cs]

namespace Files
{
    public class FileLoader : INotifyPropertyChanged
    {
        private string FileName;
        private string AccessedDate;
        private string FileType;
        private string FolderPath;

        public string Name
        {
            get { return this.FileName; }
            set
            {
                if (this.FileName != value)
                {
                    this.FileName = value;
                    this.RaisePropertyChanged("Name");
                }
            }

        }

        public string Date
        {
            get { return this.AccessedDate; }
            set
            {
                if (this.AccessedDate != value)
                {
                    this.AccessedDate = value;
                    this.RaisePropertyChanged("Date");
                }
            }

        }

        public string Type
        {
            get { return this.FileType; }
            set
            {
                if (this.FileType != value)
                {
                    this.FileType = value;
                    this.RaisePropertyChanged("Type");
                }
            }

        }

        public string Path
        {
            get { return this.FolderPath; }
            set
            {
                if (this.FolderPath != value)
                {
                    this.FolderPath = value;
                    this.RaisePropertyChanged("Path");
                }
            }

        }


        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }




    }

    public class ItemViewModel
    {
        StorageFolder folder;
        public ObservableCollection<FileLoader> infoList = new ObservableCollection<FileLoader>();
        public ObservableCollection<FileLoader> InfoList { get { return this.infoList; } }
        public ObservableCollection<FileLoader> folInfoList = new ObservableCollection<FileLoader>();
        public ObservableCollection<FileLoader> FolInfoList { get { return this.folInfoList; } }
        string gotName;
        string gotDate;
        string gotType;
        string gottenPath;
        string gotFolName;
        string gotFolDate;
        string gotFolPath;
        public IReadOnlyList<StorageFolder> folderList;


        public ItemViewModel(string thePath)
        {

            gottenPath = thePath;
            GetTheFilesAsync(thePath);
            GetTheFoldersAsync(thePath);
        }

        public async void GetTheFoldersAsync(string path)
        {

            FileLoader fileL = new FileLoader();
            folder = await StorageFolder.GetFolderFromPathAsync(path);
            folderList = await folder.GetFoldersAsync();
            foreach(StorageFolder fol in folderList)
            {
                gotFolName = fol.Name.ToString();
                gotFolDate = fol.DateCreated.ToString();
                gotFolPath = fol.Path.ToString();
                this.folInfoList.Add(new FileLoader() { Name = gotFolName, Date = gotFolDate, Path = gotFolPath });

            }
        }


        public async void GetTheFilesAsync(string path)
        {
            folder = await StorageFolder.GetFolderFromPathAsync(path);
            IReadOnlyList<StorageFile> fileList = await folder.GetFilesAsync();
            foreach (StorageFile f in fileList)
            {
                gotName = f.Name.ToString();
                gotDate = f.DateCreated.ToString(); // In the future, parse date to human readable format
                gotType = f.FileType.ToString();
                this.infoList.Add(new FileLoader() { Name = gotName, Date = gotDate, Type = gotType });

            }
        }

    }

}

[GenericFileBrowser.cs]

namespace Files
{

    public sealed partial class GenericFileBrowser : Page
    {
        string pathToView;
        public TextBlock textBlock;

        public GenericFileBrowser()
        {
            this.InitializeComponent();
            textBlock = importDiag;
            pathToView = @"C:\";
            string pathToKeep;
            string env = Environment.ExpandEnvironmentVariables("%userprofile%");
            this.ViewModel = new ItemViewModel(pathToView);
            this.IsTextScaleFactorEnabled = true;
            ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(500, 500));
            var CoreTitleBar = CoreApplication.GetCurrentView().TitleBar;
            CoreTitleBar.ExtendViewIntoTitleBar = true;
            var titleBar = ApplicationView.GetForCurrentView().TitleBar;
            titleBar.ButtonBackgroundColor = Color.FromArgb(100, 255, 255, 255);
            titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 10, 10, 10);
            titleBar.ButtonHoverBackgroundColor = Color.FromArgb(75, 10, 10, 10);


        }
        public ItemViewModel ViewModel { get; set; }


        private void navView_ItemInvoked(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
        {
            NavigationViewItem item = args.SelectedItem as NavigationViewItem;
            if (item.Name == "homeIc")
            {
                this.Frame.Navigate(typeof(MainPage));
            }
            else if (item.Name == "DesktopIC")
            {
                this.Frame.Navigate(typeof(Desktop));

            }
        }



        private void FolderView_ItemClick(object sender, SelectionChangedEventArgs e)
        {
            var selectedIndex = FolderView.Items.IndexOf(FolderView.SelectedItem);
            string pathOfSelected = ViewModel.FolInfoList[selectedIndex].Path;
            importDiag.Text = pathOfSelected;
            ViewModel = new ItemViewModel(pathOfSelected);

        }

        private void FileView_ItemClick(object sender, ItemClickEventArgs e)
        {

        }


    }

}

[GenericFileBrowser.xaml]

<Page
    x:Class="Files.GenericFileBrowser"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="using:Files"
    mc:Ignorable="d" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto">

    <Page.Resources>
        <AcrylicBrush x:Key="RegAcrylic" BackgroundSource="HostBackdrop" TintColor="White" TintOpacity="0.7" FallbackColor="{StaticResource SystemChromeMediumColor}"/>
        <AcrylicBrush x:Key="InAppAcrylic" BackgroundSource="Backdrop"  TintColor="#FF16B7E8" TintOpacity="0.6" FallbackColor="{StaticResource SystemChromeHighColor}"/>
        <AcrylicBrush x:Key="LightAcrylic" BackgroundSource="HostBackdrop" TintColor="White" TintOpacity="0.8" FallbackColor="{StaticResource SystemChromeMediumColor}"/>
        <Storyboard x:Name="PointerHoverButton1">
            <FadeOutThemeAnimation Storyboard.TargetName="Shadow1"/>

        </Storyboard>
    </Page.Resources>
    <Grid>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState>
                    <VisualState.StateTriggers>
                        <!--VisualState to be triggered when window width is >=0 effective pixels.-->
                        <AdaptiveTrigger MinWindowHeight="0"/>
                    </VisualState.StateTriggers>

                    <VisualState.Setters>

                    </VisualState.Setters>
                </VisualState>

                <VisualState>
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowHeight="1080"/>
                    </VisualState.StateTriggers>
                    <VisualState.Setters>

                    </VisualState.Setters>
                </VisualState>

            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>


        <ScrollViewer Margin="320,0,0,0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
            <Grid Background="White">
                <controls:ScrollHeader Mode="Sticky" HorizontalAlignment="Stretch" Height="240" VerticalAlignment="Top" FontFamily="Segoe UI Black" FontWeight="Bold" HorizontalContentAlignment="Stretch" FontSize="48">
                    <Grid HorizontalAlignment="Stretch">

                        <TextBlock Text=""/>
                        <TextBlock x:Name="VisiblePath" Text="" Margin="50,150,0,0" FontFamily="Segoe UI Black" FontWeight="Bold" FontSize="48"></TextBlock>

                    </Grid>
                </controls:ScrollHeader>
                <Grid Padding="50,250,50,25">
                    <StackPanel Orientation="Vertical">

                        <ListView x:Name="FolderView" SelectionMode="Single"  IsItemClickEnabled="False" SelectionChanged="FolderView_ItemClick" Background="{StaticResource LightAcrylic}"  ItemsSource="{x:Bind ViewModel.FolInfoList}" Margin="0,0,1500,0" VerticalAlignment="Top" HorizontalAlignment="Center">
                            <ListView.ItemTemplate>
                                <DataTemplate x:DataType="local:FileLoader">

                                    <Grid Background="{StaticResource LightAcrylic}" Width="1050" Height="45" VerticalAlignment="Center" BorderBrush="White" BorderThickness="0,0,0,0.5">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition></ColumnDefinition>
                                            <ColumnDefinition></ColumnDefinition>
                                            <ColumnDefinition></ColumnDefinition>

                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0" Text="{x:Bind Name}" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Center"></TextBlock>
                                        <TextBlock Grid.Column="1" Text="{x:Bind Date}" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center"></TextBlock>
                                        <TextBlock Grid.Column="2" Text="Folder" HorizontalAlignment="Right" Margin="0,0,0,0" VerticalAlignment="Center"></TextBlock>
                                    </Grid>

                                </DataTemplate>
                            </ListView.ItemTemplate>

                        </ListView>

                        <ListView x:Name="FileView" ItemClick="FileView_ItemClick" Background="{StaticResource LightAcrylic}"  ItemsSource="{x:Bind ViewModel.InfoList}" Margin="0,0,1500,0" VerticalAlignment="Top">
                            <ListView.ItemTemplate>
                                <DataTemplate x:DataType="local:FileLoader">

                                    <Grid Background="{StaticResource LightAcrylic}" Width="1050" Height="45" VerticalAlignment="Center">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition></ColumnDefinition>
                                            <ColumnDefinition></ColumnDefinition>
                                            <ColumnDefinition></ColumnDefinition>

                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0" Text="{x:Bind Name}" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Center"></TextBlock>
                                        <TextBlock Grid.Column="1" Text="{x:Bind Date}" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center"></TextBlock>
                                        <TextBlock Grid.Column="2" Text="{x:Bind Type}" HorizontalAlignment="Right" Margin="0,0,0,0" VerticalAlignment="Center"></TextBlock>
                                    </Grid>

                                </DataTemplate>
                            </ListView.ItemTemplate>

                        </ListView>
                    </StackPanel>
                </Grid>
                <TextBlock x:Name="importDiag" HorizontalAlignment="Left" Margin="140,845,0,215" Text="TextBlock" TextWrapping="Wrap" Width="612"/>
            </Grid>



        </ScrollViewer>
        <RelativePanel>
            <Grid Background="{StaticResource RegAcrylic}" Height="1080" Width="320">
                <NavigationView SelectionChanged="navView_ItemInvoked" IsPaneToggleButtonVisible="false" IsSettingsVisible="False" x:Name="navView" VerticalContentAlignment="Top" HorizontalContentAlignment="Stretch" IsPaneOpen="True" CompactModeThresholdWidth="560" ExpandedModeThresholdWidth="0" HorizontalAlignment="Stretch" Background="#FFF2F2F2" UseLayoutRounding="True" Margin="0,160,0,0">
                    <NavigationView.MenuItems>

                        <NavigationViewItem x:Name="homeIc"  Margin="30,0,0,0" Content="Home" FontFamily="Segoe UI">
                            <NavigationViewItem.Icon>
                                <FontIcon Glyph="&#xE80F;" FontFamily="Segoe MDL2 Assets"></FontIcon>
                            </NavigationViewItem.Icon>
                        </NavigationViewItem>

                        <NavigationViewItem Content="Desktop" x:Name="DesktopIC" IsSelected="True" FontFamily="Segoe UI" Margin="30,0,0,0">
                            <NavigationViewItem.Icon>
                                <FontIcon Glyph="&#xE8FC;" FontFamily="Segoe MDL2 Assets"></FontIcon>
                            </NavigationViewItem.Icon>
                        </NavigationViewItem>

                        <NavigationViewItem Content="Downloads" FontFamily="Segoe UI" Margin="30,0,0,0">
                            <NavigationViewItem.Icon>
                                <FontIcon Glyph="&#xE896;" FontFamily="Segoe MDL2 Assets"></FontIcon>
                            </NavigationViewItem.Icon>
                        </NavigationViewItem>

                        <NavigationViewItem Content="Documents" FontFamily="Segoe UI" Margin="30,0,0,0">
                            <NavigationViewItem.Icon>
                                <FontIcon Glyph="&#xE8A5;" FontFamily="Segoe MDL2 Assets"></FontIcon>
                            </NavigationViewItem.Icon>
                        </NavigationViewItem>

                        <NavigationViewItem Content="Pictures" FontFamily="Segoe UI" Margin="30,0,0,0">
                            <NavigationViewItem.Icon>
                                <FontIcon Glyph="&#xE8B9;" FontFamily="Segoe MDL2 Assets"></FontIcon>
                            </NavigationViewItem.Icon>
                        </NavigationViewItem>

                        <NavigationViewItem Content="Music" FontFamily="Segoe UI" Margin="30,0,0,0">
                            <NavigationViewItem.Icon>
                                <FontIcon Glyph="&#xEC4F;" FontFamily="Segoe MDL2 Assets"></FontIcon>
                            </NavigationViewItem.Icon>
                        </NavigationViewItem>

                        <NavigationViewItem Content="Videos" FontFamily="Segoe UI" Margin="30,0,0,0">
                            <NavigationViewItem.Icon>
                                <FontIcon Glyph="&#xE8B2;" FontFamily="Segoe MDL2 Assets"></FontIcon>
                            </NavigationViewItem.Icon>
                        </NavigationViewItem>

                        <NavigationViewItemHeader Content="DRIVES" Margin="30,15,0,0" FontFamily="Segoe UI Semibold" FontSize="8"></NavigationViewItemHeader>

                        <NavigationViewItem Content="Local Disk" FontFamily="Segoe UI" Margin="30,0,0,0">
                            <NavigationViewItem.Icon>
                                <FontIcon Glyph="&#xEDA2;" FontFamily="Segoe MDL2 Assets"></FontIcon>
                            </NavigationViewItem.Icon>
                        </NavigationViewItem>
                    </NavigationView.MenuItems>
                </NavigationView>
                <TextBlock HorizontalAlignment="Left" Margin="45,121,0,0" Text="Files" TextWrapping="Wrap" VerticalAlignment="Top" FontFamily="Segoe UI Black" FontSize="20" FontWeight="Bold"/>
            </Grid>
        </RelativePanel>
    </Grid>


</Page>

0 ответов

Другие вопросы по тегам