none
ComboBox: System.ArgumentOutOfRangeException bei Bindung an eine Collection RRS feed

  • Frage

  • Hallo,

    ich bekomme eine Exception wenn ich eine CombpBox-Liste mit Click auf den Pfeil rechts öffnen will.

    System.ArgumentOutOfRangeException: This collection cannot work with indices larger than Int32.MaxValue - 1

    Beim ersten Mal geht es. Wenn ich dann einen Ordner geöffnet habe kommt die Exception.
    Es ist Windows 10, Visual Studio Express for Windows mit Update 5

    Das ist die Combo-Box:

    <ComboBox x:Name="FolderComboBox" 
              ItemsSource="{Binding CustomObj_FolderList}"
              DisplayMemberPath="FolderName"
              Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
              Foreground="{ThemeResource ApplicationForegroundThemeBrush}"
              FontSize="16"
              IsDropDownOpen="False" 
              HorizontalAlignment="Left" VerticalAlignment="Top" 
              BorderThickness="0"
              Margin="10,10,10,10"
              Style="{StaticResource ComboBoxStyle1}"/>
    


    ItemsSource der Combobox die CustomObj_FolderList ist so definiert und wird mit dem folgenden Code gefüllt:

    public class clsCustomObj_Folder
    {
       public string token;
    
       string folderName;
          public string FolderName
          { get { return folderName; } set { folderName = value; } }
    
          public clsCustomObj_Folder(string ptoken, string pfolderName)
          { token = ptoken; folderName = pfolderName; }
    }
    
    
    
    public Collection<clsCustomObj_Folder> CustomObj_FolderList
    {
          get { return (Collection<clsCustomObj_Folder>)GetValue(CustomObj_FolderList_Property); }
          set { SetValue(CustomObj_FolderList_Property, value); }
    }
    
    public static readonly DependencyProperty CustomObj_FolderList_Property =
    DependencyProperty.Register("CustomObj_FolderList", typeof(Collection<clsCustomObj_Folder>), typeof(MainPage),
    new PropertyMetadata(new Collection<clsCustomObj_Folder>()));
    
    
    private async void FolderOpenButton_Click(object sender, RoutedEventArgs e)
    {
          string exMsg = "";
    
          try
          {
            FolderPicker folderPicker = new FolderPicker();
            folderPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            folderPicker.ViewMode = PickerViewMode.List;
            folderPicker.FileTypeFilter.Add("*");
    
            IAsyncOperation<StorageFolder> AsyncOperation_StorageFolder =
              folderPicker.PickSingleFolderAsync();
    
            // Do something.
    
            StorageFolder folder = await AsyncOperation_StorageFolder;
    
            if (folder != null)
            {
              // Application now has read/write access to the picked folder
              mfolderCurrent = folder;
    
              // offen: eher add?
              Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add
                              (mfolderCurrent);
    
              // Hole die Unterordner.
              CustomObj_FolderList_Fill(mfolderCurrent);
            }
          }
    
          catch (Exception ex)
          {
            exMsg = ex.Message;
          }
    
          if (exMsg.Length > 0)
          {
            var msgDlg = new Windows.UI.Popups.MessageDialog(exMsg);
            msgDlg.DefaultCommandIndex = 1;
            await msgDlg.ShowAsync();
          }
    }
    
    
    private async void CustomObj_FolderList_Fill(StorageFolder pfolder)
    {
          // Get the files and folders in the current folder.
          IReadOnlyList<IStorageItem> itemsInFolder =
                   await mfolderCurrent.GetItemsAsync();
    
          // Iterate over the results and print the list of items
          // to the Visual Studio Output window.
          CustomObj_FolderList.Clear();
          CustomObj_FolderList = null;
          CustomObj_FolderList = new Collection<clsCustomObj_Folder>();
    
          foreach (IStorageItem item in itemsInFolder)
          {
            if (item.IsOfType(StorageItemTypes.Folder))
              CustomObj_FolderList.Add(new clsCustomObj_Folder(item.Name, item.Name));
          }
    }
    
    
    

    Was kann da die Ursache sein?

    Grüße und Danke,
    Markus


    Freitag, 31. Juli 2015 07:07

Antworten

