-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 添加 ListBox 和 ListBoxItem 的自定义控件, 允许 TextBox 设置 CornerRadius
- Loading branch information
Showing
10 changed files
with
231 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace EleCho.WpfSuite | ||
{ | ||
public class ListBox : System.Windows.Controls.ListBox | ||
{ | ||
static ListBox() | ||
{ | ||
DefaultStyleKeyProperty.OverrideMetadata(typeof(ListBox), new FrameworkPropertyMetadata(typeof(ListBox))); | ||
} | ||
|
||
public CornerRadius CornerRadius | ||
{ | ||
get { return (CornerRadius)GetValue(CornerRadiusProperty); } | ||
set { SetValue(CornerRadiusProperty, value); } | ||
} | ||
|
||
protected override DependencyObject GetContainerForItemOverride() | ||
{ | ||
return new ListBoxItem(); | ||
} | ||
|
||
public static readonly DependencyProperty CornerRadiusProperty = | ||
Border.CornerRadiusProperty.AddOwner(typeof(ListBox)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace EleCho.WpfSuite | ||
{ | ||
public class ListBoxItem : System.Windows.Controls.ListBoxItem | ||
{ | ||
static ListBoxItem() | ||
{ | ||
DefaultStyleKeyProperty.OverrideMetadata(typeof(ListBoxItem), new FrameworkPropertyMetadata(typeof(ListBoxItem))); | ||
} | ||
|
||
public CornerRadius CornerRadius | ||
{ | ||
get { return (CornerRadius)GetValue(CornerRadiusProperty); } | ||
set { SetValue(CornerRadiusProperty, value); } | ||
} | ||
|
||
|
||
public static readonly DependencyProperty CornerRadiusProperty = | ||
Border.CornerRadiusProperty.AddOwner(typeof(ListBoxItem)); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:ws="https://github.com/OrgEleCho/EleCho.WpfSuite"> | ||
|
||
<Style x:Key="FocusVisual"> | ||
<Setter Property="Control.Template"> | ||
<Setter.Value> | ||
<ControlTemplate> | ||
<Rectangle Margin="2" StrokeDashArray="1 2" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" SnapsToDevicePixels="true" StrokeThickness="1"/> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
<SolidColorBrush x:Key="Item.MouseOver.Background" Color="#1F26A0DA"/> | ||
<SolidColorBrush x:Key="Item.MouseOver.Border" Color="#a826A0Da"/> | ||
<SolidColorBrush x:Key="Item.SelectedActive.Background" Color="#3D26A0DA"/> | ||
<SolidColorBrush x:Key="Item.SelectedActive.Border" Color="#FF26A0DA"/> | ||
<SolidColorBrush x:Key="Item.SelectedInactive.Background" Color="#3DDADADA"/> | ||
<SolidColorBrush x:Key="Item.SelectedInactive.Border" Color="#FFDADADA"/> | ||
<Style TargetType="{x:Type ws:ListBoxItem}"> | ||
<Setter Property="SnapsToDevicePixels" Value="True"/> | ||
<Setter Property="Padding" Value="4,1"/> | ||
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> | ||
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> | ||
<Setter Property="Background" Value="Transparent"/> | ||
<Setter Property="BorderBrush" Value="Transparent"/> | ||
<Setter Property="BorderThickness" Value="1"/> | ||
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="{x:Type ws:ListBoxItem}"> | ||
<Border x:Name="Bd" | ||
Background="{TemplateBinding Background}" | ||
BorderBrush="{TemplateBinding BorderBrush}" | ||
BorderThickness="{TemplateBinding BorderThickness}" | ||
CornerRadius="{TemplateBinding CornerRadius}" | ||
Padding="{TemplateBinding Padding}" | ||
SnapsToDevicePixels="true"> | ||
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> | ||
</Border> | ||
<ControlTemplate.Triggers> | ||
<MultiTrigger> | ||
<MultiTrigger.Conditions> | ||
<Condition Property="IsMouseOver" Value="True"/> | ||
</MultiTrigger.Conditions> | ||
<Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.MouseOver.Background}"/> | ||
<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.MouseOver.Border}"/> | ||
</MultiTrigger> | ||
<MultiTrigger> | ||
<MultiTrigger.Conditions> | ||
<Condition Property="Selector.IsSelectionActive" Value="False"/> | ||
<Condition Property="IsSelected" Value="True"/> | ||
</MultiTrigger.Conditions> | ||
<Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedInactive.Background}"/> | ||
<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedInactive.Border}"/> | ||
</MultiTrigger> | ||
<MultiTrigger> | ||
<MultiTrigger.Conditions> | ||
<Condition Property="Selector.IsSelectionActive" Value="True"/> | ||
<Condition Property="IsSelected" Value="True"/> | ||
</MultiTrigger.Conditions> | ||
<Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Background}"/> | ||
<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Border}"/> | ||
</MultiTrigger> | ||
<Trigger Property="IsEnabled" Value="False"> | ||
<Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> | ||
</Trigger> | ||
</ControlTemplate.Triggers> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:ws="https://github.com/OrgEleCho/EleCho.WpfSuite"> | ||
|
||
<SolidColorBrush x:Key="ListBox.Static.Background" Color="#FFFFFFFF"/> | ||
<SolidColorBrush x:Key="ListBox.Static.Border" Color="#FFABADB3"/> | ||
<SolidColorBrush x:Key="ListBox.Disabled.Background" Color="#FFFFFFFF"/> | ||
<SolidColorBrush x:Key="ListBox.Disabled.Border" Color="#FFD9D9D9"/> | ||
<Style TargetType="{x:Type ws:ListBox}"> | ||
<Setter Property="Background" Value="{StaticResource ListBox.Static.Background}"/> | ||
<Setter Property="BorderBrush" Value="{StaticResource ListBox.Static.Border}"/> | ||
<Setter Property="BorderThickness" Value="1"/> | ||
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> | ||
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> | ||
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> | ||
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/> | ||
<Setter Property="ScrollViewer.PanningMode" Value="Both"/> | ||
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/> | ||
<Setter Property="VerticalContentAlignment" Value="Center"/> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="{x:Type ws:ListBox}"> | ||
<Border x:Name="Bd" | ||
Background="{TemplateBinding Background}" | ||
BorderBrush="{TemplateBinding BorderBrush}" | ||
BorderThickness="{TemplateBinding BorderThickness}" | ||
CornerRadius="{TemplateBinding CornerRadius}" | ||
Padding="1" | ||
SnapsToDevicePixels="true"> | ||
<ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}"> | ||
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> | ||
</ScrollViewer> | ||
</Border> | ||
<ControlTemplate.Triggers> | ||
<Trigger Property="IsEnabled" Value="false"> | ||
<Setter Property="Background" TargetName="Bd" Value="{StaticResource ListBox.Disabled.Background}"/> | ||
<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource ListBox.Disabled.Border}"/> | ||
</Trigger> | ||
<MultiTrigger> | ||
<MultiTrigger.Conditions> | ||
<Condition Property="IsGrouping" Value="true"/> | ||
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/> | ||
</MultiTrigger.Conditions> | ||
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/> | ||
</MultiTrigger> | ||
</ControlTemplate.Triggers> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters