2

Using Caliburn Micro MVVM, I'm trying to control a ScrollViewer from code behind. I have a button click that is handled in the viewmodel. I also need to call methods on a ScrollViewer, which I believe can only be done from the view.xaml.cs code behind file.
I've tried 2 things. 1) EventHandler 2) Caliburn Micro IHandle

Neither way seems to hit the code behind file.

Here's the code for option 2

ViewModel:

_eventAggregator.PublishOnUIThread(new MyClickMessage(this)); 

Code-behind (view.xaml.cs) file:

public partial class MyClass: UserControl, IHandle<MyClickMessage> { public MyClass() { InitializeComponent(); } public void Handle(MyClickMessage message) { NOT HITTING HERE } } 

Any advice immensely appreciated.

0

1 Answer 1

3

It should work provided that you actually subscribe in the view. Try this:

public partial class MyClass : UserControl, IHandle<MyClickMessage> { public MyClass() { InitializeComponent(); IEventAggregator eventAggregator = IoC.Get<IEventAggregator>(); eventAggregator.Subscribe(this); } public void Handle(MyClickMessage message) { //... } } 

It works just fine for me.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.