我希望每个透视图项目都是隔离存储中的一个目录,然后将每个文件名加载到一个列表框中我发现它很混乱,你们可以帮助我吗?
目前它只是在一个支点和一个枢轴中显示对于我的应用程序,用户实际上可以创建一个pivot 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 :(得分:1)
为每个目录创建一个透视图项目,如果你可以为它创建一个类更好,名称说“DirectoyItem”,它有名称和文件集合(称为< strong>文件)该目录中的名称。
为了获得更好的模块性和清晰度,请为页面创建一个Viewmodel,其中集合(最优选的是ObservableColelction)为“DirectoryItem”。将此集合称为目录
公共类ViewModel { ObservableCollection目录= new ObservableColelction();
// call LoadFromLocalStorage() and add items to this Directories list
}
public class DirectoryItem:INotifyPropertyChanged { string _name;
ObservableCollection<string> Files;
public DirectoryItem()
{
_name = null;
Files = new ObservableCollection<string>();
}
//write public set and get for Name field.
//notify whenever property changes
}
将此集合项绑定到PivotControl项。 你可以这样做,如下
在页面构造函数
中设置datacontextpublic MyPage()
{
//Initializa components
this.DataContext = new ViewModel();
}
通过执行此操作,您将创建一个页面,该页面具有数据透视控件,其项目是独立存储的目录,每个数据透视表项目都包含该特定目录中文件的名称。