大佬教程收集整理的这篇文章主要介绍了Silverlight一级菜单导航(纯XAML脚本方式实现),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这个是自己东拼西凑然后各种借鉴混合而成的一个一级菜单导航,本来之前做一个一级导航很简单的,但是老板必须得用纯XAML语言写,就有点悲剧了,也就是说所有的事件神马的都是在XAML里面搞定,最郁闷的是Silverlight没有triggers属性。。。然后找啊找啊找啊找啊,找了N多资料,终于搞定了,激动了,
选中和鼠标移动上去的样式一样的,具体样式可以根据自己去修改
下面是代码
<!--ListBoxItemStyle--> <Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem"> <Setter Property="cursor" Value="Hand"/> <Setter Property="Foreground" Value="White"/> <Setter Property="FontSize" Value="16"/> <Setter Property="Padding" Value="3"/> <Setter Property="Margin" Value="20,0"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="BACkground" Value="Transparent"/> <Setter Property="TabNavigation" Value="Local"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Grid BACkground="{TemplateBinding BACkgrounD}"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"/> <VisualState x:Name="MouSEOver"> <Storyboard> <DoubleAnimation Duration="0" To=".75" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor3"/> </Storyboard> </VisualState> <VisualState x:Name="Disabled"> <Storyboard> <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="SELEctionStates"> <VisualState x:Name="UnSELEcted"/> <VisualState x:Name="SELEcted"> <Storyboard> <DoubleAnimation Duration="0" To=".75" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor2"/> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="FocusStates"> <VisualState x:Name="Focused"/> <VisualState x:Name="Unfocused"/> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Rectangle x:Name="fillColor" Width="75" Height="25" RadiusX="5" RadiusY="5" stroke="Black"> <Rectangle.Fill> <LinearGradientBrush StartPoint="1,0"> <GradientStop Color="#BD5E54" Offset="0.0"/> <GradientStop Color="#90322A" Offset="0.9"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Rectangle x:Name="fillColor2" Width="75" Height="25" RadiusX="5" RadiusY="5" IsHitTestVisible="false" Opacity="0" stroke="#5E1A14"> <Rectangle.Fill> <LinearGradientBrush StartPoint="1,0"> <GradientStop Color="#5C5C5C" Offset="0.0"/> <GradientStop Color="#969595" Offset="0.8"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Rectangle x:Name="fillColor3" Width="75" Height="25" RadiusX="5" RadiusY="5" IsHitTestVisible="false" Opacity="0" stroke="#5E1A14"> <Rectangle.Fill> <LinearGradientBrush StartPoint="1,0"> <GradientStop Color="#5C5C5C" Offset="0.0"/> <GradientStop Color="#969595" Offset="0.8"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplatE}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
然后调用
其中List是一个集合,我给写在了资源文件里面,然后DIsplay和SELEcted是list集合对象里面的属性
<ListBox ItemsSouth={Staticresource list} SELEctionChanged="lbNavigate_SELEctionChanged" x:Name="lbNavigate" DisplaymemberPath = "SysModuleMTR.Modulename" SELEctedValuePath = "SysPromissions" BACkground="Transparent" BorderBrush="Transparent" ItemContainerStyle="{Staticresource ListBoxItemStylE}" Height="35" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal"></VirtualizingStackPanel> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox>
以上是大佬教程为你收集整理的Silverlight一级菜单导航(纯XAML脚本方式实现)全部内容,希望文章能够帮你解决Silverlight一级菜单导航(纯XAML脚本方式实现)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。