欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于WPF封裝一個可擴(kuò)展的Window

 更新時間:2024年04月02日 16:54:19   作者:趨時軟件  
WPF中Window相信大家都很熟悉,有時我們有一些自定義需求默認(rèn)Window是無法滿足的,所以本文就來和大家聊聊WPF如何封裝一個可擴(kuò)展的Window吧

前言

WPF中Window相信大家都很熟悉,有時我們有一些自定義需求默認(rèn)Window是無法滿足的,比如在標(biāo)題欄上放一些自己東西,這個時候我們就需要寫一個自己的Window,實現(xiàn)起來也很簡單,只要給Window設(shè)置一個WindowChrome.WindowChrome附加屬性就可以實現(xiàn),WindowChrome 可以讓你自定義窗口的非工作區(qū)的外觀和行為。非工作區(qū)就是窗口的標(biāo)題欄和邊框,通常由操作系統(tǒng)繪制和管理。WindowChrome 可以讓你將 WPF 的內(nèi)容擴(kuò)展到非工作區(qū),同時保留一些系統(tǒng)的功能和行為,比如調(diào)整大小,移動,最大化,最小化等。

一、示例代碼

1.1 基本使用

<local:CustomWindow
    x:Class="CustomWindowDemo.Window1"
    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:local="clr-namespace:CustomWindowDemo"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="Window1"
    Width="800"
    Height="450"
    Icon="/logo.png"
    mc:Ignorable="d">
    <Grid />
</local:CustomWindow>

1.2 自定義標(biāo)題欄高度

<local:CustomWindow
    x:Class="CustomWindowDemo.Window1"
    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:local="clr-namespace:CustomWindowDemo"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="Window1"
    Width="800"
    Height="450"
    CaptionHeight="35"
    Icon="/logo.png"
    mc:Ignorable="d">
    <Grid />
</local:CustomWindow>

1.3 自定義標(biāo)題欄顏色

<local:CustomWindow
    x:Class="CustomWindowDemo.Window1"
    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:local="clr-namespace:CustomWindowDemo"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="Window1"
    Width="800"
    Height="450"
    CaptionBackground="Blue"
    Icon="/logo.png"
    mc:Ignorable="d">
    <Grid />
</local:CustomWindow>

1.4 自定義標(biāo)題欄內(nèi)容

<local:CustomWindow
    x:Class="CustomWindowDemo.Window1"
    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:local="clr-namespace:CustomWindowDemo"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="Window1"
    Width="800"
    Height="450"
    Icon="/logo.png"
    mc:Ignorable="d">
    <local:CustomWindow.CaptionBarContent>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Button
                Margin="5"
                Padding="2"
                VerticalAlignment="Center"
                Background="Transparent"
                BorderThickness="0"
                WindowChrome.IsHitTestVisibleInChrome="True">
                <StackPanel Orientation="Horizontal">
                    <Polygon
                        VerticalAlignment="Center"
                        Fill="White"
                        Points="0,6 6,0 6,12" />
                    <TextBlock
                        Margin="4,0,0,0"
                        VerticalAlignment="Center"
                        FontSize="14"
                        Foreground="White"
                        Text="返回" />
                </StackPanel>
            </Button>
            <TextBlock
                Grid.Column="1"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                FontSize="14"
                Foreground="White"
                Text="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=Title}" />
            <Button
                Grid.Column="2"
                Margin="5"
                Padding="2"
                VerticalAlignment="Center"
                Background="Transparent"
                BorderThickness="0"
                FontSize="14"
                Foreground="White"
                WindowChrome.IsHitTestVisibleInChrome="True">
                <StackPanel Orientation="Horizontal">
                    <TextBlock
                        Margin="0,0,4,0"
                        VerticalAlignment="Center"
                        Text="Admin" />
                    <Polyline
                        VerticalAlignment="Center"
                        Points="0,0 5,5 10,0"
                        Stroke="White"
                        StrokeThickness="2" />
                </StackPanel>
            </Button>
        </Grid>
    </local:CustomWindow.CaptionBarContent>
    <Grid />
</local:CustomWindow>

 二、綜合案例

到此這篇關(guān)于基于WPF封裝一個可擴(kuò)展的Window的文章就介紹到這了,更多相關(guān)WPF封裝可擴(kuò)展Window內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C# WPF 建立無邊框(標(biāo)題欄)的登錄窗口的示例

    C# WPF 建立無邊框(標(biāo)題欄)的登錄窗口的示例

    這篇文章主要介紹了C# WPF 建立無邊框(標(biāo)題欄)的登錄窗口的示例,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-12-12
  • Unity實現(xiàn)人物平滑轉(zhuǎn)身

    Unity實現(xiàn)人物平滑轉(zhuǎn)身

    這篇文章主要為大家詳細(xì)介紹了Unity實現(xiàn)人物平滑轉(zhuǎn)身,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-01-01
  • C#中的匿名方法實例解析

    C#中的匿名方法實例解析

    這篇文章主要介紹了C#中的匿名方法,包括其由來、定義及用法等,需要的朋友可以參考下
    2014-09-09
  • C# 設(shè)計模式系列教程-組合模式

    C# 設(shè)計模式系列教程-組合模式

    組合模式可以使客戶端調(diào)用簡單,它可以一致使用組合結(jié)構(gòu)或是其中單個對象,簡化了客戶端代碼。
    2016-06-06
  • C#設(shè)置窗體最大化且不遮擋任務(wù)欄的方法

    C#設(shè)置窗體最大化且不遮擋任務(wù)欄的方法

    這篇文章主要介紹了C#設(shè)置窗體最大化且不遮擋任務(wù)欄的方法,涉及針對form窗體的寬和高的相對大小操作,是非常簡單而實用的技巧,需要的朋友可以參考下
    2014-12-12
  • C#設(shè)計模式之策略模式

    C#設(shè)計模式之策略模式

    這篇文章介紹了C#設(shè)計模式之策略模式,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • C#使用Queue<T>進(jìn)行隊列設(shè)計

    C#使用Queue<T>進(jìn)行隊列設(shè)計

    Queue<T>類提供了許多方法和屬性,用于處理隊列中的元素,本文主要介紹了C#使用Queue<T>進(jìn)行隊列設(shè)計,具有一定的參考價值,感興趣的可以了解一下
    2024-03-03
  • C#文件流進(jìn)行壓縮和解壓縮的方法

    C#文件流進(jìn)行壓縮和解壓縮的方法

    這篇文章主要介紹了C#文件流進(jìn)行壓縮和解壓縮的方法,涉及C#文件流操作的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • C#中TextBox的橫線樣式及占位提示詳解

    C#中TextBox的橫線樣式及占位提示詳解

    橫線樣式就是將TextBox以一條底橫線的形式展示在頁面,占位提示就是Web的Placeholder屬性,即在輸入框沒有內(nèi)容的時候進(jìn)行一個輸入提示。本文主要介紹了C#中TextBox的這兩個的實現(xiàn),需要的可以參考一下
    2022-11-11
  • WinForm實現(xiàn)最小化到系統(tǒng)托盤方法實例詳解

    WinForm實現(xiàn)最小化到系統(tǒng)托盤方法實例詳解

    這篇文章主要介紹了WinForm實現(xiàn)最小化到系統(tǒng)托盤方法,實例分析了C#中實現(xiàn)WinForm最小化到系統(tǒng)托盤所需的相關(guān)控件與使用技巧,需要的朋友可以參考下
    2015-05-05

最新評論