(精华)2020年01月26日 WPF课程管理系统项目实战(平台布局-资源字典的使用)

举报
愚公搬代码 发表于 2021/10/20 00:08:13 2021/10/20
【摘要】 1.以图标为例 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ...

1.以图标为例

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Zhaoxi.CourseManagement.Assets.Styes">

    <Style TargetType="Button" x:Key="WindowControlButtonStyle">
        <Setter Property="Width" Value="40"/>
        <Setter Property="Height" Value="30"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border Background="Transparent" Name="back">
                        <TextBlock Text="{Binding Content,RelativeSource={RelativeSource AncestorType=Button,Mode=FindAncestor}}"
                       VerticalAlignment="Center" HorizontalAlignment="Center"
                       FontFamily="../Fonts/#iconfont" FontSize="16"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="back" Property="Background" Value="#22FFFFFF"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="back" Property="Background" Value="#44FFFFFF"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

2.使用定义的图标(本地和引用资源合并)

<Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Assets/Styles/DefaultStyle.xaml"/>
                <ResourceDictionary>
                    <converter:GenderConverter x:Key="genderConverter"/>

                    <Style TargetType="RadioButton" x:Key="NavButtonStyle">
                        <Setter Property="Foreground" Value="White"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="RadioButton">
                                    <Border Background="Transparent" CornerRadius="8" Name="back">
                                        <ContentControl Content="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="20,4" FontSize="13"/>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsChecked" Value="True">
                                            <Setter TargetName="back" Property="Background" Value="#44FFFFFF"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>

                    <SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
                    <SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
                    <SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
                    <ControlTemplate TargetType="{x:Type TextBox}" x:Key="SearchTextBoxTemplate">
                        <Border x:Name="border" BorderThickness="0" Background="#22000000" SnapsToDevicePixels="True"
                        CornerRadius="10">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="30"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="&#xe600;" FontFamily="../Assets/Fonts/#iconfont" VerticalAlignment="Center"
                                   HorizontalAlignment="Center" Foreground="#44FFFFFF" FontSize="15"/>
                                <TextBlock Text="Search for what you like..." Grid.Column="1" VerticalAlignment="Center" 
                                   Foreground="#44FFFFFF" Name="mt" Visibility="Collapsed"/>
                                <ScrollViewer x:Name="PART_ContentHost" Grid.Column="1" Focusable="false" HorizontalScrollBarVisibility="Hidden"
                                  VerticalScrollBarVisibility="Hidden"
                                      VerticalAlignment="Center"
                                  Background="Transparent"/>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Opacity" TargetName="border" Value="0.56"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
                            </Trigger>
                            <Trigger Property="IsKeyboardFocused" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/>
                            </Trigger>
                            <DataTrigger Binding="{Binding Text,RelativeSource={RelativeSource Mode=Self}}" Value="">
                                <Setter TargetName="mt" Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>

                    <Storyboard x:Key="UserInfoStoryboard">
                        <DoubleAnimation Duration="0:0:0.2" To="0"
                                         Storyboard.TargetName="tt"
                                         Storyboard.TargetProperty="X"/>
                    </Storyboard>
                    <Storyboard x:Key="CloseUserInfoStoryboard">
                        <DoubleAnimation Duration="0:0:0.1"
                                         Storyboard.TargetName="tt"
                                         Storyboard.TargetProperty="X"/>
                    </Storyboard>

                    <ControlTemplate TargetType="RadioButton" x:Key="GenderRadioButtonTemplate">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Border Width="14" Height="14" CornerRadius="7" BorderThickness="1" BorderBrush="#007DFA" 
                                    Background="White" Margin="5,0" VerticalAlignment="Center">
                                <Border Width="8" Height="8" CornerRadius="4" Background="#007DFA"
                                        Name="point" Visibility="Collapsed"/>
                            </Border>
                            <ContentControl Content="{TemplateBinding Content}" VerticalAlignment="Center"
                                            Grid.Column="1"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Visibility" Value="Visible" TargetName="point"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97

文章来源: codeboy.blog.csdn.net,作者:愚公搬代码,版权归原作者所有,如需转载,请联系作者。

原文链接:codeboy.blog.csdn.net/article/details/112760052

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。