技术开发 频道

WPF 模拟Windows 7 气象组件

  制作WPF 程序

  重新编译WRUC 后得到新的WeatherReaderMVC.dll,有了它接下来的工作就简单了。新建项目将DLL 加入其中。在MainWindow.xaml 中加入WeatherReaderMVC 命名空间,在通过WindowStyle、Background、AllowsTransparency、ResizeMode 将WPF 设置为透明、无边框、不可修改尺寸的窗口模式。如下代码通过 添加上面刚刚修改好的WRUC 控件,由于边框被取消所以添加<Image>控件用来关闭应用程序。

          查看其它地区天气情况,到了晚上太阳图标也会变化。

 制作WPF 程序


          由于WRUC 使用的是Windows 7 气象组件的图像资源,所以从外观上看两者大致相同。

 制作WPF 程序 制作WPF 程序

<Window x:Class="WpfWeatherReporter.MainWindow"
        xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:w
="clr-namespace:WeatherReaderMVC;assembly=WeatherReaderMVC"
        Title
="MainWindow" Height="250" Width="300" WindowStyle="None"
        Background
="Transparent" AllowsTransparency="True" ResizeMode="NoResize"
        Icon
="/WpfWeatherReporter;component/Images/Sunny.ico"         WindowStartupLocation="CenterScreen">
    
<Grid>
        
<w:WeatherReaderUI MouseLeftButtonDown="WeatherReaderUI_MouseLeftButtonDown" />
        
<Image Source="/WpfWeatherReporter;component/Images/Close.png"                MouseLeftButtonDown="Image_MouseLeftButtonDown"
               Width
="19" Height="19" Margin="253,63,7,132" ToolTip="Close" />
    
</Grid>
</Window>

 制作WPF 程序

      WeatherReaderUI_MouseLeftButtonDown 和Image_MouseLeftButtonDown 事件分别用于移动窗口和关闭窗口。

private void WeatherReaderUI_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    this.DragMove();
}

private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    this.Close();
}

     至此,所有的工作已完成, 下图为程序运行后的初始和迷你界面。 

制作WPF 程序  制作WPF 程序


 

 

0
相关文章