間如流水,只能流去不流回!
點贊再看,養成習慣,這是您給我創作的動力!
本文 Dotnet9 https://dotnet9.com 已收錄,站長樂于分享dotnet相關技術,比如Winform、WPF、ASP.NET Core、Xamarin.Forms等,亦有C++桌面相關的Qt Quick和Qt Widgets等,只分享自己熟悉的、自己會的。
閱讀導航:
YouTube Design com WPF 大神處習得,常用的遮罩對話框實現,使用的開源 C# WPF控件庫 MaterialDesignInXAML ,本站曾有介紹:開源C# WPF控件庫《MaterialDesignInXAML》。
站長使用.Net Core 3.1創建的WPF工程,創建“ScreenOverlayMessage”解決方案后,需要添加兩個Nuget庫:MaterialDesignThemes和MaterialDesignColors,上圖的效果是使用該控件庫實現的,非常強大。
不需要截圖,只修改了兩個文件,App.xaml添加MD控件4個樣式文件,MainWindow主窗口實現效果。
<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>
MainWindow.xaml,整體布局,看上圖加上下面的界面代碼,添加界面左上角logo圖標、左側導航菜單等,下面即是全部代碼。
<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.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ScreenOverlayMessage"
mc:Ignorable="d"
xmlns:materialDesign="http://materialdesigninxaml.net/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">
允許應用程序訪問您計算機上的照片、媒體和文件?
</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.dotnet9.com/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>
重點講解:
后臺有個拖動窗體代碼:
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
建議直接打開大神視頻學習,他的YouTube上還有很多代碼視頻哦,參考:
參考視頻: Design com WPF: https://www.youtube.com/watch?v=Dwi9o3K73XM
文章中代碼已經全部貼出。
除非注明,文章均由 Dotnet9 整理發布,歡迎轉載。
轉載請注明本文地址:https://dotnet9.com/6769.html
tml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>點擊彈窗遮罩</title>
</head>
<body>
<button id="btn">點擊</button>
<!-- 遮罩 -->
<div class="cover" id="cover"></div>
<!-- 彈框 -->
<div class="grid" id="grid_box">
<span class="grid_close">x</span>
<h3>標題</h3>
<div>hahaha</div>
</div>
</body>
</html>
css
<style type="text/css">
.cover{
display: none;
position: fixed;
width:100%;
height:100%;
z-index:2;
background: rgba(102,102,102,0.7);
top:0;
left:0;
}
.grid{
display: none;
position: fixed;
z-index: 3;
width: 500px;
min-height: 300px;
top:50%;
left:50%;
margin: -150px 0 0 -250px;
background: #fff;
padding: 15px;
border-radius:10px;
}
.grid_close{
background: #fff;
float:right;
}
</style>
js
<script type="text/javascript">
var Btn = document.getElementById('btn'),
Cover = document.getElementById('cover'),
Box = document.getElementById('grid_box'),
GridClose = Box.getElementsByClassName('grid_close')[0];
//點擊彈出彈窗
Btn.onclick =function(){
ShowHide(true,Cover,Box);
}
//點擊關閉按鈕關閉彈窗
GridClose.onclick=function(){
ShowHide(false,Cover,Box);
}
//點擊遮罩空白關閉彈窗
Cover.onclick=function(){
ShowHide(false,Cover,Box);
}
//關閉公用方法
function ShowHide(Bool,item1,item2){
for (var i = 1,len=arguments.length; i<len; i++) {
if (Bool) {
arguments[i].style.display="block";
}else{
arguments[i].style.display="none";
}
}
}
</script>
業網頁推廣時出現網頁兼容問題,不僅在pc端開發中會碰到,而且在APP開發當中也會經常碰到。
1、禁止圖片點擊放大
部分安卓手機點擊圖片會放大,如需要禁止放大,只需要設置css屬性,這樣會讓img標簽的點擊事件失效,如果想要給圖片添加點擊事件就要給上面再寫一層。
方案:img{ pointer-events:none; }
2、禁止iOS設別長串數字為電話
方案:<meta name="format-detection" content="telephone=no" />
3、禁止賦值、選中文本
方案:設置CSS屬性,-webkit-user-select:none
4、一些情況下對非可點擊元素如(label,span)監聽點擊事件,不會在iOS下觸發
方案:css屬性增加 cursor:pointer
5、上下拉動滾動條時卡頓、慢
方案:body{ -webkit-overflow-scrolling:touch;overflow-scrolling:touch; }
6、安卓不會自動播放視頻
安卓手機的autoplay沒有生效,需要手動觸發一下
方案:window.addEventListener('touchstart',()=>{ audio.play(); },false)
7、半透明的遮罩層改為全透明
在iOS上,當點擊一個鏈接或者通過js綁定了點擊事件的元素時,會出現一個半透明的背景,當手指離開屏幕,灰色背景消失,出現“閃屏”
方案:html,body{ -webkit-tap-highlight-color:rgba(0,0,0,0); }
8、ios系統全屏狀態下瀏覽器上下滾動時會出現底色問題
移動端項目要求是全屏滾動,用的是 fullpage,上下滾動時安卓正常,蘋果手機瀏覽器上下滾動時會出現底色問題
方案:document.body.addEventListener('touchmove',function(e) { e.preventDefault();}, {passive:false})。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。