MaterialDesignXamlToolkit

MaterialDesignXamlToolkit(Version 4.0.0)

一、Installing the Toolkit

安装MaterialDesignThemes

可以在NuGet中搜索安装:

在这里插入图片描述

官方地址和Demo:GitHub - MaterialDesignInXAML/MaterialDesignInXamlToolkit: Google’s Material Design in XAML & WPF, for C# & VB.Net.

二、Configuring your App.xaml

和任何其他XAML库一样,都需要通过App.xaml导入才能正常使用,首先需要导入控件的所有默认样式,无论选择三种样式中的哪一种,这都是必需的。

<prism:PrismApplication
    x:Class="PrismBlankAppCore.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:PrismBlankAppCore"
    xmlns:prism="http://prismlibrary.com/">
    <Application.Resources>
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
    </Application.Resources>
</prism:PrismApplication>

接下来,需要选择一个颜色主题。最简单的选择是使用bunledtheme资源字典提供的内置主题之一。

<prism:PrismApplication
    x:Class="PrismBlankAppCore.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:PrismBlankAppCore"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns:prism="http://prismlibrary.com/">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <materialDesign:BundledTheme
                    BaseTheme="Light"
                    PrimaryColor="DeepPurple"
                    SecondaryColor="Lime" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</prism:PrismApplication>

如果喜欢为主题自定义颜色,那么可以使用CustomColorTheme:

<prism:PrismApplication
    x:Class="PrismBlankAppCore.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:PrismBlankAppCore"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns:prism="http://prismlibrary.com/">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <materialDesign:CustomColorTheme
                    BaseTheme="Dark"
                    PrimaryColor="Gray"
                    SecondaryColor="Gray" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</prism:PrismApplication>

三、Configuring your Windows

<Window [...]
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        TextElement.Foreground="{DynamicResource MaterialDesignBody}"
        Background="{DynamicResource MaterialDesignPaper}"
        TextElement.FontWeight="Medium"
        TextElement.FontSize="14"
        FontFamily="{materialDesign:MaterialDesignFont}"
        [...] >

四、示例

