最近看了下wpf,感觉wpf做界面实在是太方便,使用blend来设计界面简直不要太爽。通过mvvm模式来实现逻辑界面分离。我这里使用的是vs2013, .netFramework4.5.程序只是实现了很简单的功能:歌曲播放,歌词搜索,歌词显示 ,更换皮肤,textbox的水印文字。 下面请看主界面整体效果:
其实很简陋,主要是图片的效果掩人耳目了。 下面就谈谈具体的制作过程,同时也算是自己对wpf的一个回忆总结吧。
(1) 程序最基本的一般当然是control了。 那么首先就是Button按钮了。Button 一般有3个状态, 默认,悬浮,按下。 方法有很多,我这里的做法是:
① 从Button派生一个类 ImageButton。
public class ImageButton : Button
{
public ImageSource NorImage
{
get { return (ImageSource)GetValue(NorImageProperty); }
set { SetValue(NorImageProperty, value); }
}
// Using a DependencyProperty as the backing store for NorImage. This enables animation, styling, binding, etc...
public static readonly DependencyProperty NorImageProperty =
DependencyProperty.Register("NorImage", typeof(ImageSource), typeof(ImageButton));
public ImageSource HorImage
{
get { return (ImageSource)GetValue(HorImageProperty); }
set { SetValue(HorImageProperty, value); }
}
// Using a DependencyProperty as the backing store for HorImage. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HorImageProperty =
DependencyProperty.Register("HorImage", typeof(ImageSource), typeof(ImageButton));
public ImageSource DownImage
{
get { return (ImageSource)GetValue(DownImageProperty); }
set { SetValue(DownImageProperty, value); }
}
// Using a DependencyProperty as the backing store for DownImage. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DownImageProperty =
DependencyProperty.Register("DownImage", typeof(ImageSource), typeof(ImageButton));
}
② 然后定义But