WPF利用Path自定义画头部导航条(TOP)样式

1;新建两个多值转换器,都有用处,用来动态确定PATH的X,Y州坐标的。

EndPointConverter 该转换器主要用来动态确定X轴,和Y轴。用于画线条的。

internal class EndPointConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        double X = (double)values[0];//第一个值我这为上一个点X轴,可根据自己需要修改
        double C= double.Parse(parameter.ToString());//参数传差值,当前点的X轴与上一个点的X轴相差多少,
        double Y = 0;//默认0
        if (values.Length == 2)
        {
            Point StartPoint = (Point)values[1];//线条开始坐标共用Y轴
            Y = StartPoint.Y;
        }
        return new Point(X-C, Y);
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

PointConverter 主要用来动态确定X轴,和Y轴。但当前Y轴是上一个点的X轴。用于闭合图形填充颜色的Path类型。

public class PointConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        double X = (double)values[0];
        double C = double.Parse(parameter.ToString());//参数传差值
        double Y = 0;//默认0
        if (values.Length == 2)
        {
            Point StartPoint = (Point)values[1];//线条开始坐标共用X轴作为Y轴
            Y = StartPoint.X;//下一个点的Y轴变为上个点的X轴,主要用来画闭合Path的
        }
        return new Point(X - C, Y);
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

2;在写XML之前请在XMAL页面引入两个多值转换器(可根据自己需求自定义值类型和参数类型):

 <Window ....自己定义的其他内容....

xmlns:converters="clr-namespace:你的转换器所在路径"

......自己定义的其他内容.......>

<Window.Resources>
    //也可放置在App.XMAL下全局使用
    <converters:EndPointConverter x:Key="EndPointConverter" />
    <converters:PointConverter x:Key="PointConverter" />
</Window.Resources>

闭合Path的XMAL页面使用如下:

<!--闭合Path-->
<Path StrokeThickness="1.5" Stroke="#04386C">
    <Path.Data>
        <PathGeometry>
            <PathFigure  StartPoint="0,30">
                <LineSegment x:Name="Point1" Point="30,50"></LineSegment>
                <LineSegment x:Name="Point2">
                    <LineSegment.Point>
                        <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="30">
                            <Binding ElementName="ColorZone" Path="ActualWidth"/>
                            <Binding ElementName="Point1" Path="Point"/>
                        </MultiBinding>
                    </LineSegment.Point>
                </LineSegment>
                <LineSegment x:Name="Point3">
                    <LineSegment.Point>
                        <MultiBinding Converter="{StaticResource PointConverter}" ConverterParameter="0">
                            <Binding ElementName="ColorZone" Path="ActualWidth"/>
                            <Binding ElementName="Point1" Path="Point"/>
                        </MultiBinding>
                    </LineSegment.Point>
                </LineSegment>
                <LineSegment x:Name="Point4" >
                    <LineSegment.Point>
                        <MultiBinding Converter="{StaticResource PointConverter}" ConverterParameter="0">
                            <Binding ElementName="ColorZone" Path="ActualWidth"/>
                        </MultiBinding>
                    </LineSegment.Point>
                </LineSegment>
                <LineSegment Point="0,0"></LineSegment>
                <LineSegment Point="0,30"></LineSegment>
            </PathFigure>
        </PathGeometry>
    </Path.Data>
    <Path.Fill>
<!--渐变色设置-->
        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
            <GradientStop Color="#07164C" Offset="0.4"></GradientStop>
            <GradientStop Color="#07205A" Offset="0.8"></GradientStop>
            <GradientStop Color="#07205B" Offset="1"></GradientStop>
        </LinearGradientBrush>
    </Path.Fill>
</Path>

效果:

线条Path的使用如下:

