最近写的一个玩具,WPF写出来的东西还是挺好看的


style.xaml

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CustomListBox"> <SolidColorBrush x:Key="StandardBoarderBrush" Color="#FF515151"></SolidColorBrush>
<SolidColorBrush x:Key="StandardBackgroundBrush" Color="#FF252526" />
<SolidColorBrush x:Key="HoverBorderBrush" Color="LightYellow" Opacity="0.4"/>
<SolidColorBrush x:Key="SelectedBackgroundBrush" Color="Gray" />
<SolidColorBrush x:Key="SelectedForegroundBrush" Color="White" />
<SolidColorBrush x:Key="ScrollBarLineButtonBrush" Color="#FF888D91"/>
<SolidColorBrush x:Key="ScrollBarLineButtonHoverBrush" Color="#FF1286A9"/>
<SolidColorBrush x:Key="ScrollBarThumbBrush" Color="#FF686868"/>
<SolidColorBrush x:Key="ScrollBarThumbHoverBrush" Color="#FFC8C8C8"/> <LinearGradientBrush x:Key="ListBoxBackgroundBrush" StartPoint="0,0" EndPoint="1,0.001">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF2F2F2F" Offset="0.0" />
<GradientStop Color="#FF2F2F2F" Offset="0.6" />
<GradientStop Color="#FF2F2F2F" Offset="1.2"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush> <LinearGradientBrush x:Key="StandardBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="#CCC" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush> <SolidColorBrush x:Key="GlyphBrush" Color="#444" />
<LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#BBB" Offset="0.0"/>
<GradientStop Color="#EEE" Offset="0.1"/>
<GradientStop Color="#EEE" Offset="0.9"/>
<GradientStop Color="#FFF" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush> <Style x:Key="ScrollBarLineUpButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="Focusable" Value="False"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Path HorizontalAlignment="Center" VerticalAlignment="Center"
Name="triangle" Fill="{StaticResource ScrollBarLineButtonBrush}"
Data="M 0 4 L 8 4 L 4 0 Z"/>
</Grid> <ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="triangle" Property="Fill"
Value="{StaticResource ScrollBarLineButtonHoverBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <Style x:Key="ScrollBarLineDownButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="Focusable" Value="False"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Path HorizontalAlignment="Center" VerticalAlignment="Center"
Name="triangle" Fill="{StaticResource ScrollBarLineButtonBrush}"
Data="M 0 0 L 8 0 L 4 4 Z"/>
</Grid> <ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="triangle" Property="Fill"
Value="{StaticResource ScrollBarLineButtonHoverBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <Style x:Key="ScrollBarThumbStyle" TargetType="{x:Type Thumb}">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Margin" Value="1,0,1,0" />
<Setter Property="Background" Value="{StaticResource StandardBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource StandardBorderBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Rectangle Name="thumb" Fill="{StaticResource ScrollBarThumbBrush}"></Rectangle>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="thumb" Property="Fill" Value="{StaticResource ScrollBarThumbHoverBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <Style x:Key="ScrollBarPageButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Border Background="Transparent" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
<Grid Background="#FF3E3E42">
<Grid.RowDefinitions>
<RowDefinition MaxHeight="18"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition MaxHeight="18"></RowDefinition>
</Grid.RowDefinitions> <RepeatButton Grid.Row="0" Height="18"
Style="{StaticResource ScrollBarLineUpButtonStyle}"
Command="ScrollBar.LineUpCommand">
</RepeatButton> <Track Name="PART_Track" Grid.Row="1"
IsDirectionReversed="True">
<Track.DecreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageUpCommand"
Style="{StaticResource ScrollBarPageButtonStyle}"></RepeatButton>
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumbStyle}"/>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Command="ScrollBar.PageDownCommand"
Style="{StaticResource ScrollBarPageButtonStyle}"></RepeatButton>
</Track.IncreaseRepeatButton>
</Track> <RepeatButton Grid.Row="2" Height="18"
Style="{StaticResource ScrollBarLineDownButtonStyle}"
Command="ScrollBar.LineDownCommand">
</RepeatButton>
</Grid>
</ControlTemplate> <ControlTemplate x:Key="ListBoxTemplate" TargetType="{x:Type ListBox}">
<Border Name="border"
Background="{StaticResource ListBoxBackgroundBrush}"
BorderBrush="{StaticResource StandardBoarderBrush}"
BorderThickness="2" CornerRadius="3">
<ScrollViewer Focusable="False">
<ItemsPresenter Margin="10"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
</ItemsPresenter>
</ScrollViewer>
</Border>
</ControlTemplate> <ControlTemplate x:Key="ListBoxItemTemplate" TargetType="{x:Type ListBoxItem}">
<Border Name="border"
CornerRadius="3"
Margin="1"
Padding="2"
SnapsToDevicePixels="True">
<ContentPresenter TextBlock.Foreground="White"
TextBlock.FontSize="{TemplateBinding FontSize}"
TextBlock.TextAlignment="Left"/>
</Border>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="ListBoxItem.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="FontSize" By="2" Duration="0:0:0.2"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger> <EventTrigger RoutedEvent="ListBoxItem.MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="FontSize" Duration="0:0:0.1"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger> <Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Background" Value="{StaticResource HoverBorderBrush}"/>
</Trigger> <Trigger Property="IsSelected" Value="True">
<Setter TargetName="border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate> <Style x:Key="ListboxStyle" TargetType="{x:Type ListBox}">
<Setter Property="Template" Value="{StaticResource ListBoxTemplate}"></Setter>
</Style> <Style x:Key="ListboxItemStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template" Value="{StaticResource ListBoxItemTemplate}"></Setter>
</Style> <Style TargetType="{x:Type ScrollBar}">
<Setter Property="SnapsToDevicePixels" Value="True"></Setter>
<Setter Property="OverridesDefaultStyle" Value="True"></Setter>
<Setter Property="Width" Value="18"></Setter>
<Setter Property="Height" Value="Auto"></Setter>
<Setter Property="Template" Value="{StaticResource VerticalScrollBar}"></Setter>
</Style> </ResourceDictionary>

