1

I have a simple view containing a richtextbox and a button. I want to enter text into my RTB and on clicking my button have viewmodel print the RTB.

I have my command set up from the views print button and in my viewmodel have a UIElement property.

My question is how do I bind the RTB directly to my UIElement property in viewModel?

I'm fine with hooking individual properties of the RTB up but what about the whole control?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
P_S_A_M
  • 55
  • 7

1 Answers1

2

Not certain how you might accomplish that using databinding, how about just setting the reference manually?

MyControl.Loaded += (s, e) => {
   ((ViewModel)MyControl.DataContext).UiElementProperty = MyControl;
};

... although I'm not sure why you want to perform a task like that in the VM. How about just handling it in the view? Otherwise you might also encounter "dialogue must be user initiated" type errors.

Dan Wray
  • 689
  • 1
  • 5
  • 17
  • I was just trying some of the print examples from the web and all were code behind so had easy access to the UIElement, trying to get my head around MVVM properly so everyting I try want to try and separate out is all. – P_S_A_M Nov 03 '11 at 13:14
  • I would suggest there are some tasks which are simply better handled in the view, printing is one of them. MVVM is superb, but if you find you're tying yourself in knots to implement something which could be easier implemented as code in the view, it could be a good indication that you should just go ahead and put it there. – Dan Wray Nov 03 '11 at 13:21