silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight自定义二级菜单。大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

PS需要补充的一个问题  下面图片中出现的跟目录1  加载了2次  是之前上传的时候忘记LeftMenu.xaml里面的这句代码删除了 <uc:TabDetail TRootStyle="{Binding RootStyle,ElementName=LeftMenuUC}" TTabDetailText="{Binding LeftMenuText,ElementName=LeftMenuUC}"

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

效果

Silverlight自定义二级菜单。

控件的XAML代码

<UserControl x:Class="ERPSilverlightDemo.TabDetail"
    xmlns="http://scheR_941_11845@as.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://scheR_941_11845@as.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://scheR_941_11845@as.microsoft.com/expression/blend/2008"
    xmlns:mc="http://scheR_941_11845@as.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>),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>

大佬总结

以上是大佬教程为你收集整理的Silverlight自定义二级菜单。全部内容,希望文章能够帮你解决Silverlight自定义二级菜单。所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。