C# Note18: about dialog(关于对话框)

前言

基本上任何software或application都会在help菜单中,有着一个关于对话框,介绍产品的版权、版本等信息,还有就是对第三方的引用(add author credits)。

首先,看下常用软件的关于对话框:

言归正传,进入正题,介绍下我在进行这部分开发时的三种方法:

由于用到了很多需要credit的icons,几种方法主要的区别便在于如何显示这些icons,并加上作者信息。

(1)使用ListView显示,并制作DataTemplate模板

MainWindow.xaml

<Window x:Class="AboutApplicationTest.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:AboutApplicationTest"
        mc:Ignorable="d"
        Title="XXXXX Application" Height="460" Width="580" Icon="/images/about.png">
    <Window.Resources>
        <DataTemplate x:Key="MyTemplate" DataType="{x:Type local:IconInfo}">
            <Label Height="30" Width="500">
                <Label.Content>
                    <DockPanel>
                        <Image Source="{Binding Icon}" DockPanel.Dock="Left" Width="20" Height="20"/>
                        <TextBlock Text=" Icon made by " DockPanel.Dock="Left" Margin="10,0,0,0"/>
                        <TextBlock DockPanel.Dock="Left">
                                <Hyperlink NavigateUri="{Binding Url}" Name="linkHelp" ToolTip="Author Credits" Click="linkHelp_Click_1">
                                    <Hyperlink.Inlines>
                                        <Run Text="{Binding Author}"/>
                                    </Hyperlink.Inlines>
                                </Hyperlink>
                        </TextBlock>
                        <TextBlock Text="from www.flaticon.com" DockPanel.Dock="Left" Margin="5,0,0,0"/>
                    </DockPanel>
                </Label.Content>
            </Label>
        </DataTemplate>
    </Window.Resources>
    <Grid Background="LightGray">
        <Grid Margin="0,0,0,0" VerticalAlignment="Top" Width="580" Height="440" HorizontalAlignment="Left" Background="LightGray">
            <Image Source="/Images/user.png" Width="60" Height="60" HorizontalAlignment="Left" Margin="50,10,0,0" VerticalAlignment="Top"/>
            <Label Content="XXXXX Application" FontWeight="Bold" FontSize="16" HorizontalAlignment="Left" Margin="160,10,0,0" VerticalAlignment="Top"></Label>
            <Label Content="Copyright ? 2017 by XXXXXX Corporation. All Rights Reserved." HorizontalAlignment="Left" Margin="160,40,0,0" VerticalAlignment="Top"></Label>
            <GroupBox BorderBrush="DarkGreen"  Header="Product Information:" HorizontalAlignment="Left" Height="60" Margin="50,80,0,0" VerticalAlignment="Top" Width="460">
                <Label Name="pbc_version" Content="" HorizontalAlignment="Left" Margin="135,5,0,0" VerticalAlignment="Top"/>
            </GroupBox>

            <Label Content="Included third parties:" HorizontalAlignment="Left" Margin="10,150,0,0" VerticalAlignment="Top"></Label>
            <ListView x:Name="lvIconInfo" ItemTemplate="{StaticResource  MyTemplate}"  Height="180" Width="545" Margin="10,175,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <Label Name="WarningInfo" Content="Warning:" HorizontalAlignment="Left" Margin="5,360,0,0" VerticalAlignment="Top" Width="555"></Label>
        </Grid>
    </Grid>
