小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

C# WPF遮罩對話框(Popup Message Overlay/ Dialog Host)

 行者花雕 2021-04-18

時間如流水,只能流去不流回!

點贊再看,養(yǎng)成習(xí)慣,這是您給我創(chuàng)作的動力!

本文 Dotnet9 https:// 已收錄,站長樂于分享dotnet相關(guān)技術(shù),比如Winform、WPF、ASP.NET Core、Xamarin.Forms等,亦有C++桌面相關(guān)的Qt Quick和Qt Widgets等,只分享自己熟悉的、自己會的。

閱讀導(dǎo)航:

  • 一、先看效果
  • 二、本文背景
  • 三、代碼實現(xiàn)
  • 四、文章參考
  • 五、代碼下載

一、先看效果

二、本文背景

YouTube  Design com WPF 大神處習(xí)得,常用的遮罩對話框?qū)崿F(xiàn),使用的開源 C# WPF控件庫 MaterialDesignInXAML ,本站曾有介紹:開源C# WPF控件庫《MaterialDesignInXAML》

三、代碼實現(xiàn)

3.1 添加Nuget庫

站長使用.Net Core 3.1創(chuàng)建的WPF工程,創(chuàng)建“ScreenOverlayMessage”解決方案后,需要添加兩個Nuget庫:MaterialDesignThemes和MaterialDesignColors,上圖的效果是使用該控件庫實現(xiàn)的,非常強大。

C# WPF抽屜效果實現(xiàn)(C# WPF Material Design UI: Navigation Drawer & PopUp Menu)

3.2 工程結(jié)構(gòu)

不需要截圖,只修改了兩個文件,App.xaml添加MD控件4個樣式文件,MainWindow主窗口實現(xiàn)效果。

3.3 App.xaml引入MD控件樣式

<Application x:Class="DropDownMenu.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:DropDownMenu"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Indigo.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

3.4 主窗體

MainWindow.xaml,整體布局,看上圖加上下面的界面代碼,添加界面左上角logo圖標(biāo)、左側(cè)導(dǎo)航菜單等,下面即是全部代碼。

<Window x:Class="ScreenOverlayMessage.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./markup-compatibility/2006"
        xmlns:local="clr-namespace:ScreenOverlayMessage"
        mc:Ignorable="d"
        xmlns:materialDesign="http:///winfx/xaml/themes" MouseDown="Window_MouseDown"
        Title="MainWindow" Height="576" Width="1024" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowStyle="None" Background="#FF423A3A">
    <Grid>
        <materialDesign:DialogHost BorderBrush="{DynamicResource MaterialDesignDivider}">
            <materialDesign:DialogHost.DialogContent>
                <Grid Width="300" Height="150" HorizontalAlignment="Center">
                    <StackPanel Orientation="Horizontal" Margin="15">
                        <materialDesign:PackIcon Kind="Folder" Foreground="{StaticResource PrimaryHueMidBrush}" Width="50" Height="50"/>
                        <TextBlock Foreground="Gray" Width="200" Margin="15 5" TextWrapping="Wrap">
                            允許應(yīng)用程序訪問您計算機上的照片、媒體和文件?
                        </TextBlock>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="15">
                        <Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Style="{DynamicResource MaterialDesignFlatButton}" Margin="4" VerticalAlignment="Center">
                            拒絕
                        </Button>
                        <Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Style="{DynamicResource MaterialDesignFlatButton}" Margin="4" VerticalAlignment="Center">
                            允許
                        </Button>
                    </StackPanel>
                </Grid>
            </materialDesign:DialogHost.DialogContent>
            <Grid>
                <StackPanel Width="200" HorizontalAlignment="Left" Background="#FF472076">
                    <Grid Height="150" Background="White">
                        <Image Source="https://img./logo.png"/>
                    </Grid>
                    <Button Style="{StaticResource MaterialDesignFlatButton}" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
                        <StackPanel Orientation="Horizontal" Height="30">
                            <materialDesign:PackIcon Kind="PhotoAlbum" Width="20" Height="20" VerticalAlignment="Center"/>
                            <TextBlock Text="照片" Margin="20 0" FontSize="15" VerticalAlignment="Center"/>
                        </StackPanel>
                    </Button>
                    <Button Style="{StaticResource MaterialDesignFlatButton}" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
                        <StackPanel Orientation="Horizontal" Height="30">
                            <materialDesign:PackIcon Kind="Music" Width="20" Height="20" VerticalAlignment="Center"/>
                            <TextBlock Text="音樂" Margin="20 0" FontSize="15" VerticalAlignment="Center"/>
                        </StackPanel>
                    </Button>
                </StackPanel>
            </Grid>
        </materialDesign:DialogHost>
    </Grid>
</Window>

重點講解:

  • materialDesign:DialogHost:設(shè)置遮罩對話框覆蓋的地方,即彈出遮罩對話框后,背后有陰影的位置。
  • materialDesign:DialogHost.DialogContent:對話框內(nèi)容,即彈出的對話框配置

后臺有個拖動窗體代碼:

private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
    DragMove();
}

四、文章參考

建議直接打開大神視頻學(xué)習(xí),他的YouTube上還有很多代碼視頻哦,參考:
參考視頻: Design com WPF: https://www./watch?v=Dwi9o3K73XM

五、代碼下載

文章中代碼已經(jīng)全部貼出。

除非注明,文章均由 Dotnet9 整理發(fā)布,歡迎轉(zhuǎn)載。

轉(zhuǎn)載請注明本文地址:https:///6769.html

歡迎掃描下方二維碼關(guān)注 Dotnet9 的微信公眾號,本站會及時推送最新技術(shù)文章(微信公眾號“dotnet9_com”):

 

如有收獲,請大力轉(zhuǎn)發(fā),給Dotnet9贊助和支持,謝謝大家對dotnet技術(shù)的關(guān)注和支持 。

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多