Skip to content

Commit 7f8f412

Browse files
committed
Code: Agnostic > Demo: added/fixed even more enumeration controls,
all controls are done
1 parent b46b341 commit 7f8f412

File tree

7 files changed

+139
-13
lines changed

7 files changed

+139
-13
lines changed

code/Agnostic/Enumeration.Controls/Controls/Enumeration.Controls.xaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
<Setter Property="BorderThickness" Value="0 1 0 0"/>
1010
</Style>
1111
<Style TargetType="CheckBox">
12-
<Setter Property="Margin" Value="8 5 0 0"/>
12+
<Setter Property="Margin" Value="8 5 8 0"/>
13+
</Style>
14+
<Style TargetType="ComboBox">
15+
<Setter Property="Margin" Value="4 3 4 0"/>
16+
</Style>
17+
<Style x:Key="texBlockName" TargetType="TextBlock">
18+
<Setter Property="Margin" Value="4 0 4 0"/>
19+
</Style>
20+
<Style x:Key="texBlockValue" TargetType="TextBlock">
21+
<Setter Property="Margin" Value="4 0 4 0"/>
1322
</Style>
1423
</ResourceDictionary>

code/Agnostic/Enumeration.Controls/Controls/EnumerationBitsetBox.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
<RowDefinition Height="Auto"/>
1616
</Grid.RowDefinitions>
1717
<Border Grid.Row="0" Style="{StaticResource borderName}">
18-
<TextBlock x:Name="textBlockName"/>
18+
<TextBlock x:Name="textBlockName" Style="{StaticResource texBlockName}"/>
1919
</Border>
2020
<Border Grid.Row="1">
2121
<StackPanel x:Name="stackPanelItems"/>
2222
</Border>
2323
<Border Grid.Row="2" Style="{StaticResource borderValue}">
24-
<TextBlock x:Name="textBlockValue"/>
24+
<TextBlock x:Name="textBlockValue" Style="{StaticResource texBlockValue}"/>
2525
</Border>
2626
</Grid>
2727
</UserControl>

