这几天一直在学习WPF的东西。刚开始以为和Winform一样.拖拽控件来进行布局。结果远远没有那么简单。很多东西都需要自己写。包括样式。今天给大家分享一个 MahApps.Metro.

首先在NuGet程序包里搜索MahApps.Metro然后下载。当然说到这里。有些大家在搜索NuGET的时候等待时间过长,搜索不到之类的。以及一些有关方面的一个博客。我好多东西都是从他的博客总结。

链接:http://www.wxzzz.com/

当然我自己写个很逗比的东西,是才接触WPF做的。有兴趣的或者才开始学的可以看下。至于大神级别的希望可以指点下。

<controls:MetroWindow x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="测试按钮" Height="" Width="">
<controls:MetroWindow.RightWindowCommands>
<controls:WindowCommands>
<Button Content="settings" />
<Button Content="设置" />
</controls:WindowCommands>
</controls:MetroWindow.RightWindowCommands> <Grid>
<Rectangle Height="" Stroke="White" Fill="SkyBlue"></Rectangle>
<Button Content="点击逐渐增长" Height="" HorizontalAlignment="Left" Margin="29,37,0,0" Name="btnGrowAdd" VerticalAlignment="Top" Width="" Click="btnGrowAdd_Click" />
<Button Content="点击逐渐归位" Height="" HorizontalAlignment="Left" Margin="29,87,0,0" Name="btnBack" VerticalAlignment="Top" Width="" Click="btnBack_Click" /> <StackPanel Grid.Row="" Grid.Column="" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="20,0,0,0">
<Border Width="" Height="" RenderTransformOrigin="0.391,0.424">
<Border.Background>
<ImageBrush ImageSource="/images/绿色输入框.png"/>
</Border.Background>
<TextBox x:Name="Phone" Style="{DynamicResource InPutTextBox}" Width="" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Phone}" Margin="38,21,9,20" Height=""/>
</Border>
</StackPanel>
<Button Height="" HorizontalAlignment="Left" Margin="99,207,0,0" Name="btnGrow" VerticalAlignment="Top" Width="" Click="btnGrow_Click" >
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border Name="ThisBorder" Cursor="Hand" CornerRadius="" BorderThickness="">
<Border.Background>
<ImageBrush ImageSource="/images/普通按钮.png"/>
</Border.Background>
<Border VerticalAlignment="Center" HorizontalAlignment="Center"> <Label FontFamily="微软雅黑" FontSize="" Foreground="White" Content="点击增长" VerticalAlignment="Bottom" HorizontalAlignment="Center"/> </Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="ThisBorder" Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/images/普通按钮按下.png"/>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template> </Button> <Button Content="弹出" Height="" HorizontalAlignment="Left" Name="btndc" VerticalAlignment="Top" Width="" Click="btndc_Click" Margin="99,279,0,0">
<Button.Background>
<ImageBrush ImageSource="/images/普通按钮.png"/>
</Button.Background> </Button>
<Button Content="SS" Height="" HorizontalAlignment="Left" x:Name="btnss" VerticalAlignment="Top" Width="" Margin="223,278,0,0" Click="btnss_Click">
<Button.Background>
<ImageBrush ImageSource="images/普通按钮.png"/>
</Button.Background> </Button>
<Button Content="小球" Height="" HorizontalAlignment="Left" x:Name="xiuqiu" VerticalAlignment="Top" Width="" Margin="99,243,0,0" Click="xiuqiu_Click">
<Button.Background>
<ImageBrush ImageSource="images/普通按钮.png"/>
</Button.Background> </Button> </Grid>
</controls:MetroWindow>

这个是 wpf窗体的程序,这里面用过MahApps.Metro部分的。其中要把默认的Window  改为controls:MetroWindow。后台的 window 也改为MetroWindow

附上后台代码。只是为了测试几个按钮的效果。

public MainWindow()
{
InitializeComponent();
btnGrowAdd.Click += new RoutedEventHandler(btnGrowAdd_Click);
btnBack.Click += new RoutedEventHandler(btnBack_Click);
btnGrow.Click += new RoutedEventHandler(btnGrow_Click);
} //点击增长
private void btnGrow_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation widthAnimation = new DoubleAnimation() { By = , Duration = TimeSpan.FromSeconds(0.2) };
btnGrow.BeginAnimation(Button.WidthProperty, widthAnimation);
Phone.Text += ;
} private void btnGrowAdd_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation widthAnimation = new DoubleAnimation()
{
To = this.Width - ,
Duration = TimeSpan.FromSeconds()
};
DoubleAnimation heightAnimation = new DoubleAnimation()
{
To = (this.Height - ) / ,
Duration = TimeSpan.FromSeconds()
};
btnGrowAdd.BeginAnimation(Button.WidthProperty, widthAnimation);
btnGrowAdd.BeginAnimation(Button.HeightProperty, heightAnimation);
} private void btnBack_Click(object sender, RoutedEventArgs e)
{ DoubleAnimation widthAmination = new DoubleAnimation();
widthAmination.Duration = TimeSpan.FromSeconds();
DoubleAnimation heightAmimation = new DoubleAnimation();
heightAmimation.Duration = TimeSpan.FromSeconds();
btnGrow.BeginAnimation(Button.WidthProperty, widthAmination);
btnGrow.BeginAnimation(Button.HeightProperty, widthAmination);
btnGrowAdd.BeginAnimation(Button.WidthProperty, widthAmination);
btnGrowAdd.BeginAnimation(Button.HeightProperty, heightAmimation);
Phone.Text = "";
} private void btndc_Click(object sender, RoutedEventArgs e)
{
this.ShowMessageAsync("标题", "内容", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "确定" });
}

最后感谢大家花时间看。因为这是第一次写博客,希望大家多提意见。一起进步。。

最新文章

  1. js sql C#时间、时间戳相互转换
  2. hexo环境变量的配置问题
  3. Neo4j创建自动索引
  4. C++ 不能在类体外指定关键字static
  5. C# 从excel里面复制的1万6千多条记录粘贴到FCKeditor里面,点保存的时候,保存不了,页面没有反应
  6. Struts2学习笔记-jsp中引用struts2框架
  7. 第1章 UML基础:类的关系
  8. Count the Trees[HDU1131]
  9. PayPal 开发详解(三):在网站上创建【立即付款】按钮
  10. Python Scrapy安装杂症记录
  11. python手记(27)
  12. .Net Remoting 调用远程对象
  13. vector内存回收
  14. es6的正则扩展笔记之修饰符
  15. mybatis 常用
  16. Python学习笔记第二十七周(Bootstrap)
  17. linux系统下载pycharm
  18. CSS:Float
  19. 20155206 2016-2017-2 《Java程序设计》第7周学习总结
  20. Python学习笔记001——Linux

热门文章

  1. 避免if语句的深层次嵌套
  2. [CSS] Get up and running with CSS Grid Layout
  3. Innodb单表数据物理恢复
  4. Weblogic中可以使用的脚本
  5. [Redux] Important things in Redux
  6. 【t073】&&【t015】魔法物品
  7. Live Unit Testing
  8. git 本地分支关联远程分支
  9. 理解 iOS 和 macOS 的内存管理
  10. c语言学习笔记(9)——指针