</Window>

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AboutApplicationTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private ObservableCollection<IconInfo> iconInfoList;
        public MainWindow()
        {
            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;

            InitializeComponent();

            WarningInfo.Content += " This computer program is protected by copyright law and international treaties. Unauthoized"
            + "\n" + "reproduction or distribution of this program, or any portion of it, may result in severe civil and criminal"
            + "\n" + "penalties, and will be prosecuted to the maximum extent possible under the law.";

            pbc_version.Content = "Version:     " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); //利用反射的方式获取assembly的version信息

            iconInfoList = new ObservableCollection<IconInfo>();

            iconInfoList.Add(new IconInfo("/Images/user.png", "https://www.flaticon.com/authors/chanut-is-industries", "Chanut is Industries"));
            iconInfoList.Add(new IconInfo("/Images/password.png", "https://www.flaticon.com/authors/freepik", "Freepik"));
            iconInfoList.Add(new IconInfo("/Images/user.png", "https://www.flaticon.com/authors/chanut-is-industries", "Chanut is Industries"));
            iconInfoList.Add(new IconInfo("/Images/password.png", "https://www.flaticon.com/authors/freepik", "Freepik"));
            iconInfoList.Add(new IconInfo("/Images/user.png", "https://www.flaticon.com/authors/chanut-is-industries", "Chanut is Industries"));
            iconInfoList.Add(new IconInfo("/Images/password.png", "https://www.flaticon.com/authors/freepik", "Freepik"));
            iconInfoList.Add(new IconInfo("/Images/user.png", "https://www.flaticon.com/authors/chanut-is-industries", "Chanut is Industries"));
            iconInfoList.Add(new IconInfo("/Images/password.png", "https://www.flaticon.com/authors/freepik", "Freepik"));

            this.lvIconInfo.ItemsSource = iconInfoList;
        }

        private void linkHelp_Click_1(object sender, RoutedEventArgs e)
        {
            //Hyperlink link = sender as Hyperlink;
            //Process.Start(new ProcessStartInfo(link.NavigateUri.AbsoluteUri));
            if (sender.GetType() != typeof(Hyperlink))
                return;
            string link = ((Hyperlink)sender).NavigateUri.ToString();
            Process.Start(link);
        }
    }

    public class IconInfo
    {
        private string icon;
        private string url;
        private string author;

        public IconInfo(string icon, string url, string author)
        {
            this.icon = icon;
            this.url = url;
            this.author = author;
        }

        public string Icon
        {
            get
            {
                return this.icon;
            }
            set
            {
                this.icon = value;
            }
        }

        public string Url
        {
            get
            {
                return this.url;
            }
            set
            {
                this.url = value;
            }
        }

        public string Author
        {
            get
            {
                return this.author;
            }
            set
            {
                this.author = value;
            }
        }
    }
}

运行效果图:

(2)使用StackPanel包裹Label控件,然后外加滚动条

部分代码:  

