17WPF---UI库

1.MahApps(mahapps.com)

①通过Nuget安装:MahApps.Metro

 ②项目中引入

<Application x:Class="WPFUI库.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WPFUI库"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <!--原生控件:新的样式模板-->
        <!--扩展控件:自定义控件    cs/ControlTemplate-->
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
        <!-- Theme setting -->
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
    </Application.Resources>
</Application>

③使用

<Window x:Class="WPFUI库.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:WPFUI库"
        xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <!--<Style TargetType="Button">
            <Setter Property="Foreground" Value="Red"/>
        </Style>-->
    </Window.Resources>
    <Grid>
        <StackPanel>
            <Button Content="Button" Width="200" Height="30" Style="{x:Null}"/>
            <mah:MetroTabControl>
                <mah:MetroTabItem Header="AA" CloseButtonEnabled="True"/>
                <mah:MetroTabItem Header="AA"/>
                <mah:MetroTabItem Header="AA"/>
                <mah:MetroTabItem Header="AA"/>
            </mah:MetroTabControl>
            
            <mah:FlipView BannerText="Hello" IsBannerEnabled="False">
                <mah:FlipViewItem Height="100" Width="300">
                    <Border Background="Orange"/>
                </mah:FlipViewItem>
                <mah:FlipViewItem Height="100" Width="300">
                    <Border Background="Green"/>
                </mah:FlipViewItem>
            </mah:FlipView>
        </StackPanel>
    </Grid>
</Window>

④效果

 2.HandyControl(handyorg.gitee.io)

①Nuget引入

② 项目中引入

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

③应用

<hc:Window x:Class="WPFHandyControl.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:WPFHandyControl"
         xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
        xmlns:hc="https://handyorg.github.io/handycontrol"
        xmlns:sys="clr-namespace:System;assembly=System.Runtime"
        mc:Ignorable="d"
        Title="MainWindow" Height="800" Width="800">
    <Grid>
        <StackPanel>
            <Button Content="Burtton" Width="200" Style="{StaticResource ButtonDashedPrimary}"/>
            <ProgressBar Width="200" Height="30" Minimum="0" Maximum="100" Value="45"/>
            <Button Style="{StaticResource ButtonSuccess}" Content="这是一个按钮"/>
            <Button Style="{StaticResource ButtonSuccess}" Content="这是一个按钮" Margin="0,0,0,0" hc:BorderElement.CornerRadius="15"/>


            <Grid Margin="32">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <hc:NumericUpDown x:Name="UpDownGroups" HorizontalAlignment="Center" Value="2" Minimum="1" Maximum="3" Width="200" Style="{StaticResource NumericUpDownExtend}" hc:TitleElement.Title="列数" hc:TitleElement.TitleWidth="50" hc:TitleElement.TitlePlacement="Left"/>
                <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,16,0,0">
                    <hc:ScrollViewer MaxHeight="300">
                        <hc:WaterfallPanel VerticalAlignment="Center" Width="300" Groups="{Binding Value,ElementName=UpDownGroups}" hc:PanelElement.FluidMoveBehavior="{StaticResource BehaviorXY200}">
                            <Border Height="100" Background="{DynamicResource PrimaryBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
                                <TextBlock Text="A" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
                            </Border>
                            <Border Height="140" Background="{DynamicResource DangerBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
                                <TextBlock Text="B" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
                            </Border>
                            <Border Height="100" Background="{DynamicResource SuccessBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
                                <TextBlock Text="C" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
                            </Border>
                            <Border Height="170" Background="{DynamicResource InfoBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
                                <TextBlock Text="D" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
                            </Border>
                            <Border Height="100" Background="{DynamicResource WarningBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
                                <TextBlock Text="E" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
                            </Border>
                        </hc:WaterfallPanel>
                    </hc:ScrollViewer>
                    <hc:ScrollViewer Margin="32,0,0,0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" MaxWidth="300">
                        <hc:WaterfallPanel VerticalAlignment="Center" Height="300" Orientation="Vertical" Groups="{Binding Value,ElementName=UpDownGroups}" hc:PanelElement.FluidMoveBehavior="{StaticResource BehaviorXY200}">
                            <Border Width="100" Background="{DynamicResource PrimaryBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
                                <TextBlock Text="A" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
                            </Border>
                            <Border Width="140" Background="{DynamicResource DangerBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
                                <TextBlock Text="B" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
                            </Border>
                            <Border Width="100" Background="{DynamicResource SuccessBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
                                <TextBlock Text="C" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
                            </Border>
                            <Border Width="170" Background="{DynamicResource InfoBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
                                <TextBlock Text="D" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
                            </Border>
                            <Border Width="100" Background="{DynamicResource WarningBrush}" Effect="{StaticResource EffectShadow1}" Margin="5">
                                <TextBlock Text="E" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
                            </Border>
                        </hc:WaterfallPanel>
                    </hc:ScrollViewer>
                </StackPanel>
            </Grid>
        </StackPanel>
    </Grid>
</hc:Window>

 3.LiveCharts

①Nuget添加

 ②代码

