WPF之MahApps.Metro下载和WPF学习经验
2024-08-31 23:47:30
这几天一直在学习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 = "确定" });
}
最后感谢大家花时间看。因为这是第一次写博客,希望大家多提意见。一起进步。。
最新文章
- js sql C#时间、时间戳相互转换
- hexo环境变量的配置问题
- Neo4j创建自动索引
- C++ 不能在类体外指定关键字static
- C# 从excel里面复制的1万6千多条记录粘贴到FCKeditor里面,点保存的时候,保存不了,页面没有反应
- Struts2学习笔记-jsp中引用struts2框架
- 第1章 UML基础:类的关系
- Count the Trees[HDU1131]
- PayPal 开发详解(三):在网站上创建【立即付款】按钮
- Python Scrapy安装杂症记录
- python手记(27)
- .Net Remoting 调用远程对象
- vector内存回收
- es6的正则扩展笔记之修饰符
- mybatis 常用
- Python学习笔记第二十七周(Bootstrap)
- linux系统下载pycharm
- CSS:Float
- 20155206 2016-2017-2 《Java程序设计》第7周学习总结
- Python学习笔记001——Linux