<Grid Background="LightGray">
        <Grid Margin="0,0,0,0" VerticalAlignment="Top" Width="580" Height="440" HorizontalAlignment="Left" Background="LightGray">
            <Image Source="/Images/pbc_icon.png" Width="120" Height="50" HorizontalAlignment="Left" Margin="30,10,0,0" VerticalAlignment="Top"/>
            <Label Content="XXXXX Application" FontWeight="Bold" FontSize="16" HorizontalAlignment="Left" Margin="160,10,0,0" VerticalAlignment="Top"></Label>
            <Label Content="Copyright ? 2017 by XXXXXX Corporation. All Rights Reserved." HorizontalAlignment="Left" Margin="160,40,0,0" VerticalAlignment="Top"></Label>
            <GroupBox BorderBrush="DarkGreen"  Header="Product Information:" HorizontalAlignment="Left" Height="60" Margin="50,80,0,0" VerticalAlignment="Top" Width="460">
                <Label Name="XXX_version" Content="" HorizontalAlignment="Left" Margin="135,5,0,0" VerticalAlignment="Top"/>
            </GroupBox>

            <Label Content="Included third parties:" HorizontalAlignment="Left" Margin="10,150,0,0" VerticalAlignment="Top"></Label>
            <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Height="180" Margin="10,175,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
                <StackPanel Background="White" Width="535">
                    <Label Height="30" Width="535">
                        <Label.Content>
                            <DockPanel>
                                <Image Source="/Images/user.png" DockPanel.Dock="Left" Width="20" Height="20"/>
                                <TextBlock Text=" Icon made by " DockPanel.Dock="Left" Margin="10,0,0,0"/>
                                <TextBlock DockPanel.Dock="Left">
                                <Hyperlink NavigateUri="https://www.flaticon.com/authors/chanut-is-industries" Name="linkHelp" Click="linkHelp_Click">Chanut is Industries
                                </Hyperlink>
                                </TextBlock>
                                <TextBlock Text="from www.flaticon.com" DockPanel.Dock="Left" Margin="5,0,0,0"/>
                            </DockPanel>
                        </Label.Content>
                    </Label>
                    <Label Height="30" Width="535">
                        <Label.Content>
                            <DockPanel>
                                <Image Source="/Images/password.png" DockPanel.Dock="Left" Width="20" Height="20"/>
                                <TextBlock Text=" Icon made by " DockPanel.Dock="Left" Margin="10,0,0,0"/>
                                <TextBlock DockPanel.Dock="Left">
                                <Hyperlink NavigateUri="https://www.flaticon.com/authors/freepik" Name="linkHelp1" Click="linkHelp_Click">Freepik
                                </Hyperlink>
                                </TextBlock>
                                <TextBlock Text="from www.flaticon.com" DockPanel.Dock="Left" Margin="5,0,0,0"/>
                            </DockPanel>
                        </Label.Content>
                    </Label>
                    <Label Height="30" Width="535">
                        <Label.Content>
                            <DockPanel>
                                <Image Source="/Images/verifyPassword.png" DockPanel.Dock="Left" Width="20" Height="20"/>
                                <TextBlock Text=" Icon made by " DockPanel.Dock="Left" Margin="10,0,0,0"/>
                                <TextBlock DockPanel.Dock="Left">
                                <Hyperlink NavigateUri="https://www.flaticon.com/authors/freepik" Name="linkHelp2" Click="linkHelp_Click">Freepik
                                </Hyperlink>
                                </TextBlock>
                                <TextBlock Text="from www.flaticon.com" DockPanel.Dock="Left" Margin="5,0,0,0"/>
                            </DockPanel>
                        </Label.Content>
                    </Label>
                    <Label Height="30" Width="535">
                        <Label.Content>
                            <DockPanel>
                                <Image Source="/Images/description.png" DockPanel.Dock="Left" Width="20" Height="20"/>
                                <TextBlock Text=" Icon made by " DockPanel.Dock="Left" Margin="10,0,0,0"/>
                                <TextBlock DockPanel.Dock="Left">
                                <Hyperlink NavigateUri="https://www.flaticon.com/authors/Picol" Name="linkHelp3" Click="linkHelp_Click">Picol
                                </Hyperlink>
                                </TextBlock>
                                <TextBlock Text="from www.flaticon.com" DockPanel.Dock="Left" Margin="5,0,0,0"/>
                            </DockPanel>
                        </Label.Content>
                    </Label>
                    <Label Height="30" Width="535">
                        <Label.Content>
                            <DockPanel>
                                <Image Source="/Images/role.png" DockPanel.Dock="Left" Width="20" Height="20"/>
                                <TextBlock Text=" Icon made by " DockPanel.Dock="Left" Margin="10,0,0,0"/>
                                <TextBlock DockPanel.Dock="Left">
                                <Hyperlink NavigateUri="https://www.flaticon.com/authors/Vectors-Market" Name="linkHelp4" Click="linkHelp_Click">Vectors Market
                                </Hyperlink>
                                </TextBlock>
                                <TextBlock Text="from www.flaticon.com" DockPanel.Dock="Left" Margin="5,0,0,0"/>
                            </DockPanel>
                        </Label.Content>
                    </Label>
                    <Label Height="30" Width="535">
                        <Label.Content>
                            <DockPanel>
                                <Image Source="/Images/error.png" DockPanel.Dock="Left" Width="20" Height="20"/>
                                <TextBlock Text=" Icon made by " DockPanel.Dock="Left" Margin="10,0,0,0"/>
                                <TextBlock DockPanel.Dock="Left">
                                <Hyperlink NavigateUri="https://www.flaticon.com/authors/Pixel-Buddha" Name="linkHelp5" Click="linkHelp_Click">Pixel Buddha
                                </Hyperlink>
                                </TextBlock>
                                <TextBlock Text="from www.flaticon.com" DockPanel.Dock="Left" Margin="5,0,0,0"/>
                            </DockPanel>
                        </Label.Content>
                    </Label>
                    <Label Height="30" Width="535">
                        <Label.Content>
                            <DockPanel>
                                <Image Source="/Images/alarm.png" DockPanel.Dock="Left" Width="20" Height="20"/>
                                <TextBlock Text=" Icon made by " DockPanel.Dock="Left" Margin="10,0,0,0"/>
                                <TextBlock DockPanel.Dock="Left">
                                <Hyperlink NavigateUri="https://www.flaticon.com/authors/freepik" Name="linkHelp6" Click="linkHelp_Click">Freepik
                                </Hyperlink>
                                </TextBlock>
                                <TextBlock Text="from www.flaticon.com" DockPanel.Dock="Left" Margin="5,0,0,0"/>
                            </DockPanel>
                        </Label.Content>
                    </Label>
                </StackPanel>
            </ScrollViewer>
            <Label Name="WarningInfo" Content="Warning:" HorizontalAlignment="Left" Margin="5,360,0,0" VerticalAlignment="Top" Width="555"></Label>
        </Grid>
    </Grid>