<Path StrokeThickness="3" Stroke="White">
        <Path.Data>
            <GeometryGroup>
                <LineGeometry x:Name="Point1" StartPoint="0 30" EndPoint="50 45" />
                <LineGeometry x:Name="Point2" StartPoint="50,45">
                    <LineGeometry.EndPoint>
                        <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="50">
                            <Binding ElementName="ColorZone" Path="ActualWidth"/>
                            <Binding Path="StartPoint" RelativeSource="{RelativeSource Mode=self}"/>
                        </MultiBinding>
                    </LineGeometry.EndPoint>
                </LineGeometry>
                <LineGeometry x:Name="Point3">
                    <LineGeometry.StartPoint>
                        <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="50">
                            <Binding ElementName="ColorZone" Path="ActualWidth"/>
                            <Binding ElementName="Point2" Path="StartPoint" />
                        </MultiBinding>
                    </LineGeometry.StartPoint>
                    <LineGeometry.EndPoint>
                        <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="0">
                            <Binding ElementName="ColorZone" Path="ActualWidth"/>
                            <Binding ElementName="Point1" Path="StartPoint" />
                        </MultiBinding>
                    </LineGeometry.EndPoint>
                </LineGeometry>
                <LineGeometry x:Name="Point4">
                    <LineGeometry.StartPoint>
                        <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="0">
                            <Binding ElementName="ColorZone" Path="ActualWidth"/>
                            <Binding ElementName="Point3" Path="EndPoint"/>
                        </MultiBinding>
                    </LineGeometry.StartPoint>
                    <LineGeometry.EndPoint>
                        <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="0">
                            <Binding ElementName="ColorZone" Path="ActualWidth"/>
                        </MultiBinding>
                    </LineGeometry.EndPoint>
                </LineGeometry>
                <LineGeometry x:Name="Point5" EndPoint="0 0">
                    <LineGeometry.StartPoint>
                        <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="0">
                            <Binding ElementName="ColorZone" Path="ActualWidth"/>
                        </MultiBinding>
                    </LineGeometry.StartPoint>
                </LineGeometry>
                <LineGeometry x:Name="Point6" StartPoint="0 0" EndPoint="0 30"/>
            </GeometryGroup>
        </Path.Data>
    </Path>

效果(白色才是效果色):

两种图形中的"ColorZone"是Path的父控件,materialDesign:ColorZone是WPF的UI框架materialDesign下的控件,可替换为你自己的控件作为父控件只是注意父控件名称修改下即可。

整体如下:

 <DockPanel>
     <!--头部-->
     <materialDesign:ColorZone Padding="0" Height="50"
                              
                       ClipToBounds="False" CornerRadius="5 5 0 0"
                         DockPanel.Dock="Top" x:Name="ColorZone">
         <StackPanel>
             <!--<Path StrokeThickness="1.5" Stroke="#04386C">
                 <Path.Data>
                     <PathGeometry>
                         <PathFigure  StartPoint="0,30">
                             <LineSegment x:Name="Point1" Point="30,50"></LineSegment>
                             <LineSegment x:Name="Point2">
                                 <LineSegment.Point>
                                     <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="30">
                                         <Binding ElementName="ColorZone" Path="ActualWidth"/>
                                         <Binding ElementName="Point1" Path="Point"/>
                                     </MultiBinding>
                                 </LineSegment.Point>
                             </LineSegment>
                             <LineSegment x:Name="Point3">
                                 <LineSegment.Point>
                                     <MultiBinding Converter="{StaticResource PointConverter}" ConverterParameter="0">
                                         <Binding ElementName="ColorZone" Path="ActualWidth"/>
                                         <Binding ElementName="Point1" Path="Point"/>
                                     </MultiBinding>
                                 </LineSegment.Point>
                             </LineSegment>
                             <LineSegment x:Name="Point4" >
                                 <LineSegment.Point>
                                     <MultiBinding Converter="{StaticResource PointConverter}" ConverterParameter="0">
                                         <Binding ElementName="ColorZone" Path="ActualWidth"/>
                                     </MultiBinding>
                                 </LineSegment.Point>
                             </LineSegment>
                             <LineSegment Point="0,0"></LineSegment>
                             <LineSegment Point="0,30"></LineSegment>
                         </PathFigure>
                     </PathGeometry>
                 </Path.Data>
                 <Path.Fill>
                     <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                         <GradientStop Color="#07164C" Offset="0.4"></GradientStop>
                         <GradientStop Color="#07205A" Offset="0.8"></GradientStop>
                         <GradientStop Color="#07205B" Offset="1"></GradientStop>
                     </LinearGradientBrush>
                 </Path.Fill>
             </Path>-->
             
         <Path StrokeThickness="3" Stroke="White">
                 <Path.Data>
                     <GeometryGroup>
                         <LineGeometry x:Name="Point1" StartPoint="0 30" EndPoint="50 45" />
                         <LineGeometry x:Name="Point2" StartPoint="50,45">
                             <LineGeometry.EndPoint>
                                 <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="50">
                                     <Binding ElementName="ColorZone" Path="ActualWidth"/>
                                     <Binding Path="StartPoint" RelativeSource="{RelativeSource Mode=self}"/>
                                 </MultiBinding>
                             </LineGeometry.EndPoint>
                         </LineGeometry>
                         <LineGeometry x:Name="Point3">
                             <LineGeometry.StartPoint>
                                 <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="50">
                                     <Binding ElementName="ColorZone" Path="ActualWidth"/>
                                     <Binding ElementName="Point2" Path="StartPoint" />
                                 </MultiBinding>
                             </LineGeometry.StartPoint>
                             <LineGeometry.EndPoint>
                                 <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="0">
                                     <Binding ElementName="ColorZone" Path="ActualWidth"/>
                                     <Binding ElementName="Point1" Path="StartPoint" />
                                 </MultiBinding>
                             </LineGeometry.EndPoint>
                         </LineGeometry>
                         <LineGeometry x:Name="Point4">
                             <LineGeometry.StartPoint>
                                 <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="0">
                                     <Binding ElementName="ColorZone" Path="ActualWidth"/>
                                     <Binding ElementName="Point3" Path="EndPoint"/>
                                 </MultiBinding>
                             </LineGeometry.StartPoint>
                             <LineGeometry.EndPoint>
                                 <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="0">
                                     <Binding ElementName="ColorZone" Path="ActualWidth"/>
                                 </MultiBinding>
                             </LineGeometry.EndPoint>
                         </LineGeometry>
                         <LineGeometry x:Name="Point5" EndPoint="0 0">
                             <LineGeometry.StartPoint>
                                 <MultiBinding Converter="{StaticResource EndPointConverter}" ConverterParameter="0">
                                     <Binding ElementName="ColorZone" Path="ActualWidth"/>
                                 </MultiBinding>
                             </LineGeometry.StartPoint>
                         </LineGeometry>
                         <LineGeometry x:Name="Point6" StartPoint="0 0" EndPoint="0 30"/>
                     </GeometryGroup>
                 </Path.Data>
             </Path>
         </StackPanel>
        
        
     </materialDesign:ColorZone>
     <!--底部-->
    
     <!--中部 只能放于最后,利用DockPanel的LastChildFill特性填充中间空间-->
    
 </DockPanel>

