Silverlight自訂二級菜單。

來源:互聯網
上載者:User

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>

刪除這句代碼  就會正常顯示   目錄  1  2  3  4

 

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>

 

後台cs代碼

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>), typeof(TabDetail), 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), typeof(TabDetail), 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), typeof(TabDetail), new PropertyMetadata(default(Style)));        public Style TRootStyle        {            get { return (Style)GetValue(TRootStyleProperty); }            set { SetValue(TRootStyleProperty, value); }        }        //根目錄上面的字型樣式        public static readonly DependencyProperty TTabDetailTextProperty = DependencyProperty.Register("TTabDetailText", typeof(Style), typeof(TabDetail), 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>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.