Selaa lähdekoodia

20251113002 添加浮窗显示,增加了两个方式,窗口和展示框

向羽 孟 1 viikko sitten
vanhempi
säilyke
f2dff51a9f

+ 7 - 0
MvvmScaffoldFrame48/MvvmScaffoldFrame48.csproj

@@ -75,6 +75,9 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="WPFFroms\SuspensionWindow.xaml.cs">
+      <DependentUpon>SuspensionWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="WPFPage\AlarmPage.xaml.cs">
       <DependentUpon>AlarmPage.xaml</DependentUpon>
     </Compile>
@@ -97,6 +100,10 @@
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Page Include="WPFFroms\SuspensionWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="WPFPage\AlarmPage.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 1 - 1
MvvmScaffoldFrame48/WPFFroms/MainWindow.xaml

@@ -5,7 +5,7 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:MvvmScaffoldFrame48"
         mc:Ignorable="d"
-        Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
+        Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded" Closing="Window_Closing">
     <Grid>
         <Frame x:Name="ShowFrame" Margin="0,0,0,0" NavigationUIVisibility="Hidden"/>
     </Grid>

+ 7 - 1
MvvmScaffoldFrame48/WPFFroms/MainWindow.xaml.cs

@@ -17,8 +17,14 @@ namespace MvvmScaffoldFrame48
 
         private void Window_Loaded(object sender, RoutedEventArgs e)
         {
-            Uri ShowUri = new Uri("WPFPage\\AlarmPage.xaml", UriKind.Relative);
+            Uri ShowUri = new Uri("WPFPage\\CustomControlPage.xaml", UriKind.Relative);
             ShowFrame.Navigate(ShowUri);
         }
+
+        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
+        {
+
+            Environment.Exit(0);
+        }
     }
 }

+ 16 - 0
MvvmScaffoldFrame48/WPFFroms/SuspensionWindow.xaml

@@ -0,0 +1,16 @@
+<Window x:Class="MvvmScaffoldFrame48.WPFFroms.SuspensionWindow"
+        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:MvvmScaffoldFrame48.WPFFroms"
+        mc:Ignorable="d"
+        Title="SuspensionWindow" WindowStyle="None" ResizeMode="NoResize" Topmost="True"
+        AllowsTransparency="True" Background="Transparent"
+        SizeToContent="WidthAndHeight">
+    <Grid>
+        <Border Background="White" BorderBrush="Gray" BorderThickness="1" CornerRadius="5">
+            <TextBlock Text="悬浮窗口内容" Padding="20" Margin="10"/>
+        </Border>
+    </Grid>
+</Window>

+ 32 - 0
MvvmScaffoldFrame48/WPFFroms/SuspensionWindow.xaml.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+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.Shapes;
+
+namespace MvvmScaffoldFrame48.WPFFroms
+{
+    /// <summary>
+    /// SuspensionWindow.xaml 的交互逻辑
+    /// </summary>
+    public partial class SuspensionWindow : Window
+    {
+        public SuspensionWindow()
+        {
+            InitializeComponent();
+            this.WindowStyle = WindowStyle.None;
+            this.ResizeMode = ResizeMode.NoResize;
+            this.Topmost = true;
+            this.AllowsTransparency = true;
+            this.Background = Brushes.Transparent;
+        }
+    }
+}

+ 13 - 0
MvvmScaffoldFrame48/WPFPage/CustomControlPage.xaml

@@ -116,6 +116,19 @@
                     </Button.Template>
                 </Button>
             </StackPanel>
+            <StackPanel Orientation ="Horizontal"  HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,120,0,0"> 
+                <Label Content="悬浮提示框:"/>
+                <Button Content="悬浮提示框" Name="PopupBtn" BorderThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" Click="PopupBtn_Click"/>
+                <Popup Name="myPopup" Placement="Mouse" AllowsTransparency="True">
+                    <Border Background="LightYellow" BorderBrush="Gray" BorderThickness="1">
+                        <TextBlock Text="这是一个悬浮提示" Padding="10"/>
+                    </Border>
+                </Popup>
+            </StackPanel>
+            <StackPanel Orientation ="Horizontal"  HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,160,0,0">
+                <Label Content="悬浮窗口:"/>
+                <Button Content="悬浮窗口" Name="FloatBtn" BorderThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" Click="FloatBtn_Click"/>
+            </StackPanel>
         </Grid>
     </Grid>
 </Page>

+ 19 - 0
MvvmScaffoldFrame48/WPFPage/CustomControlPage.xaml.cs

@@ -1,4 +1,5 @@
 using MvvmScaffoldFrame48.ViewModel.ViewModel;
+using MvvmScaffoldFrame48.WPFFroms;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -21,11 +22,29 @@ namespace MvvmScaffoldFrame48.WPFPage
     /// </summary>
     public partial class CustomControlPage : Page
     {
+        SuspensionWindow suspensionWindow = new SuspensionWindow();
         public CustomControlPage()
         {
             InitializeComponent();
             CustomControlViewModel viewModel = new CustomControlViewModel();
             this.DataContext = viewModel;
         }
+
+        private void PopupBtn_Click(object sender, RoutedEventArgs e)
+        {
+            myPopup.IsOpen = !myPopup.IsOpen;
+        }
+
+        private void FloatBtn_Click(object sender, RoutedEventArgs e)
+        {
+            if(suspensionWindow.IsVisible)
+            {
+                suspensionWindow.Hide();
+            }
+            else
+            {
+                suspensionWindow.Show();
+            }
+        }
     }
 }