(3)在第一种方法的基础上,不用hardcode的方式,而是增加一个xml配置文件,从中读取icons的credit数据。 

  

时间: 2024-11-10 01:06:22

C# Note18: about dialog(关于对话框)的相关文章

wxPython Modal Dialog模式对话框,Python对话框中打开对话框

今天用wxPython写一个输入关键词自动生成文章工具,设置部分需要用模式对话框来打开设置界面.下面介绍wxPython Modal Dialog模式对话框: 1. Modal Dialog(模式对话框) A modal dialog blocks other widgets from receiving user events until it is closed; in other words, it places the user in dialog mode for the durati

EasyUI 中点击取消按钮关闭Dialog(对话框窗口)

1.在取消按钮里的function中通过id找到这个对话框所在的层, 2.点出这个对话框,然后在括号了写入关闭的方法 <div id="dl1" class="easyui-dialog" title="窗口" style="width:400px;height: 200px" data-options=" toolbar:[ { text:'添加', iconCls:'icon-add', handler:f

用jquery-ui的dialog做对话框

js文件: <script src="plugins/jqueryui/jqueryui/jquery-1.9.1.js" type="text/javascript"></script> <link rel="stylesheet" href="plugins/jqueryui/themes/base/jquery.ui.all.css"/> <script src="pl

Dialog(对话框窗口)

创建dialog方式 一: <div id="dd" class="easyui-dialog" title="My Dialog" style="width:400px;height:200px;"> Dialog Content. </div> 这里为什么加了class="easyui-dialog"就会出现想要的效果,不加就是一个div,因为除了css样式的缘故,主要是pars

Android Dialog触摸对话框外部让其消失的实现方法

方法一: [java] view plaincopy @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (!(event.getX() >= -10 && event.getY() >= -10) || event.getX() >= calendarLayout.getWidth() + 10

用dialog在前台实现一个简单的UI对话框

<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>对话框部件(Dialog Widget)演示</title> <link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.m

Android 对话框 Dialog

对话框 Dialog 什么是对话框 对话框是在当前的页面之上弹出的小窗口, 用于显示一些重要的提示信息, 提示用户的输入,确认信息, 或显示某种状态.如 :  显示进度条对话框, 退出提示. 对话框的特点: 1, 当前界面弹出的小窗口. 2, 用户要与它进行交互, 可以接收用户输入的信息, 也可以反馈信息给用户. 常用对话框: 1, 普通对话框 AlertDialog 2, 进度条对话框  ProgressDialog 3, 日期对话框    DatePickerDialog 4, 时间对话框

转 Android 对话框(Dialog)大全 建立你自己的对话框

Activities提供了一种方便管理的创建.保存.回复的对话框机制,例如 onCreateDialog(int), onPrepareDialog(int, Dialog), showDialog(int), dismissDialog(int)等方法,如果使用这些方法的话,Activity将通过getOwnerActivity()方法返回该Activity管理的对话框(dialog). onCreateDialog(int):当你使用这个回调函数时,Android系统会有效的设置这个 Act

Android 对话框(Dialog)大全 建立你自己的对话框

Activities提供了一种方便管理的创建.保存.回复的对话框机制,例如 onCreateDialog(int), onPrepareDialog(int, Dialog), showDialog(int), dismissDialog(int)等方法,如果使用这些方法的话,Activity将通过getOwnerActivity()方法返回该Activity管理的对话框(dialog). onCreateDialog(int):当你使用这个回调函数时,Android系统会有效的设置这个Acti