WPF界面美化(整体作用到控件),一步步教你使用FirstFloor.ModernUI
生活随笔
收集整理的這篇文章主要介紹了
WPF界面美化(整体作用到控件),一步步教你使用FirstFloor.ModernUI
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
開發工具:VS2015
1、獲取相關DLL(通過NuGet或者GitHub上下載的源碼中獲得),并在項目中添加引用
FirstFloor.ModernUI.dll
Microsoft.Windows.Shell.dll
UIShell.OSGi(這個是我運行程序時報的錯誤"未能加載文件或程序集",然后在NuGet上下載得到的)
2、在.xaml文件中將MainWindow轉為Mui.ModernUIWindow
.xaml.cs文件中繼承Window改為繼承ModernWindow
<mui:ModernWindow x:Class="GFunctionCalculate.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:GFunctionCalculate"xmlns:mui="http://firstfloorsoftware.com/ModernUI"mc:Ignorable="d"Title="MainWindow" Height="600" Width="800" WindowState="Normal" WindowStartupLocation="CenterScreen" ContentSource="/page1.xaml"><mui:ModernWindow.MenuLinkGroups><mui:LinkGroup DisplayName="" ><mui:LinkGroup.Links><mui:Link DisplayName="選擇文件" Source="/page1.xaml"/><mui:Link DisplayName="數據列表" Source="/page2.xaml"/></mui:LinkGroup.Links></mui:LinkGroup></mui:ModernWindow.MenuLinkGroups> </mui:ModernWindow>?
using FirstFloor.ModernUI.Windows.Controls; using FirstFloor.ModernUI.Presentation;namespace GFunctionCalculate {/// <summary>/// MainWindow.xaml 的交互邏輯/// </summary>public partial class MainWindow : ModernWindow{public MainWindow(){InitializeComponent();}} }3、在App.xaml文件中添加樣式(不添加運行會是全黑的窗口)
<Application x:Class="GFunctionCalculate.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-namespace:GFunctionCalculate"StartupUri="MainWindow.xaml"><Application.Resources><ResourceDictionary><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" /><ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/></ResourceDictionary.MergedDictionaries><Color x:Key="AccentColor">#008A00</Color><!--添加背景圖片時使用--><!--<Rectangle x:Key="WindowBackgroundContent" x:Shared="false"><Rectangle.Fill><ImageBrush Opacity=".1" ImageSource="/Assets/background.Love.jpg" Stretch="UniformToFill" /></Rectangle.Fill></Rectangle>--></ResourceDictionary></Application.Resources> </Application>4、添加Page頁
MainWindow中:
<mui:ModernWindow x:Class="GFunctionCalculate.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:GFunctionCalculate"xmlns:mui="http://firstfloorsoftware.com/ModernUI"mc:Ignorable="d"Title="MainWindow" Height="600" Width="800" WindowState="Normal" WindowStartupLocation="CenterScreen" ContentSource="/page1.xaml"><mui:ModernWindow.MenuLinkGroups><mui:LinkGroup DisplayName="" ><mui:LinkGroup.Links><mui:Link DisplayName="數據列表" Source="/page1.xaml"/></mui:LinkGroup.Links></mui:LinkGroup></mui:ModernWindow.MenuLinkGroups> </mui:ModernWindow>新建UserControl,命名為page1
page1.xaml
<UserControl x:Class="GFunctionCalculate.page1"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:GFunctionCalculate"xmlns:mui="http://firstfloorsoftware.com/ModernUI"xmlns:core="clr-namespace:System;assembly=mscorlib"mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="800"><Grid><Grid.Resources><!--Create list of enumeration values--><ObjectDataProvider x:Key="myEnum" MethodName="GetValues" ObjectType="{x:Type core:Enum}"><ObjectDataProvider.MethodParameters><x:Type Type="local:OrderStatus"/></ObjectDataProvider.MethodParameters></ObjectDataProvider></Grid.Resources><DockPanel><TextBlock DockPanel.Dock="Top" Text="DATAGRID" Style="{StaticResource Heading2}" Margin="0,0,0,8" /><DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" ><DataGrid.Columns><mui:DataGridTextColumn Header="First Name" Binding="{Binding FirstName}"/><mui:DataGridTextColumn Header="Last Name" Binding="{Binding LastName}" /><mui:DataGridTextColumn Header="Email" Binding="{Binding Email}"/><mui:DataGridCheckBoxColumn Header="Member" Binding="{Binding IsMember}" /><mui:DataGridComboBoxColumn Header="Order Status" SelectedItemBinding="{Binding Status}" ItemsSource="{Binding Source={StaticResource myEnum}}" /></DataGrid.Columns></DataGrid></DockPanel></Grid> </UserControl>page1.xaml.cs
using System.Collections.ObjectModel; using System.Windows.Controls;namespace GFunctionCalculate {public enum OrderStatus { None, New, Processing, Shipped, Received };public class Customer{public string FirstName { get; set; }public string LastName { get; set; }public string Email { get; set; }public bool IsMember { get; set; }public OrderStatus Status { get; set; }}/// <summary>/// Interaction logic for ControlsStylesDataGrid.xaml/// </summary>public partial class page1 : UserControl{public page1(){InitializeComponent();ObservableCollection<Customer> custdata = GetData();//Bind the DataGrid to the customer dataDG1.DataContext = custdata;}private ObservableCollection<Customer> GetData(){var customers = new ObservableCollection<Customer>();customers.Add(new Customer { FirstName = "Orlando", LastName = "Gee", Email = "orlando0@adventure-works.com", IsMember = true, Status = OrderStatus.New });customers.Add(new Customer { FirstName = "Keith", LastName = "Harris", Email = "keith0@adventure-works.com", IsMember = true, Status = OrderStatus.Received });customers.Add(new Customer { FirstName = "Donna", LastName = "Carreras", Email = "donna0@adventure-works.com", IsMember = false, Status = OrderStatus.None });customers.Add(new Customer { FirstName = "Janet", LastName = "Gates", Email = "janet0@adventure-works.com", IsMember = true, Status = OrderStatus.Shipped });customers.Add(new Customer { FirstName = "Lucy", LastName = "Harrington", Email = "lucy0@adventure-works.com", IsMember = false, Status = OrderStatus.New });customers.Add(new Customer { FirstName = "Rosmarie", LastName = "Carroll", Email = "rosmarie0@adventure-works.com", IsMember = true, Status = OrderStatus.Processing });customers.Add(new Customer { FirstName = "Dominic", LastName = "Gash", Email = "dominic0@adventure-works.com", IsMember = true, Status = OrderStatus.Received });customers.Add(new Customer { FirstName = "Kathleen", LastName = "Garza", Email = "kathleen0@adventure-works.com", IsMember = false, Status = OrderStatus.None });customers.Add(new Customer { FirstName = "Katherine", LastName = "Harding", Email = "katherine0@adventure-works.com", IsMember = true, Status = OrderStatus.Shipped });customers.Add(new Customer { FirstName = "Johnny", LastName = "Caprio", Email = "johnny0@adventure-works.com", IsMember = false, Status = OrderStatus.Processing });return customers;}} }?運行結果:
謝謝觀看,有所幫助的話請點個贊"*★,°*:.☆( ̄▽ ̄)/$:*.°★* 。"
?
總結
以上是生活随笔為你收集整理的WPF界面美化(整体作用到控件),一步步教你使用FirstFloor.ModernUI的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python解压7z文件_如何读取用7z
- 下一篇: state-threads Netsca