WPF—QQ界面(四):单击QQ昵称弹出个人简介窗口的效果实现

效果分析:当鼠标左键单击QQ的昵称时,会弹出另一个关于个人信息的窗口。

此处用到的是Popup。

设置鼠标触发Popup事件,该事件触发会跳转到另一个自定义窗口。

前台代码:

<Button Content="邓不利东" FontSize="24" FontStyle="Normal" Foreground="Black" Background="Transparent" BorderBrush="Transparent"
                    Cursor="Hand" Click="Popup_CP_Click"/>

后台Popup_CP_Click的事件触发:

private void Popup_CP_Click(object sender, RoutedEventArgs e)   
        {
            MyProfile myprofile = new MyProfile();
            myprofile.ShowDialog();
        }

触发事件中MyProfile myprofile = new MyProfile(); 是新建一个MyProfile的窗口,因此,我们新建窗口的时候,将 Title 设为 MyProfile 即可。

如下:

<Window x:Class="QQ_presentation.MyProfile"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MyProfile" Height="700" Width="560"
        ResizeMode="NoResize">

此时就能将主窗口与自定义窗口建立连接了,用Popup弹出自定义窗口。

最终效果图如下:

右图即为Popup出的新窗口。

原文地址:https://www.cnblogs.com/danieldong/p/5342702.html