当前位置:   article > 正文

Material Design_materialdesign neget无法下载

materialdesign neget无法下载

Material Design

写毕设的过程中用到了Material Design这一C#库,在网上找了很多教程没发现很好的解决方法,在YouTube上看了个视频,还挺好的,就实操了一下,记录下来给后来的同学们参考。

  • 新建wpf项目
    wpfapp
    WpfAppMaterialDesign

  • 通过NuGet安装MaterialDesign
    选中项目后点击管理NuGet
    搜索material后安装

  • 安装后打开项目的GitHub地址
    https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit

建议下载代码压缩包方便本地预览效果,下面将讲述构建本地预览

下拉GitHub页面找到Getting Started,进入Super Quick Start
也可以访问网址http://materialdesigninxaml.net/ 找到GETTING STARTED

  • 构建本地预览效果,选中整个项目,重新生成解决方案
    解压缩下载包后进入文件夹
    选中项目
    重新生成解决方法
    成功后回到文件夹,参照下图路径找到本地exe文件
    文件路径
    效果
  • 回到第一步新建的WpfAppMaterialDesign项目中,从Material Design In XAMLGETTING STARTED中将相关代码复制到App.xaml中,如下图

小tip: Material Design In XAML的开始方法和GitHub仓库的开始方法不太一样,区别在于是否引入了命名空间

Resource
GitHub仓
复制到MainWindow.xaml的代码是配置整个窗口属性的。
MainWindow.xaml

  • 从本地预览效果复制需要的代码到项目中
    copy
  • 代码部分
    App.xaml
<Application x:Class="WpfAppMaterialDesign.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WpfAppMaterialDesign"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

MainWindow.xaml

<Window x:Class="WpfAppMaterialDesign.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:WpfAppMaterialDesign"
        mc:Ignorable="d"
        
        TextElement.Foreground="{DynamicResource MaterialDesignBody}"
        TextElement.FontWeight="Regular"
        TextElement.FontSize="13"
        TextOptions.TextFormattingMode="Ideal"
        TextOptions.TextRenderingMode="Auto"
        Background="{DynamicResource MaterialDesignPaper}"
        FontFamily="{DynamicResource MaterialDesignFont}"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button Style="{StaticResource MaterialDesignRaisedButton}" Width="100"
            ToolTip="Resource name: MaterialDesignRaisedButton"
            Content="Click me!"  Click="Button_Click"/>
    </Grid>
</Window>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfAppMaterialDesign
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Thank you for learning!", "Message", MessageBoxButton.OK, MessageBoxImage.Information);
        }
    }
}
  • 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
  • 程序运行效果:
    result
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/97775
推荐阅读
相关标签
  

闽ICP备14008679号