MainWindow.xaml:

 <Window x:Class="CustomListBox.MainWindow"
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"
xmlns:local="clr-namespace:CustomListBox"
mc:Ignorable="d"
Title="VS_StyleListbox" Height="350" Width="275" Background="#FF5F5F5F"
MinHeight="350" MinWidth="275">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Style.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<ListBox Name="customListbox" Margin="5" Style="{StaticResource ListboxStyle}"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.CanContentScroll="False"
ScrollViewer.PanningMode="Both"
SelectionMode="Single">
<ListBox.Items>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">One</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Two</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Three</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Four</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Five</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Six</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Seven</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Eight</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Nine</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Ten</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">One</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Two</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Three</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Four</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Five</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Six</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Seven</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Eight</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Nine</ListBoxItem>
<ListBoxItem Style="{StaticResource ListboxItemStyle}" FontSize="13.5">Ten</ListBoxItem>
</ListBox.Items>
</ListBox>
</Grid>
</Window>

WPF制作的VS黑色风格的Listbox的更多相关文章

  1. QSS样式表之PS黑色风格+白色风格+淡蓝色风格(开源)

    用QUI皮肤生成器制作皮肤,基本上不超过一分钟就可以生成一套自己想要的皮肤,只要设置八种颜色即可.本人非常喜欢这套黑色风格样式皮肤,特意分享出来,下载地址:https://download.csdn. ...

  2. WPF制作的小时钟

    原文:WPF制作的小时钟 周末无事, 看到WEB QQ上的小时钟挺可爱的, 于是寻思着用WPF模仿着做一个. 先看下WEB QQ的图: 打开VS, 开始动工. 建立好项目后, 面对一个空荡荡的页面, ...

  3. WPF制作的小型笔记本

    WPF制作的小型笔记本-仿有道云笔记 楼主所在的公司不允许下载外部资源, 不允许私自安装应用程序, 平时记录东西都是用记事本,时间久了很难找到以前记的东西. 平时在家都用有道笔记, 因此就模仿着做了一 ...

  4. WPF制作表示透明区域的马赛克画刷

    最近在用WPF制作一款软件,需要像ps一样表示透明区域,于是制作了一个马赛克背景的style.实现比较简单,那么过程和思路就不表了,直接上代码 <DrawingBrush TileMode=&q ...

  5. [Swift通天遁地]一、超级工具-(19)制作六种别具风格的动作表单

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. WPF制作Logo,很爽,今后在应用程序中加入Logo轻松,省事!

    原文:WPF制作Logo,很爽,今后在应用程序中加入Logo轻松,省事! 这是效果: XAML代码:<Viewbox Width="723.955078" Height=&q ...

  7. WPF制作的党旗

    原文:WPF制作的党旗 --------------------------------------------------------------------------------引用或转载时请保 ...

  8. WPF 调用API修改窗体风格实现真正的无边框窗体

    原文:WPF 调用API修改窗体风格实现真正的无边框窗体 WPF中设置无边框窗体似乎是要将WindowStyle设置为None,AllowTransparency=true,这样才能达到WinForm ...

  9. WPF 制作 Windows 屏保

    分享如何使用WPF 制作 Windows 屏保 WPF 制作 Windows 屏保 作者:驚鏵 原文链接:https://github.com/yanjinhuagood/ScreenSaver 框架 ...

