实现目标
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