<Window x:Class="WPFLiveCharts.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:WPFLiveCharts"
        xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.DataContext>
        <local:ViewModel/>
    </Window.DataContext>
    <Grid>
        <lvc:CartesianChart Zoom="Xy" DisableAnimations="False" Margin="10,1,-10,0" Grid.ColumnSpan="2">
            <lvc:CartesianChart.Series>
                <lvc:LineSeries Values="{Binding Values}"/>
                <lvc:ColumnSeries Values="{Binding Values2}"/>
            </lvc:CartesianChart.Series>
            <lvc:CartesianChart.AxisX>
                <lvc:Axis Title="时间" Labels="{Binding xLabel}" LabelsRotation="-45">
                    <lvc:Axis.Separator>
                        <lvc:Separator Step="1"/>
                    </lvc:Axis.Separator>
                </lvc:Axis>
            </lvc:CartesianChart.AxisX>
            <lvc:CartesianChart.AxisY>
                <lvc:Axis Title="温度" MinValue="-10" MaxValue="100">
                    <lvc:Axis.Separator>
                        <lvc:Separator Step="5"/>
                    </lvc:Axis.Separator>
                </lvc:Axis>
                <lvc:Axis Title="压力" MinValue="0" MaxValue="10" Position="RightTop" >
                    <lvc:Axis.Separator>
                        <lvc:Separator Step="1"/>
                    </lvc:Axis.Separator>
                </lvc:Axis>
            </lvc:CartesianChart.AxisY>

        </lvc:CartesianChart>
    </Grid>
</Window>
using LiveCharts;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPFLiveCharts
{
    internal class ViewModel
    {
        public ChartValues<double> Values { get; set; }
        public ChartValues<double> Values2 { get; set; }
        public ObservableCollection<string> xLabel { get; set; }


        public ViewModel()
        {
            Values=new ChartValues<double>();
            Values2 = new ChartValues<double>();
            xLabel =new ObservableCollection<string>();


            Task.Factory.StartNew(async () =>
            {
                Random random = new Random();
                while (true)
                {
                    await Task.Delay(200);
                    Values.Add(random.NextDouble()*10);
                    Values2.Add(random.NextDouble() * 10);
                    xLabel.Add(DateTime.Now.ToString("mm:ss")); 
                    if (Values.Count>50)
                    {
                        Values.RemoveAt(0);
                        xLabel.RemoveAt(0);
                        Values2.RemoveAt(0);
                    }
                }
            });
            
        }
    }
}

4.DataGrid

    <Window.Resources>
        <x:Array Type="sys:String" x:Key="datas">
            <sys:String>LUOZHIWEI</sys:String>
            <sys:String>LUOZHIWEI</sys:String>
            <sys:String>LUOZHIWEI</sys:String>
            <sys:String>LUOZHIWEI</sys:String>
            <sys:String>LUOZHIWEI</sys:String>
            <sys:String>LUOZHIWEI</sys:String>
            <sys:String>LUOZHIWEI</sys:String>
        </x:Array>
    </Window.Resources>
    <Grid>
        <DataGrid ItemsSource="{Binding Source={StaticResource datas}}" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Header="AA" Binding="{Binding [0]}"/>
                <DataGridTextColumn Header="BB" Binding="{Binding [1]}"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>

ModernUI(http://mui.codeplex.com/)是一个开源的WPF界面,利用该界面,我们可以创建很酷的应用程序。下面是ModernUI官方示例,你可以从官方网站直接下载源码运行,如果是.NET 4.0的话,记得要声明“NET4”预编译变量,否则无法编译通过。 这个界面框架是基于ModernUI来实现的,在该文我将分享所有的源码,并详细描述如何基于ModernUI来构造一个非常通用的、插件化的WPF开发框架。下载源码的同志,希望点击一下推荐。 本文将按照以下四点来介绍: (1)ModernUI简介; (2)构建通用界面框架的思路; (3)基于ModernUI和OSGi.NET的插件化界面框架实现原理及源码分析; (4)其它更有趣的东西~~。 要编写这样的WPF界面,我们需要在一个Window上声明菜单和Tab页面,下图是定义菜单的声明。 此外,每一个Tab风格页面,你也需要手动的为菜单创建这样的界面元素。 直接用这样的方式来使用ModernUI,显然不太适合团队协作性的并行开发,因为在一个团队的协作中,不同的人需要完成不同的功能,实现不同页面,每个人都需要来更改主界面。 我非常希望模块化的开发方法,因为这可以尽可能的复用现有资产,使程序员可以聚焦在自己关注的业务逻辑上,不需要关心UI的使用。下面,我将来描述基于ModernUI实现的一个通用界面框架,这个界面框架允许程序员在自己的业务模块中配置需要显示的界面元素。 通用界面框架实现思路: 我希望能够实现这样的通用界面框架: (1)程序员可以直接实现需要展现业务逻辑的界面,不需要关注如何使用ModernUI; (2)程序员可以通过简单的配置就可以将自己实现的业务逻辑页面显示在主界面中; (3)这个界面框架可以完全复用。 当我看到ModernUI这个界面时,我希望将应用程序做成模块化,每一个模块能够: (1)通过以下配置能够直接显示二级菜单。 (2)通过以下配置能够直接显示三级菜单。 这样做的好处是,开发插件的时候可以不需要关心界面框架插件;团队在协作开发应用的时候,可以独立开发并不需要修改主界面;团队成员的插件可以随时集成到这个主界面;当主界面无法满足我们的布局时或者用户需求无法满足时,可以直接替换主界面框架而不需要修改任何插件代码。 最终的效果如下,以下界面的几个菜单及点击菜单显示的内容由DemoPlugin插件、DemoPlugin2插件来提供。当插件框架加载更多插件时,界面上会出现更多的菜单;反之,当插件被卸载或者被停止时,则相应的菜单将消失掉。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值