ReactiveUI in WinForms application.

764 views
Skip to first unread message

Chris Shepley

unread,
Oct 26, 2012, 3:37:59 PM10/26/12
to reacti...@googlegroups.com
Hi, I'm trying to use Rx in a winforms app that is hosted inside Word as an Add-In Express add-in. I am using the 4.0 preview since in theory the new binding mechanism and Rx's WinForms ControlScheduler should allow me to dispatch everything properly. The problem I am encountering is that a ConfigurationErrorsException is being thrown somewhere in the ReactiveAsyncCommand constructor and I can't figure out why.

Any help would be appreciated.

Chris

P.S. I would love to use WPF or make it an HTML server hosted application, but I cannot due to the brownfield nature of the application and the Add-In Express component which at its very limits only allow me to host WPF controls in specialized winforms containers derived from Form.

Paul Betts

unread,
Oct 26, 2012, 3:54:55 PM10/26/12
to reacti...@googlegroups.com

Call Stack?

Chris Shepley

unread,
Oct 26, 2012, 4:18:13 PM10/26/12
to reacti...@googlegroups.com
Okay, I just got past this, but am trying to get the new Binding stuff done (Getting an exception method of "Property set method not found."). Which is where it is failing now. I am pasting the constructor of my WinForms view below.


        public CompanySearchDialog()
        {
            ViewModel = new CompanySearchViewModel(new ControlScheduler(this));
            
            InitializeComponent();
 
            this.Bind(ViewModel, x => x.SearchTerm, x => x._LblCompany.Text);
            this.Bind(ViewModel, x => x.AutoCompleteEntities, dialog => (object) dialog._CbCompany.Items);
        }


Any insight would be appreciated.

Paul Betts

unread,
Oct 26, 2012, 4:47:15 PM10/26/12
to reacti...@googlegroups.com
ReactiveUI doesn't have existing support for WinForms at the moment.
In order to get View Binding working with a new UI framework, you're
going to have to write some code. Specifically, you're probably going
to have to write (in order of importance):

* Startup code to set RxApp.DeferredScheduler to a ControlScheduler

* An implementation of ICreatesObservableForProperty that knows how to
bind to WinForms controls (i.e. if it asks for "Text", you go looking
for an event called "TextChanged" to hook)

* An implementation of ICreatesCommandBinding that knows how to bind
to WinForms buttons / menus / clicky things.

* A RoutedViewHost and ViewModelViewHost that derive from a WinForms
control instead of a WPF control.

Register the interface implementations with the service locator, check
out https://github.com/reactiveui/ReactiveUI/blob/rxui4/ReactiveUI.Xaml/ServiceLocationRegistration.cs#L26
for an example.

As to your error, I believe it's trying to tell you that Items is a
read-only property, so you can't set it.

--
Paul Betts <pa...@paulbetts.org>

Chris Shepley

unread,
Oct 26, 2012, 4:50:05 PM10/26/12
to reacti...@googlegroups.com
Thanks. This is actually all I need. Since I have already written some Observables that allow me to do one-way proeprty binding, It probably won't be two much work to use your interfaces to make it easier for myself.

Chris Shepley


5632 Montgomery Road
Ellicott City, MD 21043

Chris Shepley

unread,
Oct 26, 2012, 4:53:37 PM10/26/12
to reacti...@googlegroups.com
I've also already changed my startup code to use the Scheduler.CurrentThread as my scheduler (the start-up code is unfortunately a Component, not a Control Scheduler). However, I have added an IScheduler to my ViewModels contstructotrs and pass in the Views scheduler whic can be a ControlScheduler and use that in all commands.

Thanks a lot for your help. I could have done most of what I am doing with straight Rx code, but like a lot abour ReactiveUi like the MemoizingMRUCache and stuff like that which comes handy anyhow for my app and the fact I cuold enforce some structure over what was originally written almost rpocedurally by the off-shore team I took over for.

Chris Shepley


5632 Montgomery Road
Ellicott City, MD 21043



On Fri, Oct 26, 2012 at 4:47 PM, Paul Betts <paul....@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages