最近在试验用Silverlight做应用系统,效果如下:
XAML部分代码:
<controls:TreeView x:Name="tv" Margin="8,50,0,8" HorizontalAlignment="Left" Width="102" FontSize="13.333" Background="#FFFAFAFA">
<controls:TreeViewItem Header="日志" Selected="OnSelected" Tag="UcLog" >
</controls:TreeViewItem>
<controls:TreeViewItem Header="用户" Selected="OnSelected" Tag="UcUser">
</controls:TreeViewItem>
<controls:TreeViewItem Header="组" Selected="OnSelected" Tag="UcGroup">
</controls:TreeViewItem>
<controls:TreeViewItem Header="权限" Selected="OnSelected" Tag="UcPermission">
</controls:TreeViewItem>
<controls:TreeViewItem Header="应用程序" Selected="OnSelected" Tag="UcApplication">
</controls:TreeViewItem>
</controls:TreeView>
<controlsToolkit:DockPanel x:Name="dp" Margin="114,50,8,8"/>
<controls:TreeViewItem Header="日志" Selected="OnSelected" Tag="UcLog" >
</controls:TreeViewItem>
<controls:TreeViewItem Header="用户" Selected="OnSelected" Tag="UcUser">
</controls:TreeViewItem>
<controls:TreeViewItem Header="组" Selected="OnSelected" Tag="UcGroup">
</controls:TreeViewItem>
<controls:TreeViewItem Header="权限" Selected="OnSelected" Tag="UcPermission">
</controls:TreeViewItem>
<controls:TreeViewItem Header="应用程序" Selected="OnSelected" Tag="UcApplication">
</controls:TreeViewItem>
</controls:TreeView>
<controlsToolkit:DockPanel x:Name="dp" Margin="114,50,8,8"/>
TreeView的ItemsSource可以通过xml文件或WebService动态绑定
Selected事件都指向OnSelected方法,Tag为所要导航到的xaml页面名称
C#代码
private void OnSelected(object sender, RoutedEventArgs e)
{
TreeViewItem tvi=(TreeViewItem)sender;
if (tvi.Tag != null)
{
DockPanelAddChildren(dp, (tvi.Tag.ToString()));
}
}
void DockPanelAddChildren(DockPanel dp, string formname)
{
Assembly ass = Assembly.GetExecutingAssembly();
UIElement value = (UIElement)ass.CreateInstance("UGP_SilverlightApp." + formname);
dp.Children.Clear();
dp.Children.Add(value);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;
namespace UGP_SilverlightApp
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;
namespace UGP_SilverlightApp
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void OnSelected(object sender, RoutedEventArgs e)
{
TreeViewItem tvi=(TreeViewItem)sender;
if (tvi.Tag != null)
{
DockPanelAddChildren(dp, (tvi.Tag.ToString()));
}
}
void DockPanelAddChildren(DockPanel dp, string formname)
{
Assembly ass = Assembly.GetExecutingAssembly();
UIElement value = (UIElement)ass.CreateInstance("UGP_SilverlightApp." + formname);
dp.Children.Clear();
dp.Children.Add(value);
}