PS需要补充的一个问题 下面图片中出现的跟目录1 加载了2次 是之前上传的时候忘记LeftMenu.xaml里面的这句代码删除了
<uc:TabDetail TRootStyle="{Binding RootStyle,ElementName=LeftMenuUC}" TTabDetailText="{Binding LeftMenuText,ElementName=LeftMenuUC}" TRootName="{Binding RootName,ElementName=LeftMenuUC}" TIResource="{Binding IResource,ElementName=LeftMenuUC}" TItemActualHeight="{Binding ItemActualHeight,ElementName=LeftMenuUC}"></uc:TabDetail>
DEMO下载
http://download.csdn.net/detail/qq873113580/4934434
效果图
控件的XAML代码
<UserControl x:Class="ERPSilverlightDemo.TabDetail" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" DataContext="{Binding RelativeSource={RelativeSource Self}}" d:DesignHeight="300" d:DesignWidth="400"> <UserControl.Resources> <!--上下的动画--> <Storyboard x:Name="TListBoxIn"> <DoubleAnimation Storyboard.TargetName="TListBox" Storyboard.TargetProperty="Height" Duration="00:00:00.50" To="0"/> </Storyboard> <Storyboard x:Name="TListBoxOut"> <DoubleAnimation Storyboard.TargetName="TListBox" Storyboard.TargetProperty="Height" Duration="00:00:00.50" To="{Binding TItemActualHeight}"/> </Storyboard> </UserControl.Resources> <Grid x:Name="LayoutRoot" Width="200"> <StackPanel> <!--根目录--> <Grid Style="{Binding TRootStyle}" Tag="0" MouseLeftButtonDown="Grid_MouseLeftButtonDown"> <TextBlock x:Name="root" Text="{Binding TRootName}" Style="{Binding TTabDetailText}"/> </Grid> <!--左边显示部分的头条--> <ListBox x:Name="TListBox" Height="0" ItemsSource="{Binding TIResource}" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderBrush="Transparent"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Name}" Style="{StaticResource LeftMenuTextDetail}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel> </Grid> </UserControl>
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 ERPSilverlightDemo.Entities; using System.Collections; namespace ERPSilverlightDemo { public partial class TabDetail : UserControl { public TabDetail() { InitializeComponent(); } //根目录的名字 public static readonly DependencyProperty TRootNameProperty = DependencyProperty.Register("TRootName",typeof(string),typeof(TabDetail),new PropertyMetadata(default(string))); public string TRootName { get { return (string)GetValue(TRootNameProperty); } set { SetValue(TRootNameProperty,value); } } //定义ListBox的数据源 public static readonly DependencyProperty TIResourceProperty = DependencyProperty.Register("TIResource",typeof(IList<NavigateDetail>),new PropertyMetadata(default(IList<NavigateDetail>))); public IList<NavigateDetail> TIResource { get { return (IList<NavigateDetail>)GetValue(TIResourceProperty); } set { SetValue(TIResourceProperty,value); } } //定义Grid的高 public static readonly DependencyProperty TItemActualHeightProperty = DependencyProperty.Register("TItemActualHeight",typeof(double),new PropertyMetadata(default(double))); public double TItemActualHeight { get { return (double)GetValue(TItemActualHeightProperty); } set { SetValue(TItemActualHeightProperty,value*TIResource.Count+5); } } //根目录的样式 public static readonly DependencyProperty TRootStyleProperty = DependencyProperty.Register("TRootStyle",typeof(Style),new PropertyMetadata(default(Style))); public Style TRootStyle { get { return (Style)GetValue(TRootStyleProperty); } set { SetValue(TRootStyleProperty,value); } } //根目录上面的字体样式 public static readonly DependencyProperty TTabDetailTextProperty = DependencyProperty.Register("TTabDetailText",new PropertyMetadata(default(Style))); public Style TTabDetailText { get { return (Style)GetValue(TTabDetailTextProperty); } set { SetValue(TTabDetailTextProperty,value); } } private void Grid_MouseLeftButtonDown(object sender,MouseButtonEventArgs e) { Grid grid = sender as Grid; this.TListBox.Selectedindex = -1; if (grid != null) { if (grid.Tag.ToString() == "0") { this.TListBoxOut.Begin(); grid.Tag = "1"; } else { this.TListBoxIn.Begin(); grid.Tag = "0"; } } } } }
在其他地方调用的时候
<uc:LeftMenu x:Name="LeftMenu" Grid.Column="0" AllResource="{StaticResource DList}" ItemActualHeight="25" RootStyle="{StaticResource LeftMenuStyle}" LeftMenuBg="{StaticResource LeftMenuBg}" LeftMenuText="{StaticResource LeftMenuText}"></uc:LeftMenu>
相关的样式
<Style x:Key="LeftMenuStyle" targettype="Grid"> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush StartPoint="1,0"> <GradientStop Color="#838181" Offset="0.0"/> <GradientStop Color="Black" Offset="1.8"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Height" Value="30"/> </Style>
<Style x:Key="LeftMenuBg" targettype="StackPanel"> <Setter Property="Background" Value="#5A5858"/> </Style>
<Style x:Key="LeftMenuText" targettype="TextBlock"> <Setter Property="Foreground" Value="White"/> <Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="Margin" Value="10,0"/> <Setter Property="FontWeight" Value="Bold"/> <Setter Property="FontSize" Value="18"/> <Setter Property="Cursor" Value="Hand"/> </Style>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。