Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit d2e020e

Browse files
committed
fixed editingtag
1 parent d039712 commit d2e020e

File tree

4 files changed

+193
-33
lines changed

4 files changed

+193
-33
lines changed

CookPopularControl/Controls/Others/EditingTag.cs

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
using System;
55
using System.ComponentModel;
66
using System.Globalization;
7+
//using System.Runtime.Remoting.Messaging;
78
using System.Windows;
9+
using System.Windows.Annotations;
10+
using System.Windows.Automation.Peers;
811
using System.Windows.Controls;
912
using System.Windows.Data;
1013
using System.Windows.Markup;
@@ -39,14 +42,20 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
3942
/// <summary>
4043
/// 可编辑标签元素的类型
4144
/// </summary>
42-
public enum EditorType
45+
internal enum EditorType
4346
{
4447
TextBox,
4548
TextBlock,
4649
NumericUpDown,
4750
Other,
4851
}
4952

53+
public enum HeaderAligment
54+
{
55+
Left,
56+
Top,
57+
}
58+
5059
/// <summary>
5160
/// 可编辑标签
5261
/// </summary>
@@ -73,6 +82,36 @@ private bool IsInDesignMode
7382
}
7483

7584

85+
/// <summary>
86+
/// <see cref="EditingTag"/>内容类型,<see cref="EditorType"/>默认为<see cref="TextBox"/>
87+
/// </summary>
88+
internal EditorType EditorType
89+
{
90+
get { return (EditorType)GetValue(EditorTypeProperty); }
91+
set { SetValue(EditorTypeProperty, value); }
92+
}
93+
/// <summary>
94+
/// 提供<see cref="EditorType"/>的依赖属性
95+
/// </summary>
96+
public static readonly DependencyProperty EditorTypeProperty =
97+
DependencyProperty.Register("EditorType", typeof(EditorType), typeof(EditingTag), new PropertyMetadata(default(EditorType), OnPropertiesChanged));
98+
99+
100+
/// <summary>
101+
/// 标头位置,上或者左
102+
/// </summary>
103+
public HeaderAligment Aligment
104+
{
105+
get => (HeaderAligment)GetValue(AligmentProperty);
106+
set => SetValue(AligmentProperty, value);
107+
}
108+
/// <summary>
109+
/// 提供<see cref="Aligment"/>的依赖属性
110+
/// </summary>
111+
public static readonly DependencyProperty AligmentProperty =
112+
DependencyProperty.Register("Aligment", typeof(HeaderAligment), typeof(EditingTag), new PropertyMetadata(default(HeaderAligment)));
113+
114+
76115
/// <summary>
77116
/// 标签头的宽度
78117
/// </summary>
@@ -88,6 +127,21 @@ public GridLength HeaderWidth
88127
DependencyProperty.Register("HeaderWidth", typeof(GridLength), typeof(EditingTag), new PropertyMetadata(GridLength.Auto, OnPropertiesChanged));
89128

90129

130+
/// <summary>
131+
/// 标签头的高度
132+
/// </summary>
133+
public GridLength HeaderHeight
134+
{
135+
get => (GridLength)GetValue(HeaderHeightProperty);
136+
set => SetValue(HeaderHeightProperty, value);
137+
}
138+
/// <summary>
139+
/// 提供<see cref="HeaderHeight"/>的依赖属性
140+
/// </summary>
141+
public static readonly DependencyProperty HeaderHeightProperty =
142+
DependencyProperty.Register("HeaderHeight", typeof(GridLength), typeof(EditingTag), new PropertyMetadata(GridLength.Auto, OnPropertiesChanged));
143+
144+
91145
/// <summary>
92146
/// 标签头的水平定位
93147
/// </summary>
@@ -100,7 +154,7 @@ public HorizontalAlignment HeaderHorizontalAlignment
100154
/// 提供<see cref="HeaderHorizontalAlignment"/>的依赖属性
101155
/// </summary>
102156
public static readonly DependencyProperty HeaderHorizontalAlignmentProperty =
103-
DependencyProperty.Register("HeaderHorizontalAlignment", typeof(HorizontalAlignment), typeof(EditingTag), new PropertyMetadata(default(HorizontalAlignment), OnPropertiesChanged));
157+
DependencyProperty.Register("HeaderHorizontalAlignment", typeof(HorizontalAlignment), typeof(EditingTag), new PropertyMetadata(HorizontalAlignment.Right, OnPropertiesChanged));
104158

105159

