Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Third Party Controls - Best Practice #412

Open
ChernayaKoshka opened this issue Aug 17, 2021 · 1 comment
Open

Creating Third Party Controls - Best Practice #412

ChernayaKoshka opened this issue Aug 17, 2021 · 1 comment

Comments

@ChernayaKoshka
Copy link

ChernayaKoshka commented Aug 17, 2021

Hello,

At work I have developed numerous control libraries utilizing Elmish.WPF for the consumption of other F# Elmish.WPF applications. Recently the need to use some of these controls in a C# WPF application has come up. I have managed to get it working, but I feel like there is something wrong with my implementation. Or, at least, that there is room for improvement either on my end or Elmish.WPF's.

Currently, I am creating a function like the following in the Control logic: https://github.com/ChernayaKoshka/Minimal3rdPartyControl/blob/main/Minimal.Controls/Controls.fs#L35-L37

And then calling it on the C# side: https://github.com/ChernayaKoshka/Minimal3rdPartyControl/blob/main/Minimal/MainWindow.xaml.cs#L12

However, there are a few issues with this implementation.

  1. The user has to add additional code in order to initialize the control, instead of having it "just work" like C# based controls
  2. Poor MVVM practice. UI-centric code is required instead of just passing parameters through XAML

I attempted one other approach in an attempt to mitigate the above issues. I added the initialization code after InitializeComponent in the control itself. This ended up not working because working with the F# libraries from C# is a less than ideal experience and results in a ton of boilerplate to get working (e.g. using FuncConvert instead of just passing in a System.Func). In addition, the passing of an additional parameter (in this case, SomeParam) to the init for the model was not doable without adding yet another project in the mix to avoid a circular dependency.

In addition, is there a best-approach for adding DependencyProperty's to an Elmish.WPF control? So far I've used a handful, but none that ended up needing to be used inside the control's logic itself. That is not to say it won't come up, however. It also forces the programmer to look in two different places for potential bindings.

Is there a better approach that I am missing? Or is this a limitation of trying to use Elmish.WPF-based controls from a non-F# application?

@TysonMN
Copy link
Member

TysonMN commented Aug 18, 2021

Hello @ChernayaKoshka.

Giving you a quick reply here to say that I will eventually take a detailed look at everything you have shared but I don't know right now when that will be.

I am not very interested at the moment in providing better/any support for C#. However, I am open to changes that improve the C# experience as long as it doesn't hurt the F# experience or introduce a maintenance burden.

In the meantime, maybe someone else will review your code and provide some feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants