Skip to content

Commit eb861b7

Browse files
committed
Code: Agnostic > Demo: implemented visibility of enumeration editors
TODO: make properties common
1 parent 878d08e commit eb861b7

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

code/Agnostic/Enumeration.Controls/Controls/EnumerationBitsetBox.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ public class EnumerationBitsetBox : EnumerationEditorBase {
1111
public EnumerationBitsetBox() {
1212
SetupResourceDictionary();
1313
Grid gridOuter = new();
14-
StyledBorderName borderName = new();
15-
textBlockName = new();
1614
borderName.Child = textBlockName;
1715
Border borderListBox = new();
1816
borderListBox.Child = stackPanelItems;
1917
StyledBorderValue borderValue = new();
20-
textBlockValue = new();
2118
borderValue.Child = textBlockValue;
2219
SetupRows(gridOuter,
2320
new bool[] { false, false, true, false },
@@ -108,10 +105,15 @@ static EnumerationBitsetBox() {
108105

109106
#region property
110107
public static readonly DependencyProperty EnumerationObjectNameProperty = RegisterEnumerationObjectNameProperty(typeof(EnumerationBitsetBox));
108+
public static readonly DependencyProperty IsLabelVisibleProperty = RegisterIsLabelVisibleProperty(typeof(EnumerationBitsetBox));
111109
new public string EnumerationObjectName {
112110
get => (string)GetValue(EnumerationObjectNameProperty);
113111
set => SetValue(EnumerationObjectNameProperty, value);
114112
} //EnumerationObjectName
113+
new public bool IsLabelVisible {
114+
get => (bool)GetValue(IsLabelVisibleProperty);
115+
set => SetValue(IsLabelVisibleProperty, value);
116+
} //IsLabelVisible
115117
#endregion property
116118

117119
Type underlyingType;

code/Agnostic/Enumeration.Controls/Controls/EnumerationBox.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ public class EnumerationBox : EnumerationEditorBase {
77
public EnumerationBox() {
88
SetupResourceDictionary();
99
Grid gridOuter = new();
10-
StyledBorderName borderName = new();
11-
textBlockName = new();
1210
borderName.Child = textBlockName;
1311
Border borderListBox = new();
1412
listBox = new() { BorderThickness = new Thickness(0) };
1513
borderListBox.Child = listBox;
1614
StyledBorderValue borderValue = new();
17-
textBlockValue = new();
1815
borderValue.Child = textBlockValue;
1916
SetupRows(gridOuter,
2017
new bool[] { false, false, false },
@@ -53,10 +50,15 @@ void Populate() {
5350

5451
#region property
5552
public static readonly DependencyProperty EnumerationObjectNameProperty = RegisterEnumerationObjectNameProperty(typeof(EnumerationBox));
53+
public static readonly DependencyProperty IsLabelVisibleProperty = RegisterIsLabelVisibleProperty(typeof(EnumerationBox));
5654
new public string EnumerationObjectName {
5755
get => (string)GetValue(EnumerationObjectNameProperty);
5856
set => SetValue(EnumerationObjectNameProperty, value);
5957
} //EnumerationObjectName
58+
new public bool IsLabelVisible {
59+
get => (bool)GetValue(IsLabelVisibleProperty);
60+
set => SetValue(IsLabelVisibleProperty, value);
61+
} //IsLabelVisible
6062
#endregion property
6163

6264
readonly ListBox listBox;

code/Agnostic/Enumeration.Controls/Controls/EnumerationComboBox.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ public class EnumerationComboBox : EnumerationEditorBase {
77
public EnumerationComboBox() {
88
SetupResourceDictionary();
99
Grid gridOuter = new();
10-
StyledBorderName borderName = new();
11-
textBlockName = new();
1210
borderName.Child = textBlockName;
1311
Border borderListBox = new();
1412
comboBox = new() { BorderThickness = new Thickness(0) };
1513
borderListBox.Child = comboBox;
1614
StyledBorderValue borderValue = new();
17-
textBlockValue = new();
1815
borderValue.Child = textBlockValue;
1916
SetupRows(gridOuter,
2017
new bool[] { false, false, true, false },
@@ -53,10 +50,15 @@ void Populate() {
5350

5451
#region property
5552
public static readonly DependencyProperty EnumerationObjectNameProperty = RegisterEnumerationObjectNameProperty(typeof(EnumerationComboBox));
53+
public static readonly DependencyProperty IsLabelVisibleProperty = RegisterIsLabelVisibleProperty(typeof(EnumerationComboBox));
5654
new public string EnumerationObjectName {
5755
get => (string)GetValue(EnumerationObjectNameProperty);
5856
set => SetValue(EnumerationObjectNameProperty, value);
5957
} //EnumerationObjectName
58+
new public bool IsLabelVisible {
59+
get => (bool)GetValue(IsLabelVisibleProperty);
60+
set => SetValue(IsLabelVisibleProperty, value);
61+
} //IsLabelVisible
6062
#endregion property
6163

6264
readonly ComboBox comboBox;

code/Agnostic/Enumeration.Controls/Controls/EnumerationEditorBase.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ private protected static DependencyProperty RegisterEnumerationObjectNamePropert
3636
}));
3737
} //RegisterEnumerationObjectNameProperty
3838
public string EnumerationObjectName { get; set; }
39+
//
40+
private protected static DependencyProperty RegisterIsLabelVisibleProperty(Type ownerType) {
41+
return DependencyProperty.Register(
42+
name: nameof(IsLabelVisible),
43+
propertyType: typeof(bool),
44+
ownerType: ownerType,
45+
typeMetadata: new FrameworkPropertyMetadata(
46+
(sender, eventArgs) => {
47+
if (sender is not EnumerationEditorBase dependencyObject) return;
48+
dependencyObject.borderName.Visibility = (bool)eventArgs.NewValue
49+
? Visibility.Visible
50+
: Visibility.Collapsed;
51+
}));
52+
} //RegisterIsLabelVisibleProperty
53+
public bool IsLabelVisible { get; set; }
3954

4055
public object Target {
4156
get => target;
@@ -46,9 +61,10 @@ public object Target {
4661

4762
private protected object target;
4863
private protected Type enumType;
49-
private protected MemberList memberList = new();
50-
private protected StyledTextBlockName textBlockName;
51-
private protected StyledTextBlockValue textBlockValue;
64+
private protected readonly MemberList memberList = new();
65+
private protected readonly StyledBorderName borderName = new() { Visibility = Visibility.Collapsed };
66+
private protected readonly StyledTextBlockName textBlockName = new();
67+
private protected readonly StyledTextBlockValue textBlockValue = new();
5268

5369
} //EnumerationEditorBase
5470

code/Demo/Editor.Demo/View/WindowMain.xaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@
5757
</Grid.ColumnDefinitions>
5858
<Border Grid.Column="0">
5959
<Border Style="{StaticResource borderText}">
60-
<controls:EnumerationBox x:Name="enumerationBox" EnumerationObjectName="{DynamicResource ListFruitChoice}"/>
60+
<controls:EnumerationBox x:Name="enumerationBox" EnumerationObjectName="{DynamicResource ListFruitChoice}" IsLabelVisible="True"/>
6161
</Border>
6262
</Border>
6363
<Border Grid.Column="1">
6464
<Border Style="{StaticResource borderText}" Margin="{StaticResource borderMiddle}">
65-
<controls:EnumerationComboBox x:Name="enumerationComboBox" EnumerationObjectName="{DynamicResource ComboFruitChoice}"/>
65+
<controls:EnumerationComboBox x:Name="enumerationComboBox" EnumerationObjectName="{DynamicResource ComboFruitChoice}" IsLabelVisible="True"/>
6666
</Border>
6767
</Border>
6868
<Border Grid.Column="2">
6969
<Border Style="{StaticResource borderText}">
70-
<controls:EnumerationBitsetBox x:Name="enumerationBitsetBox" EnumerationObjectName="{DynamicResource BitsetOptions}"/>
70+
<controls:EnumerationBitsetBox x:Name="enumerationBitsetBox" EnumerationObjectName="{DynamicResource BitsetOptions}" IsLabelVisible="True"/>
7171
</Border>
7272
</Border>
7373
</Grid>
@@ -76,6 +76,9 @@
7676
<StatusBarItem>
7777
<ComboBox x:Name="comboBoxCulture"/>
7878
</StatusBarItem>
79+
<StatusBarItem VerticalContentAlignment="Center">
80+
<CheckBox x:Name="CheckBoxLabelVisibility" IsChecked="True">_Labels</CheckBox>
81+
</StatusBarItem>
7982
</StatusBar>
8083
</Grid>
8184
</Border>

code/Demo/Editor.Demo/View/WindowMain.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using ApplicationSatelliteAssemblyIndex = Agnostic.UI.ApplicationSatelliteAssemblyIndex;
88
using AdvancedApplicationBase = Agnostic.UI.AdvancedApplicationBase;
99
using Keyboard = System.Windows.Input.Keyboard;
10+
using EnumerationEditorBase = Agnostic.UI.Controls.EnumerationEditorBase;
1011

1112
public partial class WindowMain : Window {
1213

@@ -45,6 +46,13 @@ void PopulateEnumerations() {
4546
enumerationBitsetBox.Target = bitsetOption;
4647
enumerationBox.Target = valueOption;
4748
enumerationComboBox.Target = valueOptionCombo;
49+
void SetVisibility(bool value) {
50+
enumerationBitsetBox.IsLabelVisible = value;
51+
enumerationBox.IsLabelVisible = value;
52+
enumerationComboBox.IsLabelVisible = value;
53+
} //SetVisibility
54+
CheckBoxLabelVisibility.Checked += (_, _) => SetVisibility(true);
55+
CheckBoxLabelVisibility.Unchecked += (_, _) => SetVisibility(false);
4856
} //PopulateEnumerations
4957

5058
readonly Main.BitsetOption bitsetOption = default;

0 commit comments

Comments
 (0)