106160
/// <summary>
@@ -118,20 +172,6 @@ public VerticalAlignment HeaderVerticalAlignment
118172
DependencyProperty.Register("HeaderVerticalAlignment", typeof(VerticalAlignment), typeof(EditingTag), new PropertyMetadata(default(VerticalAlignment), OnPropertiesChanged));
119173

120174

121-
/// <summary>
122-
/// <see cref="EditingTag"/>内容类型,<see cref="EditorType"/>默认为<see cref="TextBox"/>
123-
/// </summary>
124-
public EditorType EditorType
125-
{
126-
get { return (EditorType)GetValue(EditorTypeProperty); }
127-
set { SetValue(EditorTypeProperty, value); }
128-
}
129-
/// <summary>
130-
/// 提供<see cref="EditorType"/>的依赖属性
131-
/// </summary>
132-
public static readonly DependencyProperty EditorTypeProperty =
133-
DependencyProperty.Register("EditorType", typeof(EditorType), typeof(EditingTag), new PropertyMetadata(default(EditorType), OnPropertiesChanged));
134-
135175
/// <summary>
136176
/// 标签头与内容间距
137177
/// </summary>
@@ -144,7 +184,7 @@ public Thickness HeaderMargin
144184
/// 表示<see cref="HeaderMargin"/>的依赖属性
145185
/// </summary>
146186
public static readonly DependencyProperty HeaderMarginProperty =
147-
DependencyProperty.Register("HeaderMargin", typeof(Thickness), typeof(EditingTag), new PropertyMetadata(default(Thickness), OnPropertiesChanged));
187+
DependencyProperty.Register("HeaderMargin", typeof(Thickness), typeof(EditingTag), new PropertyMetadata(new Thickness(0, 0, 6, 0), OnPropertiesChanged));
148188

149189

150190
private static void OnPropertiesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

CookPopularControl/CookPopularControl.xml

Lines changed: 60 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CookPopularControl/Themes/BaseStyle/Others/EditingTagStyle.xaml

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<pc:EditorTypeToVisibilityConverter x:Key="EditorTypeToVisibilityConverter" />
1212

13-
<Style x:Key="DefaultEditingTagStyle" TargetType="{x:Type pc:EditingTag}" BasedOn="{StaticResource InputControlBaseStyle}">
13+
<!--<Style x:Key="DefaultEditingTagStyle1" TargetType="{x:Type pc:EditingTag}" BasedOn="{StaticResource InputControlBaseStyle}">
1414
<Setter Property="Background" Value="Transparent" />
1515
<Setter Property="HeaderMargin" Value="0,0,6,0" />
1616
<Setter Property="HeaderHorizontalAlignment" Value="Right" />
@@ -102,10 +102,80 @@
102102
</ControlTemplate>
103103
</Setter.Value>
104104
</Setter>
105-
</Style>
105+
</Style>-->
106106