END.......虽然最终未采用该方式,但值得记录一下。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/877494.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

wifiip地址可以随便改吗?wifi的ip地址怎么改变

对于普通用户来说&#xff0c;WiFi IP地址的管理和修改往往显得神秘而复杂。本文旨在深入探讨WiFi IP地址是否可以随意更改&#xff0c;以及如何正确地改变WiFi的IP地址。虎观代理小二将详细解释WiFi IP地址的基本概念、作用以及更改时需要注意的事项&#xff0c;帮助用户更好地…

PPT中的图形与图片:插入、调整与格式设置技术详解

目录 引言 一、图形与图片的插入 1. 插入图形 2. 插入图片 二、图形与图片的调整 1. 调整大小与位置 2. 裁剪与旋转 3. 图形与图片的合并与组合 三、图片格式与布局设置 1. 图片格式设置 2. 图片布局设置 示例案例&#xff1a;制作产品展示PPT 四、结论 引言 在现…

Harmony OS DevEco Studio低代码开发流程 - HarmonyOS开发自学5

一. 为什么要用低代码开发&#xff1f; HarmonyOS低代码开发方式&#xff0c;具有丰富的UI界面编辑功能&#xff0c;例如基于图形化的自由拖拽、数据的参数化配置等&#xff0c;通过可视化界面开发方式快速构建布局&#xff0c;可有效降低用户的时间成本和提升用户构建UI界面的…

【JVM】类加载

1. 类加载过程 Java虚拟机&#xff08;JVM&#xff09;的 类加载 过程是将字节码文件&#xff08;.class文件&#xff09;从存储设备加载到内存&#xff0c;并为其创建相应的类对象的过程。类加载是Java程序运行的基础&#xff0c;保证了程序的动态性和安全性。JVM的类加载过程…

Unity 粒子系统参数说明

一、Particle System 1. Duration&#xff08;持续时间&#xff09; 粒子系统运行一次所需的时间。它决定粒子系统持续播放的时间长度。 2. Looping&#xff08;循环播放&#xff09; 如果启用&#xff0c;粒子系统将在播放完一次后自动重新开始播放&#xff0c;直到你停止它…

pgrouting实战应用

1&#xff09;下载地区地区数据&#xff08;下载数据是XYZM 四位数据&#xff09; 2&#xff09;下载裁剪行政区数据 3&#xff09;使用arcgis pro添加路网数据和行政区数据 4&#xff09;裁剪数据&#xff0c;仅历下行政区路网 5&#xff09;arcgis pro要素转线&#xff0…

【数据结构】顺序表和链表经典题目

系列文章目录 单链表 动态顺序表实现通讯录 顺序表 文章目录 系列文章目录前言一、顺序表经典例题1. 移除元素2. 合并两个有序数组 二、链表经典例题1. 移除链表元素2. 反转链表3. 合并两个有序链表4. 链表的中间节点5. 环形链表的约瑟夫问题 总结 前言 我们通过前面对顺序表…