随机推荐

  1. 常用jQuery 方法

    //强制给数字补全小数点 function toDecimal2(x) { var f = parseFloat(x); if(isNaN(f)) { return false; } var f = ...

  2. 解决win7系统重启后ip丢失问题,即每次电脑重启都要重新设置ip地址,重启后ip地址没了

    自己制作的Ghost盘上网有点问题,每次重启后电脑的ip地址被还原,要重新设置 百度后终于找解决办法,在此记录. 第一步:点击左下角的WIN图标,输入CMD然后回车,打开DOS模式窗口. 第二步:在D ...

  3. jQuery Mobile入门

    转:http://www.cnblogs.com/linjiqin/archive/2011/07/17/2108896.html 简介:jQuery Mobile框架可以轻松的帮助我们实现非常好看的 ...

  4. 神经网络与深度学习(3):Backpropagation算法

    本文总结自<Neural Networks and Deep Learning>第2章的部分内容. Backpropagation算法 Backpropagation核心解决的问题: ∂C ...

  5. synergy 使用记录

    synergy 是一个多台电脑之间,共享鼠标.键盘的开源工具,做的很赞.目前,这个工具对 Windows.Linux.MacOS 都有很好的支持. 手上 arm 板安装的是 debian 系统,所以, ...

  6. Zabbix客户端安装

    CentOS 7 [root@localhost /]# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-agent-3 ...

  7. centos手动编译安装apache、php、mysql

    64位centos 5.5手动安装lamp,要求curl.json.pdo_mysql.gd,记录如下. centos 5.4.5.5.5.6的内核都是2.6.18,都可以安装php 5.3. 卸载旧 ...

  8. synthesize的作用

    @synthesize是对属性的实现,实际上就是制定setter和getter操作的实例变量的名称   举个栗子: @synthesize array;  默认操作的实例变量和属性同名 @synthe ...

  9. 表单元素的submit()方法和onsubmit事件

    1.表单元素中出现了name="submit"的元素 2.elemForm.submit();不会触发表单的onsubmit事件 3.动态创建表单时遇到的问题 表单元素拥有subm ...

  10. easyui的datagrid form(表单)提交到后台转对象的时候中文出现乱码

    在web.xml中配置如下代码 <filter> <filter-name>characterEncodingFilter</filter-name> <fi ...