wpf 用户控件

实现目标

dbeaver 新建连接时选择数据库类型控件

在这里插入图片描述

参考资料

自定义控件: https://www.cnblogs.com/dotnet261010/p/6372222.html

新建用户控件

在这里插入图片描述

xaml

<UserControl x:Class="database_manager.DatabaseItemSelectorButton"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:khl="clr-namespace:database_manager"
             mc:Ignorable="d" 
             d:DesignHeight="110" d:DesignWidth="100" Padding="5" MouseEnter="selector_MouseEnter" MouseLeave="selector_MouseLeave" MouseDown="selector_MouseDown">
    <StackPanel Orientation="Vertical">
        <Image Name="image" Source="{Binding Path=ImagePath, RelativeSource= {RelativeSource AncestorType={x:Type khl:DatabaseItemSelectorButton }}}" Height="70"/>
        <!--<Label Name="label" Margin="0 5 0 0" Content="{Binding Path=DatabaseName, RelativeSource= {RelativeSource AncestorType={x:Type khl:DatabaseItemSelectorButton }}}" HorizontalContentAlignment="Center" Foreground="#ffffff"  />-->
        <Label Name="label" Margin="0 5 0 0" Content="{Binding DatabaseName}" HorizontalContentAlignment="Center" />
    </StackPanel>
</UserControl>

cs

using log4net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace database_manager
{
   
    /// <summary>
    /// DatabaseItemSelectorButton.xaml 的交互逻辑
    /// </summary>
    public partial class DatabaseItemSelectorButton : UserControl
    {
   
        ILog log = LogManager.GetLogger(typeof(DatabaseItemSelectorButton));

        /// <summary>
        /// 选中状态背景色
        /// </summary>
        private const string SELECT_BG = "#0078D7";

        /// <summary>
        /// 未选中状态悬停背景色
        /// </summary>
        private const string UN_SELECT_BG = "#4CA0E3";

        /// <summary>
        /// 鼠标悬停标签颜色
        /// </summary>
        private const string LABEL_HOVER_COLOR = "#FFFFFF";

        /// <summary>
        /// 鼠标离开标签颜色
        /// </summary>
        private const string LABEL_NORMAL_COLOR = "#000000";

        /// <summary>
        /// 数据库名称
        /// </summary>
        public static readonly DependencyProperty DatabaseNameProperty = DependencyProperty.Register("DatabaseName",
            typeof(string), typeof(DatabaseItemSelectorButton), new PropertyMetadata("", new PropertyChangedCallback(OnDatabaseNamePropertyChange)));

        /// <summary>
        /// 图片
        /// </summary>
        public static readonly DependencyProperty ImagePathProperty = DependencyProperty.Register("ImagePath",
            typeof(string), typeof(DatabaseItemSelectorButton), new PropertyMetadata("", new PropertyChangedCallback(OnImagePathPropertyChange)));

        /// <summary>
        /// 选中状态变化事件
        /// </summary>
        public static readonly RoutedEvent SelectedChangedEvent = EventManager.RegisterRoutedEvent("SelectedChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(DatabaseItemSelectorButton));

        /// <summary>
        /// 是否选中
        /// </summary>
        public bool Checked {
    get; set; }

        /// <summary>
        /// 图片路径
        /// </summary>
        public string ImagePath
        {
   
            get {
    return 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值