Alle Antworten

  • Hi Markus,
    was soll die DependencyProperty im Code?

    Ich habe sie rausgenommen und Dein Code funktioniert bei mir problemlos.


    --
    Viele Grüsse
    Peter Fleischer (MVP, Partner)
    Meine Homepage mit Tipps und Tricks

    • Als Antwort markiert Markus222 Freitag, 31. Juli 2015 19:33
    Freitag, 31. Juli 2015 07:29
  • Hallo Peter,

    dachte warum nicht? (Im Stillen hatte ich so eine Ahnung...). Es erspart einem die Observable Collection mit zusätzlichem Code.

    Probiere es heute am späteren Abend mal aus und berichte morgen früh ob es geklappt hat.

    Freitag, 31. Juli 2015 07:38
  • Hi Markus,
    wenn Du die DependencyProperty einbaust, dann musst Du sie auch nutzen. In Deinen Codeausschnitten ist aber keine Bindung vorhanden. Hier mal meine Demo:

    XAML:

    <Page
        x:Class="App2.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App2"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
      <Page.Resources>
        <local:Class1 x:Key="vm"/>
      </Page.Resources>
      <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
              DataContext="{Binding Source={StaticResource vm}}">
        <ComboBox x:Name="FolderComboBox" 
              ItemsSource="{Binding CustomObj_FolderList}"
              DisplayMemberPath="FolderName"
              FontSize="16"
              IsDropDownOpen="False" 
              HorizontalAlignment="Left" VerticalAlignment="Top" 
              BorderThickness="0"
              Margin="10,10,10,10"/>
      </Grid>
    </Page>
    

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using Windows.Foundation;
    using Windows.Storage;
    using Windows.Storage.Pickers;
    using Windows.UI.Xaml;
    
    namespace App2
    {
      class Class1
      {
        public Class1()
        {
          FolderOpenButton_Click(null, null);
        }
        public class clsCustomObj_Folder
        {
          public string token;
    
          string folderName;
          public string FolderName
          { get { return folderName; } set { folderName = value; } }
    
          public clsCustomObj_Folder(string ptoken, string pfolderName)
          { token = ptoken; folderName = pfolderName; }
        }
    
        private StorageFolder mfolderCurrent;
    
        Collection<clsCustomObj_Folder> cfl;
        public Collection<clsCustomObj_Folder> CustomObj_FolderList
        {
          get { return cfl; }
          set { cfl = value; }
        }
    
    
        private async void FolderOpenButton_Click(object sender, RoutedEventArgs e)
        {
          string exMsg = "";
    
          try
          {
            FolderPicker folderPicker = new FolderPicker();
            folderPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            folderPicker.ViewMode = PickerViewMode.List;
            folderPicker.FileTypeFilter.Add("*");
    
            IAsyncOperation<StorageFolder> AsyncOperation_StorageFolder =
              folderPicker.PickSingleFolderAsync();
    
            // Do something.
    
            StorageFolder folder = await AsyncOperation_StorageFolder;
    
            if (folder != null)
            {
              // Application now has read/write access to the picked folder
              mfolderCurrent = folder;
    
              // offen: eher add?
              Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add
                              (mfolderCurrent);
    
              // Hole die Unterordner.
              CustomObj_FolderList_Fill(mfolderCurrent);
            }
          }
    
          catch (Exception ex)
          {
            exMsg = ex.Message;
          }
    
          if (exMsg.Length > 0)
          {
            var msgDlg = new Windows.UI.Popups.MessageDialog(exMsg);
            msgDlg.DefaultCommandIndex = 1;
            await msgDlg.ShowAsync();
          }
        }
    
    
        private async void CustomObj_FolderList_Fill(StorageFolder pfolder)
        {
          // Get the files and folders in the current folder.
          IReadOnlyList<IStorageItem> itemsInFolder =
                   await mfolderCurrent.GetItemsAsync();
    
          // Iterate over the results and print the list of items
          // to the Visual Studio Output window.
          CustomObj_FolderList.Clear();
          CustomObj_FolderList = null;
          CustomObj_FolderList = new Collection<clsCustomObj_Folder>();
    
          foreach (IStorageItem item in itemsInFolder)
          {
            if (item.IsOfType(StorageItemTypes.Folder))
              CustomObj_FolderList.Add(new clsCustomObj_Folder(item.Name, item.Name));
          }
        }
    
      }
    }
    


    --
    Viele Grüsse
    Peter Fleischer (MVP, Partner)
    Meine Homepage mit Tipps und Tricks

    • Als Antwort vorgeschlagen Peter Fleischer Freitag, 31. Juli 2015 07:56
    • Nicht als Antwort vorgeschlagen Markus222 Freitag, 31. Juli 2015 19:33
    Freitag, 31. Juli 2015 07:55
  • Hallo Peter,

    bitte verzeih. Habe mich in den letzten Jahren seit 2010 nur wenig mit Programmieren beschäftigt. Vorher Visual Basic. Weil mir die Oberfläche gefällt wollte ich mir ein Programm für private Textdateien schreiben. Komfortabler und schöner als mit Windows-Explorer und Editor. Bis jetzt ist es nur ein Versuch und nicht mal halbfertig.

    Eine extra Klasse habe ich nicht. Alles ist im Code Behind File also in MainPage.xaml.cs. Unten ist MainPage.xaml.

    Der Text aus der Datei wird in der TextBox (nach der Grid Definition) mit dem Binding TextSimple1 angezeigt. TextSimple1 ist ein Dependancy Property. Das hat die Change Notification enthalten.

    Ebenso ist der TextBlock darunter fileCurrent_Path ein Dependancy Property. Auch hier wird beim Öffnen verschiedener Dateien über den FileOpenPicker der Pfad und die Datei angezeigt.

    Beim ersten Öffen eines Ordners über den FolderPicker werden die Dateien in der Combobox angezeigt. Nach dem Öffnen des zweiten Ordners und Füllen der ComboBox kommt die Exception beim Klicken auf den Pfeil zum Öffnen der Liste.

    Ich weiss nicht ob ich jetzt eine Kopie des Projekts erstellen soll und das alte sichern und alles so probieren soll wie du vorschlägst. Also den Code von MainPage.xaml.cs in eine extra Klasse auslagern und das andere auch.

    Hast du auch mehrere Ordner über den Button geöffnet, quer Beet? Notfalls probiere ich es dann so. Aber ich scheue ein bisschen den Aufwand. Wenn du willst poste ich dann MainPage.xaml.cs hinterher? Vielleicht läuft der ja bei dir und der Fehler ist woanders.


    <Page
        x:Name="pageRoot"
        x:Class="App4.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App4"
        xmlns:common="using:App4.Common"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        mc:Ignorable="d">
    
    
      <Page.Resources>
        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName_Only_Demonstration">Ebay</x:String>
      </Page.Resources>
    
      <!--
            This grid acts as a root panel for the page that defines two rows:
            * Row 0 contains the back button and page title
            * Row 1 contains the rest of the page layout
        -->
      <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ChildrenTransitions>
          <TransitionCollection>
            <EntranceThemeTransition/>
          </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="9*"/>
          <RowDefinition Height="*"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="80"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
      
        <TextBox Text="{Binding TextSimple1, Mode=TwoWay}"  
                 Grid.Row="0" Grid.Column="1" AcceptsReturn="True" TextWrapping="Wrap" 
                 Margin="0,100,30,0" FontSize="18" ScrollViewer.VerticalScrollBarVisibility="Visible"/>
    
        <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding fileCurrent_Path}" Style="{StaticResource PathTextBlockStyle_Local}" 
                   IsHitTestVisible="false" />
    
        <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left">
    
          <ComboBox x:Name="FolderComboBox" 
                    ItemsSource="{Binding CustomObj_FolderList}"
                    DisplayMemberPath="FolderName"
                    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
                    Foreground="{ThemeResource ApplicationForegroundThemeBrush}"
                    FontSize="16"
                    IsDropDownOpen="False" 
                    HorizontalAlignment="Left" VerticalAlignment="Top" 
                    BorderThickness="0"
                    Margin="10,10,10,10"
                    Style="{StaticResource ComboBoxStyle1}"/>
    
          <ComboBox x:Name="FileComboBox" 
                    ItemsSource="{Binding CustomObj_FileList}"
                    DisplayMemberPath="FileName"
                    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
                    Foreground="{ThemeResource ApplicationForegroundThemeBrush}"
                    FontSize="16"
                    IsDropDownOpen="False" 
                    HorizontalAlignment="Left" VerticalAlignment="Top" 
                    BorderThickness="0"
                    Margin="10,10,10,10"
                    Style="{StaticResource ComboBoxStyle1}"/>
    
    
          <Button Content = "Speichern"  Click="FileSaveButton_Click" FontSize="16" Margin="10,10,10,10"/>
          <Button Content = "Ordner öffnen"  Click="FolderOpenButton_Click" FontSize="16" Margin="10,10,10,10"/>
          <Button Content = "Öffnen"  Click="FileOpenButton_Click" FontSize="16" Margin="10,10,10,10"/>
    
        </StackPanel> 
      </Grid>
    </Page>
    


    Freitag, 31. Juli 2015 10:10
  • Hi Markus,
    gerade für gelegentliche Programmierarbeiten ist Visual Basic wegen der gut lesbaren Anweisungen besser geeignet als C# mit den vielen nichtssagenden Klammern. Deshalb verstehe ich nicht, warum Du Dir diesen Stress antust.

    Das mit der Extra-Klasse mache ich, weil es für mich einfacher ist und ich MVVM liebe.

    Ordner habe ich beliebig geöffnet und wieder geschlossen. Dabei sind keine Probleme aufgetreten. Da mir nicht der gesamte Code zur Verfügung stand, habe ich geringfügig abgerüstet und den Aufruf von FolderOpenButton_Click in den Konstruktor eingebaut.

    Dein Programmcode hatte bei mir nicht funktioniert, weshalb ich ihn umgebaut hatte, damit er funktioniert. Du müsstest schon eine solche Demo liefern, die den Fehler ohne Nachbearbeitung eindeutig reproduzieren lässt.


    --
    Viele Grüsse
    Peter Fleischer (MVP, Partner)
    Meine Homepage mit Tipps und Tricks

    Freitag, 31. Juli 2015 11:50
  • Hallo Peter,

    im Konstruktor funktioniert es bei mir auch problemlos. Die Combo Box zeigt die Unterordnernamen. Nach dem ersten FolderOpenButten_Click geht es ebenso.

    Nach dem zweiten FolderOpenButton_Click kommt dann der Fehler. Ich versuche mal das Dependency Property durch ein normales Property zu ersetzen. Wenn das nicht hilft das ganze in eine eigene Klasse auszulagern und diese als Page.DataContext zu deklarieren. (Heute oder morgen Abend.)

     <Page.DataContext>
        <local:clsDirectoriesAndFiles/>
      </Page.DataContext>
    

     public MainPage()
        {
          this.InitializeComponent();
          this.navigationHelper = new NavigationHelper(this);
          this.navigationHelper.LoadState += navigationHelper_LoadState;
          this.navigationHelper.SaveState += navigationHelper_SaveState;
    
          //Task t = Read();
          CustomObj_FolderList = new Collection<clsCustomObj_Folder>();
          FolderCurrent_Fill();
          if (mfolderCurrent != null)
          {
            CustomObj_FolderList_Fill(mfolderCurrent);
          }
        }

    Freitag, 31. Juli 2015 12:03
  • Ich weiß nicht. Wenn ich Debug aufrufe wird der Aufruf von CustomObj_FolderList_Fill beim zweiten Mal
    (vor dem Fehler) übersprungen. mfolderCurrent hat den aktuell gewählten Ordner. Aber die
    CustomObj_FolderList noch die Einträge es vorherigen Ordners...

    Unten ist der Code von MainPage und App. Habe es vorher noch mal in ein neues Projekt kopiert.
    Ergebnis war das gleiche.
    (Es ist Windows 10 und Visual Studio Express for Windows Update 5.)

       {
              // Application now has read/write access to the picked folder
              mfolderCurrent = folder;

              // offen: eher add?
              Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add
                              (mfolderCurrent);

             

              // Hole die Unterordner.
              CustomObj_FolderList_Fill(mfolderCurrent);

              folderCurrent_Path = mfolderCurrent.Path + " " + CustomObj_FolderList.Count;
            }


    MainPage.xaml:

    <Page
        x:Name="pageRoot"
        x:Class="App6.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App6"
        xmlns:common="using:App6.Common"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        mc:Ignorable="d">
    
    
      <Page.Resources>
        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName_Only_Demonstration">Ebay</x:String>
      </Page.Resources>
    
      <!--
            This grid acts as a root panel for the page that defines two rows:
            * Row 0 contains the back button and page title
            * Row 1 contains the rest of the page layout
        -->
      <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ChildrenTransitions>
          <TransitionCollection>
            <EntranceThemeTransition/>
          </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="9*"/>
          <RowDefinition Height="*"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="80"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
    
        <TextBox Text="{Binding TextSimple1, Mode=TwoWay}"  
                 Grid.Row="0" Grid.Column="1" AcceptsReturn="True" TextWrapping="Wrap" 
                 Margin="0,100,30,0" FontSize="18" ScrollViewer.VerticalScrollBarVisibility="Visible"/>
    
        <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Vertical" HorizontalAlignment="Left">
          <TextBlock Text="{Binding folderCurrent_Path}" Style="{StaticResource PathTextBlockStyle_Local}" 
                   IsHitTestVisible="false" />
    
          <TextBlock  Text="{Binding fileCurrent_Path}" Style="{StaticResource PathTextBlockStyle_Local}" 
                   IsHitTestVisible="false" />
        </StackPanel>
    
        <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left">
    
          <ComboBox x:Name="FolderComboBox" 
                    ItemsSource="{Binding CustomObj_FolderList}"
                    DisplayMemberPath="FolderName"
                    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
                    Foreground="{ThemeResource ApplicationForegroundThemeBrush}"
                    FontSize="16"
                    IsDropDownOpen="False" 
                    HorizontalAlignment="Left" VerticalAlignment="Top" 
                    BorderThickness="0"
                    Margin="10,10,10,10"
                    Style="{StaticResource ComboBoxStyle1}"/>
    
          <ComboBox x:Name="FileComboBox" 
                    ItemsSource="{Binding CustomObj_FileList}"
                    DisplayMemberPath="FileName"
                    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
                    Foreground="{ThemeResource ApplicationForegroundThemeBrush}"
                    FontSize="16"
                    IsDropDownOpen="False" 
                    HorizontalAlignment="Left" VerticalAlignment="Top" 
                    BorderThickness="0"
                    Margin="10,10,10,10"
                    Style="{StaticResource ComboBoxStyle1}"/>
    
    
          <Button Content = "Speichern"  Click="FileSaveButton_Click" FontSize="16" Margin="10,10,10,10"/>
          <Button Content = "Ordner öffnen"  Click="FolderOpenButton_Click" FontSize="16" Margin="10,10,10,10"/>
          <Button Content = "Öffnen"  Click="FileOpenButton_Click" FontSize="16" Margin="10,10,10,10"/>
    
        </StackPanel>
      </Grid>
    </Page>
    


    MainPage.xaml.cs:

    using App6.Common;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    using System.Diagnostics;
    using System.Collections.ObjectModel;
    
    using Windows.Storage;
    using Windows.Storage.Pickers;
    using System.Threading.Tasks;
    using Windows.Graphics.Printing;
    using Windows.UI.Xaml.Printing;
    
    // The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237
    
    namespace App6
    {
      /// <summary>
      /// A basic page that provides characteristics common to most applications.
      /// </summary>
      public sealed partial class MainPage : Page
      {
    
        public class clsCustomObj_Folder
        {
          public string token;
    
          string folderName;
          public string FolderName
          { get { return folderName; } set { folderName = value; } }
    
          public clsCustomObj_Folder(string ptoken, string pfolderName)
          { token = ptoken; folderName = pfolderName; }
        }
    
    
        public class clsCustomObj_File
        {
          public string token;
    
          string fileName;
          public string FileName
          { get { return fileName; } set { fileName = value; } }
    
          public clsCustomObj_File(string ptoken, string pfileName)
          { token = ptoken; fileName = pfileName; }
        }
    
        private NavigationHelper navigationHelper;
        private ObservableDictionary defaultViewModel = new ObservableDictionary();
    
        /// <summary>
        /// This can be changed to a strongly typed view model.
        /// </summary>
        public ObservableDictionary DefaultViewModel
        {
          get { return this.defaultViewModel; }
        }
    
        /// <summary>
        /// NavigationHelper is used on each page to aid in navigation and 
        /// process lifetime management
        /// </summary>
        public NavigationHelper NavigationHelper
        {
          get { return this.navigationHelper; }
        }
    
        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session. The state will be null the first time a page is visited.</param>
        private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
        }
    
        /// <summary>
        /// Preserves state associated with this page in case the application is suspended or the
        /// page is discarded from the navigation cache.  Values must conform to the serialization
        /// requirements of <see cref="SuspensionManager.SessionState"/>.
        /// </summary>
        /// <param name="sender">The source of the event; typically <see cref="NavigationHelper"/></param>
        /// <param name="e">Event data that provides an empty dictionary to be populated with
        /// serializable state.</param>
        private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
        {
        }
    
        #region NavigationHelper registration
    
        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// 
        /// Page specific logic should be placed in event handlers for the  
        /// <see cref="GridCS.Common.NavigationHelper.LoadState"/>
        /// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method 
        /// in addition to page state preserved during an earlier session.
    
    
        PrintManager mPrintManager;
        PrintDocument mPrintDocument;
        IPrintDocumentSource mIPrintDocumentSource;
    
    
    
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
          navigationHelper.OnNavigatedTo(e);
    
          // Initialilisieren Drucken.
          Register_For_Printing();
        }
    
        protected void Register_For_Printing()
        {
          /*
          // Create the PrintDocument.
          mPrintDocument = new PrintDocument();
    
          // Save the Document Source.
          mIPrintDocumentSource = mPrintDocument.DocumentSource;
    
          // Add an event handler which creates preview pages.
          mPrintDocument.Paginate += CreatePrintPreviewPages;
    
          // Add an event handler which provides a specific preview page.
          mPrintDocument.GetPreviewPage += GetPrintPreviewPage;
    
          // Add an event handler which provides all final print pages.
          mPrintDocument.AddPages += AddPrintPages;
    
          // Create a PrintManager and add a handler for printing initialization.
          */
    
    
    
        }
    
    
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
          navigationHelper.OnNavigatedFrom(e);
    
          // Beim Verlassen der Seite.
          Unregister_For_Printing();
        }
    
        protected void Unregister_For_Printing()
        {
    
        }
    
        #endregion
    
        public Collection<clsCustomObj_Folder> CustomObj_FolderList
        {
          get { return (Collection<clsCustomObj_Folder>)GetValue(CustomObj_FolderList_Property); }
          set { SetValue(CustomObj_FolderList_Property, value); }
        }
    
       
        public static readonly DependencyProperty CustomObj_FolderList_Property =
          DependencyProperty.Register("CustomObj_FolderList", typeof(Collection<clsCustomObj_Folder>), typeof(MainPage),
          new PropertyMetadata(new Collection<clsCustomObj_Folder>()));
    
        public Collection<clsCustomObj_File> CustomObj_FileList
        {
          get { return (Collection<clsCustomObj_File>)GetValue(CustomObj_FileList_Property); }
          set { SetValue(CustomObj_FileList_Property, value); }
        }
    
        public static readonly DependencyProperty CustomObj_FileList_Property =
          DependencyProperty.Register("CustomObj_FileList", typeof(Collection<clsCustomObj_File>), typeof(MainPage),
          new PropertyMetadata(null));
    
        StorageFolder mfolderCurrent;
        StorageFile mfileCurrent;
    
        public string TextSimple1
        {
          get { return (string)GetValue(TextSimple1Property); }
          set { SetValue(TextSimple1Property, value); }
        }
    
        public static readonly DependencyProperty TextSimple1Property =
          DependencyProperty.Register("TextSimple1", typeof(string), typeof(MainPage),
          new PropertyMetadata("No file selected."));
    
    
        public string folderCurrent_Path
        {
          get { return (string)GetValue(folderCurrent_PathProperty); }
          set { SetValue(folderCurrent_PathProperty, value); }
        }
    
        public static readonly DependencyProperty folderCurrent_PathProperty =
          DependencyProperty.Register("folderCurrent_Path", typeof(string), typeof(MainPage),
          new PropertyMetadata("No folder selected."));
    
    
        public string fileCurrent_Path
        {
          get { return (string)GetValue(fileCurrent_PathProperty); }
          set { SetValue(fileCurrent_PathProperty, value); }
        }
    
        public static readonly DependencyProperty fileCurrent_PathProperty =
          DependencyProperty.Register("fileCurrent_Path", typeof(string), typeof(MainPage),
          new PropertyMetadata("No path selected."));
    
    
        public MainPage()
        {
          this.InitializeComponent();
          this.navigationHelper = new NavigationHelper(this);
          this.navigationHelper.LoadState += navigationHelper_LoadState;
          this.navigationHelper.SaveState += navigationHelper_SaveState;
    
          //Task t = Read();
          CustomObj_FolderList = new Collection<clsCustomObj_Folder>();
          FolderCurrent_Fill();
          if (mfolderCurrent != null)
          {
            CustomObj_FolderList_Fill(mfolderCurrent);
          }
    
          CustomObj_FileList = new Collection<clsCustomObj_File>();
          CustomObj_FileList.Add(new clsCustomObj_File("1", "F1"));
          CustomObj_FileList.Add(new clsCustomObj_File("2", "F2"));
          CustomObj_FileList.Add(new clsCustomObj_File("3", "F3"));
        }
    
        private async void FolderCurrent_Fill()
        {
          Windows.Storage.AccessCache.AccessListEntry entry;
    
          if (Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Entries.Count > 0)
          {
            entry = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Entries[0];
            mfolderCurrent =
            await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFolderAsync(entry.Token);
            folderCurrent_Path = mfolderCurrent.Path;
          }
        }
    
    
        private async void FileSaveButton_Click(object sender, RoutedEventArgs e)
        {
          string exMsg = "";
    
          if (mfileCurrent == null) return;
    
          try
          {
            await FileIO.WriteTextAsync(mfileCurrent, TextSimple1);
          }
          catch (Exception ex)
          {
            exMsg = ex.Message;
          }
    
          if (exMsg.Length > 0)
          {
            var msgDlg = new Windows.UI.Popups.MessageDialog(exMsg);
            msgDlg.DefaultCommandIndex = 1;
            await msgDlg.ShowAsync();
          }
        }
    
    
        private async void FolderOpenButton_Click(object sender, RoutedEventArgs e)
        {
          string exMsg = "";
    
          try
          {
            FolderPicker folderPicker = new FolderPicker();
            folderPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            folderPicker.ViewMode = PickerViewMode.List;
            folderPicker.FileTypeFilter.Add("*");
    
            IAsyncOperation<StorageFolder> AsyncOperation_StorageFolder =
              folderPicker.PickSingleFolderAsync();
    
            // Do something.
    
            StorageFolder folder = await AsyncOperation_StorageFolder;
    
            if (folder != null)
            {
              // Application now has read/write access to the picked folder
              mfolderCurrent = folder;
    
              // offen: eher add?
              Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add
                              (mfolderCurrent);
    
              // Hole die Unterordner.
              CustomObj_FolderList_Fill(mfolderCurrent);
              
              folderCurrent_Path = mfolderCurrent.Path + " " + CustomObj_FolderList.Count;
            }
          }
    
          catch (Exception ex)
          {
            exMsg = ex.Message;
          }
    
          if (exMsg.Length > 0)
          {
            var msgDlg = new Windows.UI.Popups.MessageDialog(exMsg);
            msgDlg.DefaultCommandIndex = 1;
            await msgDlg.ShowAsync();
          }
        }
    
    
        private async void CustomObj_FolderList_Fill(StorageFolder pfolder)
        {
          // Get the files and folders in the current folder.
          IReadOnlyList<IStorageItem> itemsInFolder =
                   await mfolderCurrent.GetItemsAsync();
    
          // Iterate over the results and print the list of items
          // to the Visual Studio Output window.
          CustomObj_FolderList.Clear();
          CustomObj_FolderList = null;
          CustomObj_FolderList = new Collection<clsCustomObj_Folder>();
    
          foreach (IStorageItem item in itemsInFolder)
          {
            if (item.IsOfType(StorageItemTypes.Folder))
            {
              CustomObj_FolderList.Add(new clsCustomObj_Folder(item.Name, item.Name));
            }
          }
        }
    
    
        private async void FileOpenButton_Click(object sender, RoutedEventArgs e)
        {
          FileOpenPicker openPicker = new FileOpenPicker();
          openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
          openPicker.ViewMode = PickerViewMode.List;
          openPicker.FileTypeFilter.Add(".txt");
    
          IAsyncOperation<StorageFile> AsyncOperation_StorageFile =
            openPicker.PickSingleFileAsync();
    
          // Do something.
    
          StorageFile file = await AsyncOperation_StorageFile;
    
          if (file != null)
          {
            // Application now has read/write access to the picked file
            mfileCurrent = file;
            fileCurrent_Path = mfileCurrent.Path;
    
            Task t = Read();
          }
          //}
        }
    
        private async Task Read()
        {
          string exMsg = "";
    
          try
          {
            var buffer = await FileIO.ReadBufferAsync(mfileCurrent);
            Windows.Storage.Streams.DataReader reader = Windows.Storage.Streams.DataReader.FromBuffer(buffer);
            byte[] fileContent = new byte[reader.UnconsumedBufferLength];
            reader.ReadBytes(fileContent);
            TextSimple1 = System.Text.Encoding.UTF8.GetString(fileContent, 0, fileContent.Length);
          }
          catch (Exception ex)
          {
            exMsg = ex.Message;
          }
    
          if (exMsg.Length > 0)
          {
            var msgDlg = new Windows.UI.Popups.MessageDialog(exMsg);
            msgDlg.DefaultCommandIndex = 1;
            await msgDlg.ShowAsync();
          }
        }
    
      }
    }
    
    
    


    App.xaml:

    <Application
        x:Class="App6.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App6">
    
      <Application.Resources>
        <!-- Cool comment 
          Zeile 2 -->
        <x:String x:Key="AppName">Ebay</x:String>
    
        <Style x:Key="PathTextBlockStyle_Local" BasedOn="{StaticResource BaseTextBlockStyle}" TargetType="TextBlock">
          <Setter Property="FontSize" Value="22"/>
          <Setter Property="FontWeight" Value="Light"/>
          <Setter Property="LineHeight" Value="40"/>
        </Style>
    
        <Style x:Key="ComboBoxStyle1" TargetType="ComboBox">
          <Setter Property="Padding" Value="8,0"/>
          <Setter Property="MinWidth" Value="{ThemeResource ComboBoxThemeMinWidth}"/>
          <Setter Property="Foreground" Value="{ThemeResource ComboBoxForegroundThemeBrush}"/>
          <Setter Property="Background" Value="{ThemeResource ComboBoxBackgroundThemeBrush}"/>
          <Setter Property="BorderBrush" Value="{ThemeResource ComboBoxBorderThemeBrush}"/>
          <Setter Property="BorderThickness" Value="{ThemeResource ComboBoxBorderThemeThickness}"/>
          <Setter Property="TabNavigation" Value="Once"/>
          <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
          <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
          <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled"/>
          <Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto"/>
          <Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="True"/>
          <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/>
          <Setter Property="ScrollViewer.BringIntoViewOnFocusChange" Value="True"/>
          <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
          <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
          <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
          <Setter Property="ItemsPanel">
            <Setter.Value>
              <ItemsPanelTemplate>
                <CarouselPanel/>
              </ItemsPanelTemplate>
            </Setter.Value>
          </Setter>
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="ComboBox">
                <Grid>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="32"/>
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                  </Grid.RowDefinitions>
                  <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                      <VisualState x:Name="Normal"/>
                      <VisualState x:Name="PointerOver">
                        <Storyboard>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ApplicationPageBackgroundThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Background">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPointerOverBorderThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="Highlight">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxSelectedPointerOverBackgroundThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                      </VisualState>
                      <VisualState x:Name="Pressed">
                        <Storyboard>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedBackgroundThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Background">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedBorderThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedForegroundThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                          <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PressedBackground"/>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="DropDownGlyph">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxArrowPressedForegroundThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                      </VisualState>
                      <VisualState x:Name="Disabled">
                        <Storyboard>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBackgroundThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Background">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBorderThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledForegroundThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="DropDownGlyph">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxArrowDisabledForegroundThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                      </VisualState>
                    </VisualStateGroup>
                    <VisualStateGroup x:Name="FocusStates">
                      <VisualState x:Name="Focused">
                        <Storyboard>
                          <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HighlightBackground"/>
                          <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Highlight"/>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxFocusedForegroundThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                      </VisualState>
                      <VisualState x:Name="FocusedPressed">
                        <Storyboard>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedForegroundThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="Highlight">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedHighlightThemeBrush}"/>
                          </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                      </VisualState>
                      <VisualState x:Name="Unfocused"/>
                      <VisualState x:Name="PointerFocused"/>
                      <VisualState x:Name="FocusedDropDown">
                        <Storyboard>
                          <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="PopupBorder">
                            <DiscreteObjectKeyFrame KeyTime="0">
                              <DiscreteObjectKeyFrame.Value>
                                <Visibility>Visible</Visibility>
                              </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                          </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                      </VisualState>
                    </VisualStateGroup>
                    <VisualStateGroup x:Name="DropDownStates">
                      <VisualState x:Name="Opened">
                        <Storyboard>
                          <SplitOpenThemeAnimation ClosedTargetName="ContentPresenter" ContentTranslationOffset="0" ContentTargetName="ScrollViewer" ClosedLength="{Binding TemplateSettings.DropDownClosedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}" OffsetFromCenter="{Binding TemplateSettings.DropDownOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" OpenedTargetName="PopupBorder" OpenedLength="{Binding TemplateSettings.DropDownOpenedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                        </Storyboard>
                      </VisualState>
                      <VisualState x:Name="Closed">
                        <Storyboard>
                          <SplitCloseThemeAnimation ClosedTargetName="ContentPresenter" ContentTranslationOffset="40" ContentTranslationDirection="{Binding TemplateSettings.SelectedItemDirection, RelativeSource={RelativeSource Mode=TemplatedParent}}" ContentTargetName="ScrollViewer" ClosedLength="{Binding TemplateSettings.DropDownClosedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}" OffsetFromCenter="{Binding TemplateSettings.DropDownOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" OpenedTargetName="PopupBorder" OpenedLength="{Binding TemplateSettings.DropDownOpenedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                        </Storyboard>
                      </VisualState>
                    </VisualStateGroup>
                  </VisualStateManager.VisualStateGroups>
                  <ContentPresenter x:Name="HeaderContentPresenter" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{ThemeResource ComboBoxHeaderForegroundThemeBrush}" FontWeight="{ThemeResource ComboBoxHeaderThemeFontWeight}" FlowDirection="{TemplateBinding FlowDirection}" Margin="{ThemeResource ComboBoxHeaderThemeMargin}" Visibility="Collapsed"/>
                  <Border x:Name="Background" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" Grid.Row="1"/>
                  <Rectangle x:Name="PressedBackground" Fill="{ThemeResource ComboBoxPressedHighlightThemeBrush}" Margin="{TemplateBinding BorderThickness}" Opacity="0" Grid.Row="1"/>
                  <Border x:Name="HighlightBackground" BorderBrush="{ThemeResource ComboBoxFocusedBorderThemeBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{ThemeResource ComboBoxFocusedBackgroundThemeBrush}" Grid.ColumnSpan="2" Opacity="0" Grid.Row="1"/>
                  <Rectangle x:Name="Highlight" Fill="{ThemeResource ComboBoxSelectedBackgroundThemeBrush}" Margin="{TemplateBinding BorderThickness}" Opacity="0" Grid.Row="1"/>
                  <ContentPresenter x:Name="ContentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Grid.Row="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                    <TextBlock x:Name="PlaceholderTextBlock" Foreground="{ThemeResource ComboBoxPlaceholderTextForegroundThemeBrush}" FontWeight="{ThemeResource ComboBoxPlaceholderTextThemeFontWeight}" Text="{TemplateBinding PlaceholderText}"/>
                  </ContentPresenter>
                  <TextBlock x:Name="DropDownGlyph" AutomationProperties.AccessibilityView="Raw" Grid.Column="1" Foreground="{ThemeResource ApplicationForegroundThemeBrush}" FontWeight="Bold" FontSize="{ThemeResource ComboBoxArrowThemeFontSize}" FontFamily="{ThemeResource SymbolThemeFontFamily}" HorizontalAlignment="Right" IsHitTestVisible="False" Margin="0,0,6,4" Grid.Row="1" Text="&#xE011;" VerticalAlignment="Center"/>
                  <Popup x:Name="Popup">
                    <Border x:Name="PopupBorder" BorderBrush="{ThemeResource ComboBoxPopupBorderThemeBrush}" BorderThickness="{ThemeResource ComboBoxPopupBorderThemeThickness}" Background="{ThemeResource ComboBoxPopupBackgroundThemeBrush}" HorizontalAlignment="Stretch">
                      <ScrollViewer x:Name="ScrollViewer" AutomationProperties.AccessibilityView="Raw" BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}" Foreground="{ThemeResource ComboBoxPopupForegroundThemeBrush}" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" MinWidth="{ThemeResource ComboBoxPopupThemeMinWidth}" VerticalSnapPointsType="OptionalSingle" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" VerticalSnapPointsAlignment="Near" ZoomMode="Disabled">
                        <ItemsPresenter/>
                      </ScrollViewer>
                    </Border>
                  </Popup>
                </Grid>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>
    
      </Application.Resources>
    
    </Application>
    

    App.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.ApplicationModel;
    using Windows.ApplicationModel.Activation;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    
    // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
    
    namespace App6
    {
      /// <summary>
      /// Provides application-specific behavior to supplement the default Application class.
      /// </summary>
      sealed partial class App : Application
      {
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
          this.InitializeComponent();
          this.Suspending += OnSuspending;
          this.UnhandledException += App_UnhandledException;
        }
    
        async void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
          var msgDlg = new Windows.UI.Popups.MessageDialog(e.Exception.Message);
          msgDlg.DefaultCommandIndex = 1;
          await msgDlg.ShowAsync();
    
          e.Handled = false;
        }
    
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
    
    #if DEBUG
          if (System.Diagnostics.Debugger.IsAttached)
          {
            this.DebugSettings.EnableFrameRateCounter = true;
          }
    #endif
    
          Frame rootFrame = Window.Current.Content as Frame;
    
          // Do not repeat app initialization when the Window already has content,
          // just ensure that the window is active
          if (rootFrame == null)
          {
            // Create a Frame to act as the navigation context and navigate to the first page
            rootFrame = new Frame();
            // Set the default language
            rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
    
            rootFrame.NavigationFailed += OnNavigationFailed;
    
            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
              //TODO: Load state from previously suspended application
            }
    
            // Place the frame in the current Window
            Window.Current.Content = rootFrame;
          }
    
          if (rootFrame.Content == null)
          {
            // When the navigation stack isn't restored navigate to the first page,
            // configuring the new page by passing required information as a navigation
            // parameter
            rootFrame.Navigate(typeof(MainPage), e.Arguments);
          }
          // Ensure the current window is active
          Window.Current.Activate();
        }
    
        /// <summary>
        /// Invoked when Navigation to a certain page fails
        /// </summary>
        /// <param name="sender">The Frame which failed navigation</param>
        /// <param name="e">Details about the navigation failure</param>
        void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
        {
          throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
        }
    
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private void OnSuspending(object sender, SuspendingEventArgs e)
        {
          var deferral = e.SuspendingOperation.GetDeferral();
          //TODO: Save application state and stop any background activity
          deferral.Complete();
        }
      }
    }
    

    Freitag, 31. Juli 2015 12:39
  • Hi Markus,
    mit diesen Programmauszügen kann ich leider nichts anfangen.

    --
    Viele Grüsse
    Peter Fleischer (MVP, Partner)
    Meine Homepage mit Tipps und Tricks

    Freitag, 31. Juli 2015 13:32
  • Hallo Peter,

    das erste von dir funktioniert. Hatte selbst hatte auch diese Ahnung. Hätte man gleich probieren müssen.
    Mit dem Dependency Property ging es so nicht.

    Habe die Folder Collection in eine Observable Collection und ein normales Property umgewandelt. Über INotifyPropertyChanged die Änderungs-Benachrichtigung weitergegeben. Und alle Ordner werden stets angezeigt.

    Es wird angezeigt und geht.

    Aber: Im Debug...

    In FileOpenPicker_Show_Async:

    Wenn ich Debug aufrufe wird der Aufruf von CustomObj_FolderList_Fill beim ersten oder zweiten Mal
    übersprungen. mfolderCurrent hat den aktuell gewählten Ordner. Aber die CustomObj_FolderList noch die Einträge es vorherigen Ordners...

    Es funktioniert in der Anzeige auf dem Bildschirm. Egal ob Debug oder ohne. Es bleiben Zweifel. Diese Windows Runtime und .Net. Vielleicht sollte man eher konservativ sein.



    • Bearbeitet Markus222 Samstag, 1. August 2015 09:39 Hatte korrigiert.
    Freitag, 31. Juli 2015 19:31
  • Bitte um Entschuldigung:

    Nicht in
    FileOpenPicker_Show_Async:

    sondern in
    FolderOpenButton_Click

    Freitag, 31. Juli 2015 19:44
  • Hi Markus,
    es ist bedenklich, wenn ein Programm ohne Haltepunkte läuft und mit Haltepunkten Probleme bereitet. Bei solch einem Verhalten kann man davon ausgehen, dass das Programm bei anderen Umgebungsbedingungen (CPU-Geschwindigkeit, mehr CPU-Kerne, intensive parallel laufende Anwendungen) auch Probleme bereiten kann.

    Gerade bei Nutzung asynchroner Abläufe ist es wichtig, dass die Folge der Beziehungen zwischen den threads vollständig "verriegelt" wird oder die threads vollständig unabhängig ablaufen. Dass das Programm ohne Haltepunkte funktioniert und mit Haltepunkten nicht, kann daran liegen, dass bei der Arbeit ohne Haltepunkte die CPU so belastet wird, dass parallele threads verzögert werden (im Millisekundenbereich). Diese Verzögerung (wenn auch nur sehr kurz) kann dazu führen, dass im anderen thread erst noch ein paar Zustände geschaffen werden, die dann im verzögerten thread zu anderen Abläufen führen. Mir scheint, dass nach Deiner Schilderung genau das bei Dir zutrifft.

    Auch aus diesen Gründen liebe ich MVVM. Mit der vollständigen Entkopplung der Logik von der Oberfläche kann man Detailabläufe übersichtlicher gestalten und auch testen.

    Nachtrag:

    In Deinem Code ist folgender Ablauf:

    - Aufruf der Methode FolderOpenButton_Click;
    - Aufruf der asynchronen Methode CustomObj_FolderList_Fill;
    - In CustomObj_FolderList_Fill wird mit "new Collection" die Liste erstellt;
    - In FolderOpenButton_Click wird auf die Collection zugegriffen.

    Wenn also die Methode CustomObj_FolderList_Fill nicht schnell genug die Instanz erstellt, bringt der Zugriff in der aufrufenden Methode eine NullReferenceException. Beim Setzen von Haltpunkten kann die Verzögerung dazu führen, dass die asynchrone Routine das Erzeugen der Instanz rechtzeitig schafft.


    --
    Viele Grüsse
    Peter Fleischer (MVP, Partner)
    Meine Homepage mit Tipps und Tricks



    Samstag, 1. August 2015 03:48
  • Hallo Peter,

    es bereitet keine Probleme. Es läuft so wie gewünscht. Nur Haltepunkte werden im Debug übersprungen. Es übersteigt meine Möglichkeiten den Grund dafür zu erfahren. Intern wird der Code jedenfalls ausgeführt sonst wäre das Ergebnis nicht da.

    Finde schade dass man es (scheinbar) nicht einfach halten kann mit den Dependency Properties und (weniger) Code in der Main Page selbst. Es wird stimmen sich auf das zu verlassen was du sagst.

    Die Alternative aus VB 6 Zeiten, die Combobox egal weg im Code zu füllen möchte ich nicht mehr.

    Grüße und schönes Wochenende,
    Markus

    Samstag, 1. August 2015 09:19
  • Hi Markus,
    ich habe Dein Programm mal von Ballast beseitigt und geringfügig geändert und es läuft wie gewollt, auch mit Haltepunkten (meine Umgebung: Windows 8.1, Visual Studio 2013 sp4).

    Auch in VB6-Zeiten konnte man eine Combobox binden. Sowohl RowSource als auch DataSource kann an ein Recordset gebunden werden.


    --
    Viele Grüsse
    Peter Fleischer (MVP, Partner)
    Meine Homepage mit Tipps und Tricks

    Samstag, 1. August 2015 14:17