我有一个列表框,可以通过以下代码打开和查看哪些项目...
private void AccountsList_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
var listBoxItem = AccountsList.ItemContainerGenerator.ContainerFromIndex(AccountsList.SelectedIndex) as ListBoxItem;
var txtBlk = FindVisualChildByType<TextBlock>(listBoxItem, "txtBlkAccountName");
xCa = txtBlk.Text;
NavigationService.Navigate(new Uri(string.Format("/ViewAccount.xaml?parameter={0}&action={1}", a.ToString(), "View"), UriKind.Relative));
}
&
T FindVisualChildByType<T>(DependencyObject element, String name) where T : class
{
if (element is T && (element as FrameworkElement).Name == name)
{
return element as T;
}
int childcount = VisualTreeHelper.GetChildrenCount(element);
for (int i = 0; i < childcount; i++)
{
T childElement = FindVisualChildByType<T>(VisualTreeHelper.GetChild(element, i), name);
if (childElement != null)
{
return childElement;
}
}
return null;
}
现在我正在实现 longlistselector 而不是列表框。长列表选择器显示数据库中的所有项目,但我在打开此列表中的项目时遇到问题...我无法在此 longlistselector 中使用 SelectedIndex 请帮助...