<Window
    x:Class="PrismBlankAppCore.Views.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns:prism="http://prismlibrary.com/"
    Title="{Binding Title}"
    Background="{DynamicResource MaterialDesignPaper}"
    FontFamily="{materialDesign:MaterialDesignFont}"
    TextElement.FontSize="14"
    TextElement.FontWeight="Medium"
    TextElement.Foreground="{DynamicResource MaterialDesignBody}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <StackPanel
            Grid.Row="0"
            Margin="10"
            Orientation="Horizontal">
            <Button
                Width="100"
                Height="30"
                Margin="40,0,40,0"
                Command="{Binding NavigationCmd}"
                CommandParameter="ViewA"
                Style="{StaticResource MaterialDesignOutlinedButton}">
                <materialDesign:PackIcon Kind="Connection" />
            </Button>

            <Button
                Width="100"
                Height="30"
                Margin="40,0,40,0"
                Command="{Binding NavigationCmd}"
                CommandParameter="ViewB"
                Style="{StaticResource MaterialDesignFlatButton}">
                <materialDesign:PackIcon Kind="Connection" />
            </Button>

            <Button
                Width="100"
                Height="30"
                Margin="40,0,40,0"
                Command="{Binding OpenDialogCmd}"
                Content="OpenDialog" />
        </StackPanel>

        <StackPanel
            Grid.Row="1"
            Margin="10"
            Orientation="Horizontal">
            <StackPanel Margin="2" Orientation="Horizontal">
                <RadioButton
                    Margin="4"
                    Content="FIRST"
                    IsChecked="True"
                    Style="{StaticResource MaterialDesignTabRadioButton}" />
                <RadioButton
                    Margin="4"
                    Content="SECOND"
                    IsChecked="False"
                    Style="{StaticResource MaterialDesignTabRadioButton}" />
                <RadioButton
                    Margin="4"
                    Content="THIRD"
                    IsChecked="False"
                    IsEnabled="True"
                    Style="{StaticResource MaterialDesignTabRadioButton}" />
            </StackPanel>

            <materialDesign:ColorZone Mode="PrimaryMid">
                <StackPanel Margin="2" Orientation="Vertical">
                    <RadioButton
                        Margin="4"
                        Content="FIRST"
                        IsChecked="True"
                        Style="{StaticResource MaterialDesignTabRadioButton}" />
                    <RadioButton
                        Margin="4"
                        Content="SECOND"
                        IsChecked="False"
                        Style="{StaticResource MaterialDesignTabRadioButton}" />
                    <RadioButton
                        Margin="4"
                        Content="THIRD"
                        IsChecked="False"
                        IsEnabled="False"
                        Style="{StaticResource MaterialDesignTabRadioButton}" />
                </StackPanel>
            </materialDesign:ColorZone>
        </StackPanel>

        <StackPanel
            Grid.Row="2"
            Margin="10"
            Orientation="Horizontal">
            <!--  the following based on https://material.io/guidelines/components/buttons.html#buttons-toggle-buttons  -->
            <ListBox SelectedIndex="0" Style="{StaticResource MaterialDesignToolToggleListBox}">
                <ListBoxItem Content="{materialDesign:PackIcon Kind=FormatAlignLeft}" />
                <ListBoxItem Content="{materialDesign:PackIcon Kind=FormatAlignCenter}" />
                <ListBoxItem Content="{materialDesign:PackIcon Kind=FormatAlignRight}" />
                <ListBoxItem Content="{materialDesign:PackIcon Kind=FormatAlignJustify}" />
            </ListBox>

            <ListBox SelectedIndex="0" Style="{StaticResource MaterialDesignToolVerticalToggleListBox}">
                <ListBoxItem Content="{materialDesign:PackIcon Kind=FormatAlignLeft}" />
                <ListBoxItem Content="{materialDesign:PackIcon Kind=FormatAlignCenter}" />
                <ListBoxItem Content="{materialDesign:PackIcon Kind=FormatAlignRight}" />
                <ListBoxItem Content="{materialDesign:PackIcon Kind=FormatAlignJustify}" />
            </ListBox>
        </StackPanel>

        <StackPanel
            Grid.Row="3"
            Margin="10"
            Orientation="Horizontal">
            <ProgressBar
                IsIndeterminate="True"
                Style="{StaticResource MaterialDesignCircularProgressBar}"
                Value="35" />
            <ProgressBar
                Width="200"
                Margin="10"
                IsIndeterminate="True" />
        </StackPanel>

        <StackPanel
            Grid.Row="4"
            Margin="10"
            Orientation="Horizontal">
            <ComboBox
                MinWidth="128"
                materialDesign:ColorZoneAssist.Mode="Inverted"
                materialDesign:HintAssist.HelperText="Select one OS"
                materialDesign:HintAssist.Hint="OS"
                materialDesign:TextFieldAssist.HasClearButton="True"
                materialDesign:TextFieldAssist.SuffixText="sw"
                materialDesign:TextFieldAssist.UnderlineBrush="{DynamicResource SecondaryHueMidBrush}"
                Style="{StaticResource MaterialDesignFloatingHintComboBox}">
                <ComboBoxItem Content="Android" />
                <ComboBoxItem Content="iOS" />
                <ComboBoxItem Content="Linux" />
                <ComboBoxItem Content="Windows" />
            </ComboBox>

            <ComboBox
                Width="256"
                materialDesign:HintAssist.Hint="Validation test"
                materialDesign:TextFieldAssist.HasClearButton="True"
                ItemsSource="{Binding ShortStringList}"
                Style="{StaticResource MaterialDesignOutlinedComboBox}">
                <ComboBox.SelectedItem>
                    <Binding
                        Mode="TwoWay"
                        Path="SelectedValidationOutlined"
                        UpdateSourceTrigger="PropertyChanged" />
                </ComboBox.SelectedItem>
            </ComboBox>
        </StackPanel>
    </Grid>
</Window>

在这里插入图片描述

            <ToggleButton Width="100">
                <ToggleButton.Style>
                    <Style BasedOn="{StaticResource MaterialDesignOutlinedButton}" TargetType="ToggleButton">
                        <Style.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Content">
                                    <Setter.Value>
                                        <materialDesign:PackIcon
                                            Width="auto"
                                            Height="auto"
                                            Kind="LanDisconnect" />
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="Foreground" Value="{StaticResource MaterialDesignDarkForeground}"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="False">
                                <Setter Property="Content">
                                    <Setter.Value>
                                        <materialDesign:PackIcon
                                            Width="auto"
                                            Height="auto"
                                            Kind="LanConnect" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ToggleButton.Style>
            </ToggleButton>

在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值