WP7备注(21)(ScrollViewer)

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<StackPanel Name="stackPanel" />
</ScrollViewer>
</Grid>

当横向数据过长时候,显示滚动条,没有过长,则不显示

using System;
using System.Collections.Generic;
namespace PublicClasses
{
class ClassAndChildren
{
public ClassAndChildren(Type parent)
{
Type = parent;
SubClasses = new List<ClassAndChildren>();
}
public Type Type { set; get; }
public List<ClassAndChildren> SubClasses { set; get; }
}
}
public partial class MainPage : PhoneApplicationPage
{
Brush accentBrush;
public MainPage()
{
InitializeComponent();
accentBrush = this.Resources["PhoneAccentBrush"] as Brush;
// Get all assemblies
List<Assembly> assemblies = new List<Assembly>();
assemblies.Add(Assembly.Load("System.Windows"));
assemblies.Add(Assembly.Load("Microsoft.Phone"));
assemblies.Add(Assembly.Load("Microsoft.Phone.Controls"));
assemblies.Add(Assembly.Load("Microsoft.Phone.Controls.Maps"));
// Set root object (use DependencyObject for shorter list)
Type typeRoot = typeof(object);
// Assemble total list of public classes
List<Type> classes = new List<Type>();
classes.Add(typeRoot);
foreach (Assembly assembly in assemblies)
foreach (Type type in assembly.GetTypes())
if (type.IsPublic && type.IsSubclassOf(typeRoot))
classes.Add(type);
// Sort those classes
classes.Sort(TypeCompare);
// Now put all those sorted classes into a tree structure
ClassAndChildren rootClass = new ClassAndChildren(typeRoot);
AddToTree(rootClass, classes);
// Display the tree
Display(rootClass, 0);
}
int TypeCompare(Type t1, Type t2)
{
return String.Compare(t1.Name, t2.Name);
}
// Recursive method
void AddToTree(ClassAndChildren parentClass, List<Type> classes)
{
foreach (Type type in classes)
{
if (type.BaseType == parentClass.Type)
{
ClassAndChildren subClass = new ClassAndChildren(type);
parentClass.SubClasses.Add(subClass);
AddToTree(subClass, classes);
}
}
}
// Recursive method
void Display(ClassAndChildren parentClass, int indent)
{
string str1 = String.Format("{0}{1}{2}{3}",
new string(' ', indent * 4),
parentClass.Type.Name,
parentClass.Type.IsAbstract ? " (abstract)" :
"",
parentClass.Type.IsSealed ? " (sealed)" : "");
string str2 = " " + parentClass.Type.Namespace;
TextBlock txtblk = new TextBlock();
txtblk.Inlines.Add(str1);
txtblk.Inlines.Add(new Run
{
Text = str2,
Foreground = accentBrush
});
stackPanel.Children.Add(txtblk);
foreach (ClassAndChildren child in parentClass.SubClasses)
Display(child, indent + 1);
}
}

image

原文地址:https://www.cnblogs.com/otomii/p/2032481.html