Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing a WPF Tab Control with Elmish.WPF (F#)?

Tags:

f#

elmish-wpf

I have a complex WPF Tab control inside a main main window, all in C#, using .NET Framework. The main window provides a consistent main menu and a contentcontrol holding the Tab Control.

Each tab of the tab control presents a different usercontrol using a viewmodel specific to each usercontrol.

Before going down the rabbit hole, I need to know if Elmish.WPF can provide the proper F# backing for this situation.

In studying the examples, the key handoff to Elmish.WPF seems to occur with:

Program.mkSimpleWpf App.init App.update bindings

Once the main window and the first tab are presented, can init, update, and bindings be discriminated unions allowing the user to switch between the tabs? If so, can the new tab state be "fed" into Elmish.WPF?

Any help or suggestions would be most appreciated.

TIA

(To further complicate matters, one of the tabs presents a datagrid with custom adorners for list manipulation).

like image 793
Alan Wayne Avatar asked Dec 05 '25 04:12

Alan Wayne


1 Answers

I am a maintainer of Elmish.WPF.

I have a complex WPF Tab control inside a main main window, all in C#, using .NET Framework. The main window provides a consistent main menu and a contentcontrol holding the Tab Control.

Each tab of the tab control presents a different usercontrol using a viewmodel specific to each usercontrol.

Before going down the rabbit hole, I need to know if Elmish.WPF can provide the proper F# backing for this situation.

For this scenario, yes, there should be no problems. We currently have no samples in the repo that use tab controls, but in general, everything you can achieve with bindings (and then some) in WPF can also be achieved in Elmish.WPF. Please open an issue in the Elmish.WPF repo if you are unable to get it working after studying the samples and official tutorial.

Once the main window and the first tab are presented, can init, update, and bindings be discriminated unions allowing the user to switch between the tabs? If so, can the new tab state be "fed" into Elmish.WPF?

I am a bit unsure what you're asking here, but it is possible you are confused about some central MVU concepts. The Elmish.WPF tutorial or other resources mentioned in the Elmish.WPF readme may be of help. In general, the message type is a discriminated union, and the model is a record. On the other hand, init, update and bindings are functions that act on the model and the messages.

(To further complicate matters, one of the tabs presents a datagrid with custom adorners for list manipulation).

I'm no expert on WPF tab controls, but AFAIK the contents of the tab should not impact in any way whether Elmish.WPF works with a tab control.

like image 94
cmeeren Avatar answered Dec 08 '25 02:12

cmeeren