From be55d068109c79be514183b22df1c53f76f96d92 Mon Sep 17 00:00:00 2001 From: YkTru Date: Fri, 20 Sep 2024 17:01:44 -0400 Subject: [PATCH] - Made "FormComponent" more concrete with TextBox, Checkbox, Combobox - renamed all consequentially - updated related xaml --- src/Samples/Samples.generated.sln | 121 +++++++++++ .../SubModelSelectedItem.Core/FsWPF.fs | 8 +- .../SubModelSelectedItem.Core/Program.fs | 195 +++++++++--------- .../SubModelSelectedItem/MainWindow.xaml | 29 ++- .../SubModelSelectedItem/MainWindow.xaml.cs | 7 + 5 files changed, 254 insertions(+), 106 deletions(-) create mode 100644 src/Samples/Samples.generated.sln diff --git a/src/Samples/Samples.generated.sln b/src/Samples/Samples.generated.sln new file mode 100644 index 00000000..67ad07ba --- /dev/null +++ b/src/Samples/Samples.generated.sln @@ -0,0 +1,121 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capabilities", "Capabilities\Capabilities.csproj", "{50BE7B69-76EF-4A2F-956D-040F62645E48}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventBindingsAndBehaviors", "EventBindingsAndBehaviors\EventBindingsAndBehaviors.csproj", "{5389CE5E-4D9E-4A86-BFF3-B6721BBA4D0E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileDialogs", "FileDialogs\FileDialogs.csproj", "{57352DDA-A661-46B8-A0FE-232A8C72BC1A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileDialogsCmdMsg", "FileDialogsCmdMsg\FileDialogsCmdMsg.csproj", "{A1A57765-4218-42C2-9A0B-9DD20945EEE6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Multiselect", "Multiselect\Multiselect.csproj", "{7C14D91F-D43A-4A14-B076-F3D16BFD3B8A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewWindow", "NewWindow\NewWindow.csproj", "{8CD66A83-01AD-433E-B41A-E7772C1A20C5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneWaySeq", "OneWaySeq\OneWaySeq.csproj", "{E69B6B61-6056-4B4D-BC9A-03F41C7A9EDC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SingleCounter", "SingleCounter\SingleCounter.csproj", "{38238E19-8FC9-4E61-B6E0-4AD42B077574}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sticky", "Sticky\Sticky.csproj", "{097E0802-A94D-4599-84B8-6935EA9FCB01}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubModel", "SubModel\SubModel.csproj", "{AFD3D3BC-2229-4D5C-9F37-E4C5594CFD36}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubModelOpt", "SubModelOpt\SubModelOpt.csproj", "{CC68E5BA-B417-4142-ACF4-4AB267904082}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubModelSelectedItem", "SubModelSelectedItem\SubModelSelectedItem.csproj", "{C7CF229D-D0A0-402B-818F-999A7F08725E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubModelSeq", "SubModelSeq\SubModelSeq.csproj", "{13684CFF-E918-47E5-8983-C68A2CB466B7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubModelStatic", "SubModelStatic\SubModelStatic.csproj", "{61E5C65D-796D-44CF-BFFC-2E7F66681DA2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Threading", "Threading\Threading.csproj", "{9F874D8C-C33C-42D9-AAD6-CC94CC1DC177}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UiBoundCmdParam", "UiBoundCmdParam\UiBoundCmdParam.csproj", "{A1D12300-4F10-42E6-907D-C98D84599FF7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Validation", "Validation\Validation.csproj", "{33A5664F-B468-444B-BB9C-91D6ACF2FCE7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {50BE7B69-76EF-4A2F-956D-040F62645E48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {50BE7B69-76EF-4A2F-956D-040F62645E48}.Debug|Any CPU.Build.0 = Debug|Any CPU + {50BE7B69-76EF-4A2F-956D-040F62645E48}.Release|Any CPU.ActiveCfg = Release|Any CPU + {50BE7B69-76EF-4A2F-956D-040F62645E48}.Release|Any CPU.Build.0 = Release|Any CPU + {5389CE5E-4D9E-4A86-BFF3-B6721BBA4D0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5389CE5E-4D9E-4A86-BFF3-B6721BBA4D0E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5389CE5E-4D9E-4A86-BFF3-B6721BBA4D0E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5389CE5E-4D9E-4A86-BFF3-B6721BBA4D0E}.Release|Any CPU.Build.0 = Release|Any CPU + {57352DDA-A661-46B8-A0FE-232A8C72BC1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57352DDA-A661-46B8-A0FE-232A8C72BC1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57352DDA-A661-46B8-A0FE-232A8C72BC1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57352DDA-A661-46B8-A0FE-232A8C72BC1A}.Release|Any CPU.Build.0 = Release|Any CPU + {A1A57765-4218-42C2-9A0B-9DD20945EEE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1A57765-4218-42C2-9A0B-9DD20945EEE6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1A57765-4218-42C2-9A0B-9DD20945EEE6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1A57765-4218-42C2-9A0B-9DD20945EEE6}.Release|Any CPU.Build.0 = Release|Any CPU + {7C14D91F-D43A-4A14-B076-F3D16BFD3B8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C14D91F-D43A-4A14-B076-F3D16BFD3B8A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C14D91F-D43A-4A14-B076-F3D16BFD3B8A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C14D91F-D43A-4A14-B076-F3D16BFD3B8A}.Release|Any CPU.Build.0 = Release|Any CPU + {8CD66A83-01AD-433E-B41A-E7772C1A20C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CD66A83-01AD-433E-B41A-E7772C1A20C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CD66A83-01AD-433E-B41A-E7772C1A20C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CD66A83-01AD-433E-B41A-E7772C1A20C5}.Release|Any CPU.Build.0 = Release|Any CPU + {E69B6B61-6056-4B4D-BC9A-03F41C7A9EDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E69B6B61-6056-4B4D-BC9A-03F41C7A9EDC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E69B6B61-6056-4B4D-BC9A-03F41C7A9EDC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E69B6B61-6056-4B4D-BC9A-03F41C7A9EDC}.Release|Any CPU.Build.0 = Release|Any CPU + {38238E19-8FC9-4E61-B6E0-4AD42B077574}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {38238E19-8FC9-4E61-B6E0-4AD42B077574}.Debug|Any CPU.Build.0 = Debug|Any CPU + {38238E19-8FC9-4E61-B6E0-4AD42B077574}.Release|Any CPU.ActiveCfg = Release|Any CPU + {38238E19-8FC9-4E61-B6E0-4AD42B077574}.Release|Any CPU.Build.0 = Release|Any CPU + {097E0802-A94D-4599-84B8-6935EA9FCB01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {097E0802-A94D-4599-84B8-6935EA9FCB01}.Debug|Any CPU.Build.0 = Debug|Any CPU + {097E0802-A94D-4599-84B8-6935EA9FCB01}.Release|Any CPU.ActiveCfg = Release|Any CPU + {097E0802-A94D-4599-84B8-6935EA9FCB01}.Release|Any CPU.Build.0 = Release|Any CPU + {AFD3D3BC-2229-4D5C-9F37-E4C5594CFD36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AFD3D3BC-2229-4D5C-9F37-E4C5594CFD36}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AFD3D3BC-2229-4D5C-9F37-E4C5594CFD36}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AFD3D3BC-2229-4D5C-9F37-E4C5594CFD36}.Release|Any CPU.Build.0 = Release|Any CPU + {CC68E5BA-B417-4142-ACF4-4AB267904082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CC68E5BA-B417-4142-ACF4-4AB267904082}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CC68E5BA-B417-4142-ACF4-4AB267904082}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CC68E5BA-B417-4142-ACF4-4AB267904082}.Release|Any CPU.Build.0 = Release|Any CPU + {C7CF229D-D0A0-402B-818F-999A7F08725E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C7CF229D-D0A0-402B-818F-999A7F08725E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C7CF229D-D0A0-402B-818F-999A7F08725E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C7CF229D-D0A0-402B-818F-999A7F08725E}.Release|Any CPU.Build.0 = Release|Any CPU + {13684CFF-E918-47E5-8983-C68A2CB466B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {13684CFF-E918-47E5-8983-C68A2CB466B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {13684CFF-E918-47E5-8983-C68A2CB466B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {13684CFF-E918-47E5-8983-C68A2CB466B7}.Release|Any CPU.Build.0 = Release|Any CPU + {61E5C65D-796D-44CF-BFFC-2E7F66681DA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {61E5C65D-796D-44CF-BFFC-2E7F66681DA2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61E5C65D-796D-44CF-BFFC-2E7F66681DA2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {61E5C65D-796D-44CF-BFFC-2E7F66681DA2}.Release|Any CPU.Build.0 = Release|Any CPU + {9F874D8C-C33C-42D9-AAD6-CC94CC1DC177}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F874D8C-C33C-42D9-AAD6-CC94CC1DC177}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F874D8C-C33C-42D9-AAD6-CC94CC1DC177}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F874D8C-C33C-42D9-AAD6-CC94CC1DC177}.Release|Any CPU.Build.0 = Release|Any CPU + {A1D12300-4F10-42E6-907D-C98D84599FF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1D12300-4F10-42E6-907D-C98D84599FF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1D12300-4F10-42E6-907D-C98D84599FF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1D12300-4F10-42E6-907D-C98D84599FF7}.Release|Any CPU.Build.0 = Release|Any CPU + {33A5664F-B468-444B-BB9C-91D6ACF2FCE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {33A5664F-B468-444B-BB9C-91D6ACF2FCE7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {33A5664F-B468-444B-BB9C-91D6ACF2FCE7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {33A5664F-B468-444B-BB9C-91D6ACF2FCE7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EAE8C9E3-06B3-4889-8E00-600FB55BEA5E} + EndGlobalSection +EndGlobal diff --git a/src/Samples/SubModelSelectedItem.Core/FsWPF.fs b/src/Samples/SubModelSelectedItem.Core/FsWPF.fs index 50cfb3db..b3deda90 100644 --- a/src/Samples/SubModelSelectedItem.Core/FsWPF.fs +++ b/src/Samples/SubModelSelectedItem.Core/FsWPF.fs @@ -2,7 +2,13 @@ namespace FsWPF open System open System.Windows.Data +open System.Globalization +open System.Windows +open System.Windows.Controls open Elmish.WPF.Samples.SubModelSelectedItem.Program open Form -//[toDo] DataTemplateSelector +type ComponentsTemplateSelector() = + inherit DataTemplateSelector() + +// Properties for each DataTemplate diff --git a/src/Samples/SubModelSelectedItem.Core/Program.fs b/src/Samples/SubModelSelectedItem.Core/Program.fs index b68909b3..7d0e5ca3 100644 --- a/src/Samples/SubModelSelectedItem.Core/Program.fs +++ b/src/Samples/SubModelSelectedItem.Core/Program.fs @@ -12,7 +12,6 @@ open Elmish.WPF • [?] would something other than "SubModelSelectItem" be a better option for safety? • [?] how to better seperate *specific children fields* within dynamic bindings in "Form_VM.Components"? Just comment? Helpers? - • refactor: make FormComponent more concrete = TextBox, CheckBox, ComboBox • add: DataTemplateSelector • add: get focus after adding + selecting FormComponent (Behavior) @@ -28,13 +27,13 @@ module FormComponentHelpers = prefix + randomNumber () -module FormComponentA = +module TextBoxComponent = - type Model = { Id: Guid; Name: string } + type Model = { Id: Guid; Text: string } let create () = { Id = Guid.NewGuid() - Name = FormComponentHelpers.generateName "A_" } + Text = FormComponentHelpers.generateName "TextBox_" } let init () = create () @@ -45,17 +44,19 @@ module FormComponentA = | DummyMsg -> m -module FormComponentB = +module CheckBoxComponent = - type Model = { Id: Guid; Name: string } + type Model = + { Id: Guid + Label: string + IsChecked: bool } let create () = { Id = Guid.NewGuid() - Name = FormComponentHelpers.generateName "B_" } + Label = FormComponentHelpers.generateName "CheckBox_" + IsChecked = false } - let init () = - { Id = Guid.NewGuid() - Name = "B_" + Random().Next(10000, 100000).ToString() } + let init () = create () type Msg = DummyMsg @@ -64,13 +65,17 @@ module FormComponentB = | DummyMsg -> m -module FormComponentC = +module ComboBoxComponent = - type Model = { Id: Guid; Name: string } + type Model = + { Id: Guid + Name: string // header of GroupBox containing it + Items: string list } let create () = { Id = Guid.NewGuid() - Name = FormComponentHelpers.generateName "C_" } + Name = FormComponentHelpers.generateName "ComboBox_" + Items = [ "Item 1"; "Item 2"; "Item 3" ] } let init () = create () @@ -84,44 +89,41 @@ module FormComponentC = module Form = type Components = - | FormComponentA of FormComponentA.Model - | FormComponentB of FormComponentB.Model - | FormComponentC of FormComponentC.Model - + | TextBox of TextBoxComponent.Model + | CheckBox of CheckBoxComponent.Model + | ComboBox of ComboBoxComponent.Model type Model = { Components: Components list SelectedComponent: Guid option //• SubModels - FormComponentA_Model: FormComponentA.Model - FormComponentB_Model: FormComponentB.Model - FormComponentC_Model: FormComponentC.Model } - + TextBox_Model: TextBoxComponent.Model + CheckBox_Model: CheckBoxComponent.Model + ComboBox_Model: ComboBoxComponent.Model } let components_Mock = [ for _ in 1..3 do - yield FormComponentA(FormComponentA.create ()) - yield FormComponentB(FormComponentB.create ()) - yield FormComponentC(FormComponentC.create ()) ] - + yield TextBox(TextBoxComponent.create ()) + yield CheckBox(CheckBoxComponent.create ()) + yield ComboBox(ComboBoxComponent.create ()) ] let init () = { Components = components_Mock SelectedComponent = None //• SubModels - FormComponentA_Model = FormComponentA.init () - FormComponentB_Model = FormComponentB.init () - FormComponentC_Model = FormComponentC.init () } + TextBox_Model = TextBoxComponent.init () + CheckBox_Model = CheckBoxComponent.init () + ComboBox_Model = ComboBoxComponent.init () } type Msg = | Select of Guid option - | AddFormComponentA - | AddFormComponentB - | AddFormComponentC + | AddTextBox + | AddCheckBox + | AddComboBox //• SubMsgs - | TextBoxA_Msg of FormComponentA.Msg - | TextBoxB_Msg of FormComponentB.Msg - | TextBoxC_Msg of FormComponentC.Msg + | TextBox_Msg of TextBoxComponent.Msg + | CheckBox_Msg of CheckBoxComponent.Msg + | ComboBoxC_Msg of ComboBoxComponent.Msg [] module Form = @@ -133,94 +135,96 @@ module Form = let getComponentId component_ = match component_ with - | FormComponentA a -> a.Id - | FormComponentB b -> b.Id - | FormComponentC c -> c.Id + | TextBox a -> a.Id + | CheckBox b -> b.Id + | ComboBox c -> c.Id let getComponentName component_ = match component_ with - | FormComponentA a -> a.Name - | FormComponentB b -> b.Name - | FormComponentC c -> c.Name + | TextBox a -> a.Text + | CheckBox b -> b.Label + | ComboBox c -> c.Name let isSelected selectedId component_ = match selectedId, component_ with - | Some id, FormComponentA a -> a.Id = id - | Some id, FormComponentB b -> b.Id = id - | Some id, FormComponentC c -> c.Id = id + | Some id, TextBox a -> a.Id = id + | Some id, CheckBox b -> b.Id = id + | Some id, ComboBox c -> c.Id = id | _ -> false - let insertComponentAfterSelected selectedComponent newComponent components = + let insertComponentAfterSelected selectedComponent newComponent components = - // sample purpose: make explicit that a new component has been added - let prependNewName component_ = - match component_ with - | FormComponentA a -> FormComponentA { a with Name = "#New# " + a.Name } - | FormComponentB b -> FormComponentB { b with Name = "#New# " + b.Name } - | FormComponentC c -> FormComponentC { c with Name = "#New# " + c.Name } + // sample purpose: make explicit that a new component has been added + let prependNewName component_ = + match component_ with + | TextBox a -> TextBox { a with Text = "#New# " + a.Text } + | CheckBox b -> CheckBox { b with Label = "#New# " + b.Label } + | ComboBox c -> ComboBox { c with Name = "#New# " + c.Name } - let newComponentWithPrependedName = prependNewName newComponent + let newComponentWithPrependedName = prependNewName newComponent - match selectedComponent with - | None -> - // If no component is selected, append the new one to the end - components @ [ newComponentWithPrependedName ] - | Some selectedId -> - let rec insertAfterSelected = - function - | [] -> [ newComponentWithPrependedName ] - | comp :: rest when getComponentId comp = selectedId -> comp :: newComponentWithPrependedName :: rest - | comp :: rest -> comp :: insertAfterSelected rest + match selectedComponent with + | None -> + // If no component is selected, append the new one to the end + components @ [ newComponentWithPrependedName ] + | Some selectedId -> + let rec insertAfterSelected = + function + | [] -> [ newComponentWithPrependedName ] + | comp :: rest when getComponentId comp = selectedId -> + comp :: newComponentWithPrependedName :: rest + | comp :: rest -> comp :: insertAfterSelected rest - insertAfterSelected components + insertAfterSelected components let update msg m = match msg with | Select entityId -> { m with SelectedComponent = entityId } - | AddFormComponentA -> - let newComponent = FormComponentA(FormComponentA.create ()) + | AddTextBox -> + let newTextBox = TextBox(TextBoxComponent.create ()) - let newComponentId = - match newComponent with - | FormComponentA a -> a.Id + let newTextBoxId = + match newTextBox with + | TextBox a -> a.Id | _ -> Guid.Empty { m with - Components = insertComponentAfterSelected m.SelectedComponent newComponent m.Components - SelectedComponent = Some newComponentId } + Components = insertComponentAfterSelected m.SelectedComponent newTextBox m.Components + SelectedComponent = Some newTextBoxId } - | AddFormComponentB -> - let newComponent = FormComponentB(FormComponentB.create ()) + | AddCheckBox -> + let newCheckBox = CheckBox(CheckBoxComponent.create ()) - let newComponentId = - match newComponent with - | FormComponentB b -> b.Id + let newCheckBoxId = + match newCheckBox with + | CheckBox b -> b.Id | _ -> Guid.Empty { m with - Components = insertComponentAfterSelected m.SelectedComponent newComponent m.Components - SelectedComponent = Some newComponentId } + Components = insertComponentAfterSelected m.SelectedComponent newCheckBox m.Components + SelectedComponent = Some newCheckBoxId } - | AddFormComponentC -> - let newComponent = FormComponentC(FormComponentC.create ()) + | AddComboBox -> + let newComboBox = ComboBox(ComboBoxComponent.create ()) - let newComponentId = - match newComponent with - | FormComponentC c -> c.Id + let newComboBoxId = + match newComboBox with + | ComboBox c -> c.Id | _ -> Guid.Empty { m with - Components = insertComponentAfterSelected m.SelectedComponent newComponent m.Components - SelectedComponent = Some newComponentId } + Components = insertComponentAfterSelected m.SelectedComponent newComboBox m.Components + SelectedComponent = Some newComboBoxId } //• SubModels - | TextBoxA_Msg msg -> { m with FormComponentA_Model = FormComponentA.update msg m.FormComponentA_Model } - | TextBoxB_Msg msg -> { m with FormComponentB_Model = FormComponentB.update msg m.FormComponentB_Model } - | TextBoxC_Msg msg -> { m with FormComponentC_Model = FormComponentC.update msg m.FormComponentC_Model } + | TextBox_Msg msg -> { m with TextBox_Model = TextBoxComponent.update msg m.TextBox_Model } + | CheckBox_Msg msg -> { m with CheckBox_Model = CheckBoxComponent.update msg m.CheckBox_Model } + | ComboBoxC_Msg msg -> { m with ComboBox_Model = ComboBoxComponent.update msg m.ComboBox_Model } +//# ViewModel/Bindings open Form.Form // ugly [] @@ -248,6 +252,7 @@ type Form_VM(args) = "") ]) )) + // I don't like the stringly-typed nature of this binding member _.SelectedEntity with get () = @@ -287,9 +292,9 @@ type Form_VM(args) = match m.Components |> List.find (fun e -> getComponentId e = id) with - | Form.Components.FormComponentA _ -> "Type: A" - | Form.Components.FormComponentB _ -> "Type: B" - | Form.Components.FormComponentC _ -> "Type: C" + | Form.Components.TextBox _ -> "Type: A" + | Form.Components.CheckBox _ -> "Type: B" + | Form.Components.ComboBox _ -> "Type: C" sprintf "Selected: Name = %s, Index = %d, %s" name index componentType | None -> "No selection")) @@ -297,9 +302,9 @@ type Form_VM(args) = //• Commands - member _.AddTextBoxA = base.Get () (Binding.CmdT.setAlways Form.AddFormComponentA) - member _.AddTextBoxB = base.Get () (Binding.CmdT.setAlways Form.AddFormComponentB) - member _.AddTextBoxC = base.Get () (Binding.CmdT.setAlways Form.AddFormComponentC) + member _.AddTextBox = base.Get () (Binding.CmdT.setAlways Form.AddTextBox) + member _.AddCheckBox = base.Get () (Binding.CmdT.setAlways Form.AddCheckBox) + member _.AddComboBox = base.Get () (Binding.CmdT.setAlways Form.AddComboBox) member _.SelectRandom = base.Get @@ -308,9 +313,9 @@ type Form_VM(args) = let randomEntity = m.Components.Item(Random().Next(m.Components.Length)) match randomEntity with - | Form.Components.FormComponentA aModel -> Some aModel.Id - | Form.Components.FormComponentB bModel -> Some bModel.Id - | Form.Components.FormComponentC cModel -> Some cModel.Id + | Form.Components.TextBox aModel -> Some aModel.Id + | Form.Components.CheckBox bModel -> Some bModel.Id + | Form.Components.ComboBox cModel -> Some cModel.Id |> Form.Msg.Select)) member _.Deselect = diff --git a/src/Samples/SubModelSelectedItem/MainWindow.xaml b/src/Samples/SubModelSelectedItem/MainWindow.xaml index 63861b95..e7493ec4 100644 --- a/src/Samples/SubModelSelectedItem/MainWindow.xaml +++ b/src/Samples/SubModelSelectedItem/MainWindow.xaml @@ -3,12 +3,14 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:fsWPF="clr-namespace:FsWPF;assembly=SubModelSelectedItem.Core" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:Elmish.WPF.Samples.SubModelSelectedItem.Program;assembly=SubModelSelectedItem.Core" Title="SubModelSelectedItem+StaticBindings" - Width="600" + Width="480" d:DataContext="{d:DesignInstance Type=vm:Form_VM, IsDesignTimeCreatable=True}" + SizeToContent="Height" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> @@ -24,19 +26,19 @@ @@ -60,28 +62,35 @@ - + + + + - - + + { + if (e.Key == System.Windows.Input.Key.Escape) + { + Close(); + } + }; } } }