2012-02-01 45 views
2

我希望每个数据透视条目都是独立存储中的一个目录,然后将每个文件名称加载到一个列表框中我觉得它很混乱,你们可以帮我吗?将轴心项目作为独立存储中的目录

目前,它的所有只显示在我的应用程序的一个关键点&,用户实际上可以创建枢轴aka目录。

是否有可能创建一个代码的方式,我可以加载基于pivotitem名称的目录,然后加载该目录中的所有项目?

谢谢>。 <

public partial class View2 : PhoneApplicationPage 
    { 
     public String selected; 

     public View2() 
     { 

      InitializeComponent(); 
      LoadFromLocalStorage(); 

     } 



     private void LoadFromLocalStorage() 
     { 
      try 
       { 
      using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) 
      { 

        //string[] fileNames = store.GetFileNames(); 

        string[] fileNames = store.GetFileNames("./general/*.*"); 
        var files = new ObservableCollection<string>(); 


        foreach (string s in fileNames) 
        { 
         files.Add(s); 
        } 
        lbFiles.ItemsSource = files; 
       } 
      } 
       catch 
       { 
        MessageBox.Show("Capture an image first!"); 

       } 

     } 



     private static string _first; 

     public string First 
     { 
      get 
      { 
       return _first; 
      } 
     } 

     private void lbFiles_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
     { 
      selected = lbFiles.SelectedItem.ToString(); 
      general item = new general(); 
      item.viewimage(selected); 
      MessageBox.Show(selected); 
      _first = selected; 
      NavigationService.Navigate(new Uri("/View.xaml", UriKind.Relative)); 
     } 





    } 
+0

是的,这是可能的。你希望我们写代码吗? – 2012-02-01 10:30:26

回答

1

对于每个目录创建一个支点项目,它的更好,如果你可以为同一个,名称创建一个类说“DirectoyItem”其名称和文件的(称其为集合文件)该目录中的名称。

  1. 为了更好的模块性和清晰度创建一个视图模型对于具有“DirectoryItem”的集(ObservableColelction是最优选的)的页面。呼叫这个集合作为目录

    公共类视图模型 { 的ObservableCollection目录=新ObservableColelction();

    // call LoadFromLocalStorage() and add items to this Directories list 
    

    }

    公共类DirectoryItem:INotifyPropertyChanged的 { 串_name;

    ObservableCollection<string> Files; 
    
    public DirectoryItem() 
    { 
        _name = null; 
        Files = new ObservableCollection<string>(); 
    } 
    
    //write public set and get for Name field. 
    
    //notify whenever property changes 
    

    }

  2. 绑定此藏品的PivotControl项目。 你可以这样做,如下

设置DataContext的索姆ething像这样的页面构造

public MyPage() 
{ 
    //Initializa components 
    this.DataContext = new ViewModel(); 
} 
  1. 最后应用的推出,为IsolatedStorage的每个目录中DirectoryItems的收藏(文件)创建DirectoryItem和商店。

通过这样做,您将创建一个具有枢轴控件的页面,其中的项目是独立存储的目录,每个枢轴项目都具有该特定目录中文件的名称。

相关问题