ArrayList 源码解析

ArrayList是Java集合框架中的一个动态数组实现&#xff0c;提供了可变大小的数组功能。它继承自AbstractList并实现了List接口&#xff0c;是顺序容器&#xff0c;即元素存放的数据与放进去的顺序相同&#xff0c;允许放入null元素&#xff0c;底层通过数组实现。除该类未实现同…

HTB-Vaccine(suid提权、sqlmap、john2zip)

前言 各位师傅大家好&#xff0c;我是qmx_07&#xff0c;今天来为大家讲解Vaccine靶机 渗透过程 信息搜集 服务器开放了 21FTP服务、22SSH服务、80HTTP服务 通过匿名登录FTP服务器 通过匿名登录到服务器&#xff0c;发现backup.zip文件&#xff0c;可能存在账号密码 发现b…

2024.9.16 day 1 pytorch安装及环境配置

一、配置pytorch环境&#xff0c;安装pytorch 1.查看python版本 python --version 2.在anaconda命令中创建pytorch环境 conda create -n pytorch python3.12(python版本&#xff09; 3.pytorch安装 pytorch首页 PyTorchhttps://pytorch.org/ os为windows推荐package选择…

算法练习题27——疫情下的电影院(模拟)

其实思路还好 就是输入有点难搞 Java import java.util.ArrayList; import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner new Scanner(System.in);String input scanner.nextLine();// 去掉输入字符串的方括号if (input.…

react 安装使用 antd+国际化+定制化主题+样式兼容

安装antd 现在从 yarn 或 npm 或 pnpm 安装并引入 antd。 yarn add antd修改 src/App.js&#xff0c;引入 antd 的按钮组件。 import React from react; import { Button } from antd;const App: React.FC () > (<div className"App"><Button type&q…

USB摄像头视频流转RTSP流

一、VLC查看USB摄像头视频流原理&#xff1a; USB摄像头的工作原理与VLC播放其他视频文件类似&#xff0c;主要区别在于视频流的来源是实时捕获的&#xff0c;而不是预先录制的文件。如果使用VLC将USB摄像头的视频流作为RTSP服务器广播&#xff0c;需要进一步配置 二、VLC查看…

[机器学习]决策树

1 决策树简介 2 信息熵 3 ID3决策树 3.1 决策树构建流程 3.2 决策树案例 4 C4.5决策树 5 CART决策树&#xff08;分类&回归&#xff09; 6 泰坦尼克号生存预测案例 import pandas as pd from sklearn.model_selection import train_test_split from sklearn.tree import …

扣子智能体实战-汽车客服对话机器人(核心知识:知识库和卡片)

这一节的主要内容是通过创建一个汽车客户对话机器人学习扣子平台知识库和卡片的使用。 机器人参考&#xff1a; 企业汽车客服 资深汽车销售 一&#xff0c;汽车销售机器人需求简介 汽车销售是一个需要 7*24h在线的客服咨询岗位&#xff0c;专业性强&#xff0c;但流动性非…

【数据结构】排序算法---直接插入排序

文章目录 1. 定义2. 算法步骤3. 动图演示4. 性质5. 算法分析6. 代码实现C语言PythonJavaCGo 7. 折半插入排序代码实现——C 结语 1. 定义 直接插入排序是一种简单直观的排序算法。它的工作原理为将待排列元素划分为「已排序」和「未排序」两部分&#xff0c;每次从「未排序的」…

自定义EPICS在LabVIEW中的测试

继续上一篇&#xff1a;LabVIEW中EPICS客户端/服务端的测试 变量定义 You can use CaLabSoftIOC.vi to create new EPICS variables and start them. CA Lab - LabVIEW (Realtime) EPICS INPUT: PV set Cluster-array of names, data types and field definitions to crea…

【Go】Go语言介绍与开发环境搭建

✨✨ 欢迎大家来到景天科技苑✨✨ &#x1f388;&#x1f388; 养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; &#x1f3c6; 作者简介&#xff1a;景天科技苑 &#x1f3c6;《头衔》&#xff1a;大厂架构师&#xff0c;华为云开发者社区专家博主&#xff0c;…

【Elasticsearch系列六】系统命令API

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…

二叉树OJ题——二叉树的前序遍历

文章目录 一、题目链接二、解题思路三、解题代码 一、题目链接 二叉树的前序遍历 二叉树前序遍历后需要返回一个 list 。 二、解题思路 三、解题代码