最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于WPF封裝一個可擴展的Window

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

前言

WPF中Window相信大家都很熟悉,有時我們有一些自定義需求默認Window是無法滿足的,比如在標題欄上放一些自己東西,這個時候我們就需要寫一個自己的Window,實現(xiàn)起來也很簡單,只要給Window設(shè)置一個WindowChrome.WindowChrome附加屬性就可以實現(xiàn),WindowChrome 可以讓你自定義窗口的非工作區(qū)的外觀和行為。非工作區(qū)就是窗口的標題欄和邊框,通常由操作系統(tǒng)繪制和管理。WindowChrome 可以讓你將 WPF 的內(nèi)容擴展到非工作區(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 自定義標題欄高度

<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 自定義標題欄顏色

<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 自定義標題欄內(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封裝一個可擴展的Window的文章就介紹到這了,更多相關(guān)WPF封裝可擴展Window內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C# 和 Python 的 hash_md5加密方法

    C# 和 Python 的 hash_md5加密方法

    這篇文章主要介紹了C# 和 Python 的 hash_md5加密方法,文章圍繞著C# 和 Python 的 hash_md5加密的相關(guān)資料展開文章的詳細呢偶然,需要的朋友可以參考一下,希望對你有所幫助
    2021-11-11
  • 一個可攜帶附加消息的增強消息框MessageBoxEx

    一個可攜帶附加消息的增強消息框MessageBoxEx

    一個可攜帶附加消息的增強消息框MessageBoxEx分享給大家,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • C#控制反轉(zhuǎn)的使用詳解

    C#控制反轉(zhuǎn)的使用詳解

    控制反轉(zhuǎn)是將對象的創(chuàng)建、依賴管理和生命周期控制從應(yīng)用程序代碼中轉(zhuǎn)移出來,交由外部容器來管理,下面就來詳細的介紹一下C#控制反轉(zhuǎn)的使用,感興趣的可以了解一下
    2026-01-01
  • C#中刪除字符串指定位置字符的5種方法

    C#中刪除字符串指定位置字符的5種方法

    文章介紹了在C#中刪除字符串中第x個字符的幾種方法,包括String.Remove()、Substring()、StringBuilder、字符數(shù)組和LINQ,并提供了完整示例,推薦使用String.Remove()方法,因其簡潔高效,下面小編通過代碼為大家詳細說說,需要的朋友可以參考下
    2026-02-02
  • C# 使用鼠標點擊對Chart控件實現(xiàn)數(shù)據(jù)提示效果

    C# 使用鼠標點擊對Chart控件實現(xiàn)數(shù)據(jù)提示效果

    這篇文章主要介紹了C# 使用鼠標點擊對Chart控件實現(xiàn)數(shù)據(jù)提示效果,文章給予上一篇的詳細內(nèi)容做延伸介紹,需要的小伙伴可任意參考一下
    2022-08-08
  • 如何用C#找出數(shù)組中只出現(xiàn)了一次的數(shù)字

    如何用C#找出數(shù)組中只出現(xiàn)了一次的數(shù)字

    數(shù)組從字面上理解就是存放一組數(shù),下面這篇文章主要給大家介紹了關(guān)于如何用C#找出數(shù)組中只出現(xiàn)了一次的數(shù)字,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-12-12
  • 詳解C# 線程的掛起與喚醒

    詳解C# 線程的掛起與喚醒

    這篇文章主要介紹了詳解C# 線程的掛起與喚醒,幫助大家更好的理解和學習使用c#,感興趣的朋友可以了解下
    2021-05-05
  • C# 10分鐘完成百度人臉識別(入門篇)

    C# 10分鐘完成百度人臉識別(入門篇)

    這篇文章主要介紹了C# 10分鐘完成百度人臉識別(入門篇),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-02-02
  • DevExpress實現(xiàn)為TextEdit設(shè)置水印文字的方法

    DevExpress實現(xiàn)為TextEdit設(shè)置水印文字的方法

    這篇文章主要介紹了DevExpress實現(xiàn)為TextEdit設(shè)置水印文字的方法,對C#程序設(shè)計人員來說是一個很實用的技巧,需要的朋友可以參考下
    2014-08-08
  • C#操作ini文件的幫助類

    C#操作ini文件的幫助類

    這篇文章介紹了C#操作ini文件的幫助類,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04

最新評論

泰州市| 北票市| 宜兴市| 高尔夫| 浦城县| 神木县| 平舆县| 梅河口市| 龙江县| 泸水县| 潍坊市| 和龙市| 萝北县| 山西省| 瑞安市| 静安区| 和顺县| 延安市| 都安| 乐都县| 承德市| 墨脱县| 临沭县| 韶山市| 乾安县| 大渡口区| 安远县| 托里县| 翁源县| 苏尼特右旗| 龙南县| 个旧市| 宁晋县| 济宁市| 昌宁县| 嘉义县| 长春市| 西充县| 昭通市| 岳普湖县| 北宁市|