107-
<Style x:Key="EditingTagAddClearButtonStyle" TargetType="{x:Type pc:EditingTag}" BasedOn="{StaticResource DefaultEditingTagStyle}">
107+
<!--<Style x:Key="EditingTagAddClearButtonStyle" TargetType="{x:Type pc:EditingTag}" BasedOn="{StaticResource DefaultEditingTagStyle1}">
108108
<Setter Property="common:TextElementAttached.IsAddClearButton" Value="True" />
109+
</Style>-->
110+
111+
112+
<Style x:Key="DefaultEditingTagStyle" TargetType="{x:Type pc:EditingTag}" BasedOn="{StaticResource ControlBaseStyle}">
113+
<Setter Property="Background" Value="Transparent" />
114+
<Setter Property="HeaderVerticalAlignment" Value="Center" />
115+
<Setter Property="HorizontalContentAlignment" Value="Left" />
116+
<Setter Property="VerticalContentAlignment" Value="Center" />
117+
<Setter Property="Template">
118+
<Setter.Value>
119+
<ControlTemplate TargetType="{x:Type pc:EditingTag}">
120+
<Border x:Name="RootBorder"
121+
Background="{TemplateBinding Background}"
122+
CornerRadius="{TemplateBinding common:FrameworkElementBaseAttached.CornerRadius}"
123+
Padding="{TemplateBinding Padding}"
124+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
125+
<Grid>
126+
<Grid.RowDefinitions>
127+
<RowDefinition Height="{TemplateBinding HeaderHeight}" />
128+
<RowDefinition Height="*" />
129+
</Grid.RowDefinitions>
130+
<Grid.ColumnDefinitions>
131+
<ColumnDefinition Width="{TemplateBinding HeaderWidth}" />
132+
<ColumnDefinition Width="*" />
133+
</Grid.ColumnDefinitions>
134+
<ContentPresenter x:Name="PART_Header"
135+
Grid.RowSpan="2"
136+
Content="{TemplateBinding Header}"
137+
ContentTemplate="{TemplateBinding HeaderTemplate}"
138+
ContentStringFormat="{TemplateBinding HeaderStringFormat}"
139+
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
140+
Margin="{TemplateBinding HeaderMargin}"
141+
HorizontalAlignment="{TemplateBinding HeaderHorizontalAlignment}"
142+
VerticalAlignment="{TemplateBinding HeaderVerticalAlignment}"
143+
TextElement.Foreground="{TemplateBinding Foreground}" />
144+
<ContentPresenter x:Name="PART_Content" Grid.Column="1"
145+
Grid.RowSpan="2"
146+
Content="{TemplateBinding Content}"
147+
ContentTemplate="{TemplateBinding ContentTemplate}"
148+
ContentStringFormat="{TemplateBinding ContentStringFormat}"
149+
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
150+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
151+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
152+
TextElement.Foreground="{TemplateBinding Foreground}" />
153+
</Grid>
154+
</Border>
155+
<ControlTemplate.Triggers>
156+
<Trigger Property="Aligment" Value="Top">
157+
<Setter Property="Height" Value="Auto" />
158+
<Setter Property="HeaderMargin" Value="0,0,0,6" />
159+
<Setter Property="HeaderHorizontalAlignment" Value="Center" />
160+
<Setter Property="Grid.RowSpan" Value="1" TargetName="PART_Header" />
161+
<Setter Property="Grid.ColumnSpan" Value="2" TargetName="PART_Header" />
162+
<Setter Property="Grid.Row" Value="1" TargetName="PART_Content" />
163+
<Setter Property="Grid.RowSpan" Value="1" TargetName="PART_Content" />
164+
<Setter Property="Grid.ColumnSpan" Value="2" TargetName="PART_Content" />
165+
</Trigger>
166+
<Trigger Property="Validation.HasError" Value="True">
167+
<Setter Property="BorderBrush" Value="{DynamicResource FieldValidationErrorBrush}" />
168+
<Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=BorderThickness.Left, Converter={pt:DoubleToThicknessConverter}, ConverterParameter=1.5}" TargetName="RootBorder" />
169+
</Trigger>
170+
<Trigger Property="IsEnabled" Value="False">
171+
<Setter Property="BorderThickness" Value="0" TargetName="RootBorder" />
172+
<Setter Property="Background" Value="{DynamicResource UnEnabledBrush}" />
173+
</Trigger>
174+
</ControlTemplate.Triggers>
175+
</ControlTemplate>
176+
</Setter.Value>
177+
</Setter>
109178
</Style>
110179

180+
111181
</ResourceDictionary>

CookPopularControl/Themes/TextBoxStyle.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
</Style.Triggers>
2929
</Style>
3030

31-
<Style x:Key="ValidationTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBoxStyle}">
31+
<Style x:Key="TextBoxValidationStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBoxStyle}">
3232
<Setter Property="Validation.ErrorTemplate" Value="{DynamicResource ValidationErrorBaseTemplate}" />
3333
</Style>
3434

35-
<Style x:Key="AddClearButtonTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBoxStyle}">
35+
<Style x:Key="TextBoxAddClearButtonStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBoxStyle}">
3636
<Setter Property="common:FrameworkElementBaseAttached.IconMargin" Value="2" />
3737
<Setter Property="common:TextElementAttached.IsAddClearButton" Value="True" />
3838
<Setter Property="common:FrameworkElementBaseAttached.IconWidth" Value="15" />
3939
<Setter Property="common:FrameworkElementBaseAttached.IconHeight" Value="15" />
4040
<Setter Property="common:FrameworkElementBaseAttached.IconMargin" Value="0" />
4141
</Style>
4242

43-
<Style x:Key="ValidationAddClearButtonTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource AddClearButtonTextBoxStyle}">
43+
<Style x:Key="TextBoxValidationAddClearButtonStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBoxAddClearButtonStyle}">
4444
<Setter Property="Validation.ErrorTemplate" Value="{DynamicResource ValidationErrorBaseTemplate}" />
4545
</Style>
4646

0 commit comments

Comments
 (0)