code/Agnostic/Enumeration.Controls/Controls/EnumerationBox.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
<RowDefinition Height="Auto"/>
1616
</Grid.RowDefinitions>
1717
<Border Grid.Row="0" Style="{StaticResource borderName}">
18-
<TextBlock x:Name="textBlockName"/>
18+
<TextBlock x:Name="textBlockName" Style="{StaticResource texBlockName}"/>
1919
</Border>
2020
<Border Grid.Row="1">
2121
<StackPanel>
22-
<ListBox x:Name="listBox"/>
22+
<ListBox x:Name="listBox" BorderThickness="0"/>
2323
</StackPanel>
2424
</Border>
2525
<Border Grid.Row="2" Style="{StaticResource borderValue}">
26-
<TextBlock x:Name="textBlockValue"/>
26+
<TextBlock x:Name="textBlockValue" Style="{StaticResource texBlockValue}"/>
2727
</Border>
2828
</Grid>
2929
</UserControl>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<UserControl x:Class="SA.Agnostic.UI.Controls.EnumerationComboBox"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
4+
<UserControl.Resources>
5+
<ResourceDictionary>
6+
<ResourceDictionary.MergedDictionaries>
7+
<ResourceDictionary Source="Enumeration.Controls.xaml"/>
8+
</ResourceDictionary.MergedDictionaries>
9+
</ResourceDictionary>
10+
</UserControl.Resources>
11+
<Grid>
12+
<Grid.RowDefinitions>
13+
<RowDefinition Height="Auto"/>
14+
<RowDefinition Height="Auto"/>
15+
<RowDefinition Height="*"/>
16+
<RowDefinition Height="Auto"/>
17+
</Grid.RowDefinitions>
18+
<Border Grid.Row="0" Style="{StaticResource borderName}">
19+
<TextBlock x:Name="textBlockName" Style="{StaticResource texBlockName}"/>
20+
</Border>
21+
<Border Grid.Row="1">
22+
<ComboBox x:Name="comboBox"/>
23+
</Border>
24+
<Border Grid.Row="3"/>
25+
<Border Grid.Row="3" Style="{StaticResource borderValue}">
26+
<TextBlock x:Name="textBlockValue" Style="{StaticResource texBlockValue}"/>
27+
</Border>
28+
</Grid>
29+
</UserControl>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
namespace SA.Agnostic.UI.Controls {
2+
using System.Windows.Controls;
3+
using IEnumerable = System.Collections.IEnumerable;
4+
using MemberList = System.Collections.Generic.List<Enumerations.EnumerationItemBase>;
5+
using Type = System.Type;
6+
7+
public partial class EnumerationComboBox : UserControl {
8+
9+
public EnumerationComboBox() {
10+
InitializeComponent();
11+
} //EnumerationBox
12+
13+
void SetTarget(object value) {
14+
memberList.Clear();
15+
comboBox.Items.Clear();
16+
textBlockValue.Text = null;
17+
target = value;
18+
enumType = value.GetType();
19+
Type type = typeof(Enumerations.Enumeration<>);
20+
Type enumerationType = type.MakeGenericType(new Type[] { enumType });
21+
object enumeration = System.Activator.CreateInstance(enumerationType);
22+
IEnumerable enumerable = (IEnumerable)enumeration;
23+
foreach (object @object in enumerable)
24+
memberList.Add((Enumerations.EnumerationItemBase)@object);
25+
Populate();
26+
} //SetTarget
27+
28+
void Populate() {
29+
int index = 0;
30+
int indexToSelect = 0;
31+
foreach (Enumerations.EnumerationItemBase item in memberList) {
32+
ListBoxItem visualItem = new() { Content = item.DisplayName, DataContext = index++ };
33+
comboBox.Items.Add(visualItem);
34+
} //loop
35+
comboBox.SelectionChanged += (sender, eventArgs) => {
36+
if (sender is not ComboBox comboBoxSender) return;
37+
if (comboBoxSender.SelectedIndex < 0) return;
38+
if (comboBoxSender.SelectedItem is not ListBoxItem item) return;
39+
int index = (int)item.DataContext;
40+
target = memberList[index].GenericEnumValue;
41+
textBlockValue.Text = memberList[index].DisplayName;
42+
}; //listBox.SelectionChanged
43+
comboBox.SelectedIndex = indexToSelect;
44+
} //Populate
45+
46+
public object Target {
47+
get => target;
48+
set {
49+
SetTarget(value);
50+
} //Target set
51+
} //set
52+
53+
public string TargetObjectName {
54+
get => targetObjectName;
55+
set {
56+
targetObjectName = value;
57+
textBlockName.Text = value;
58+
} //set TargetObjectName
59+
} //TargetObjectName
60+
61+
string targetObjectName;
62+
Type enumType;
63+
private protected object target;
64+
readonly MemberList memberList = new();
65+
66+
} //class EnumerationComboBox
67+
68+
}
69+

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
<ResourceDictionary>
1212
<ResourceDictionary.MergedDictionaries>
1313
<ResourceDictionary Source="pack://application:,,,/Demo.ResourceDictionary.Source;component/Shared.xaml"/>
14+
<ResourceDictionary>
15+
<Style x:Key="borderText" TargetType="Border">
16+
<Setter Property="BorderThickness" Value="1"/>
17+
<Setter Property="BorderBrush" Value="{x:Static SystemColors.ActiveBorderBrush}"/>
18+
<Setter Property="Margin" Value="12 6 12 6"/>
19+
</Style>
20+
<Thickness x:Key="borderMiddle">0 6 0 6</Thickness>
21+
</ResourceDictionary>
1422
</ResourceDictionary.MergedDictionaries>
1523
</ResourceDictionary>
1624
</Window.Resources>
@@ -23,16 +31,24 @@
2331
<Border Grid.Row="0">
2432
<Grid>
2533
<Grid.ColumnDefinitions>
26-
<ColumnDefinition Width="*"/>
2734
<ColumnDefinition Width="Auto"/>
28-
<ColumnDefinition Width="*"/>
35+
<ColumnDefinition Width="Auto"/>
36+
<ColumnDefinition Width="Auto"/>
2937
</Grid.ColumnDefinitions>
3038
<Border Grid.Column="0">
31-
<controls:EnumerationBox x:Name="enumerationBox"/>
39+
<Border Style="{StaticResource borderText}">
40+
<controls:EnumerationBox x:Name="enumerationBox" BorderThickness="0"/>
41+
</Border>
42+
</Border>
43+
<Border Grid.Column="1">
44+
<Border Style="{StaticResource borderText}" Margin="{StaticResource borderMiddle}">
45+
<controls:EnumerationComboBox x:Name="enumerationComboBox" BorderThickness="0"/>
46+
</Border>
3247
</Border>
33-
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
3448
<Border Grid.Column="2">
35-
<controls:EnumerationBitsetBox x:Name="enumerationBitsetBox"/>
49+
<Border Style="{StaticResource borderText}">
50+
<controls:EnumerationBitsetBox x:Name="enumerationBitsetBox" BorderThickness="0"/>
51+
</Border>
3652
</Border>
3753
</Grid>
3854
</Border>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ public partial class WindowMain : Window {
66

77
public WindowMain() {
88
InitializeComponent();
9-
enumerationBitsetBox.TargetObjectName = "bitset Options";
10-
enumerationBitsetBox.Target = bitsetOption;
119
enumerationBox.TargetObjectName = "value Option";
1210
enumerationBox.Target = valueOption;
11+
enumerationComboBox.Target = valueOptionCombo;
12+
enumerationComboBox.TargetObjectName = enumerationBox.TargetObjectName;
13+
enumerationBitsetBox.TargetObjectName = "bitset Options";
14+
enumerationBitsetBox.Target = bitsetOption;
1315
} //WindowMain
1416

1517
protected override void OnContentRendered(EventArgs eventArgs) {
@@ -18,6 +20,7 @@ protected override void OnContentRendered(EventArgs eventArgs) {
1820

1921
Main.BitsetOption bitsetOption = default;
2022
Main.ValueOption valueOption = default;
23+
Main.ValueOption valueOptionCombo = default;
2124

2225
} //class WindowMain
2326

0 commit comments

Comments
 (0)