To create dual window application - wpf

first window and second window will have same control like textbox or button
once some entry happend in first window it should reflect in second window also and vice-versa and in case of event also.
you can say first is mirror of second window vice-versa so any one, so can any one tell me how should i start for this.

you can use mvvm - create 1 viewmodel where you hold your data and bind the same instance of this viewmodel to both windows/views as the datacontext, create your bindings twoway and all works like you want.
btw i really dont know what you wanna do with your app :)

Related

WPF - modify window content from ViewModel

I have a WPF application. I'm trying to modify it to use the MVVM pattern.
Now, in the code behind of my main window, when I click a button, I change the "Content" of my window with a WebBrowser control :
Content = webBrowserWrapper.WebBrowser;
I would like to do it from a command in my ViewModel. How can I access the "Content" property of my window ?
If it's not possible, what is the simple way to modify the content of my window (maybe create a new window and navigate to it)
The principal behind MVVM is that UI is the concern of the View, and logic is the concern of the ViewModel.
You describe a concern of the View, which is properly handled within its codebehind. There is no need to involve the ViewModel in this action.
So, in other words... congrats. You're already there.

Databinding in the second tabitem does not work

I have a WPF TabControl with two TabItems. In both tabItems I have a textbox with the Text property bound to a property in my ViewModel. The problem is that the binding in the second tab (the one "hidden" by the first tab) is not working. I have two cases:
I run the app, I run the command that would fill the text in the second tab, I select the tab: in this case the binding works: I can see the textbox filled with data. But if I run again the command the textbox does not get updated anymore. It looks like the binding works, but only once.
The second case is if I run the app, and then, before running the command, I select the second tab. In this case the binding does not work at all.
If I move the second tab to the first position, then the binding will work for this tab. (but it will stop working for the other one)
Does someone knows about a worksround for that
Your ViewModel has to implement INotifyPropertyChanged interface.
Also you have to set the UpdateSourceTrigger property of your binding to "PropertyChanged". After this changes your app should working as expected.

Pass a value from child to parent in Silverlight

I am working on Silverlight project.
I added a custom user control (Say, control1) which has a text box and button to a xaml page (Say, Page1).
Now what I want to do is when users clicks on the button, i want to pass the value in the textbox to Page1 and do something.
So basically, I am looking for a way to pass back a value from child to parent page in Silverlight.
Thank you.
You should look into the Model View ViewModel (MVVM) pattern. It works very well with WPF and Silverlight.
http://en.wikipedia.org/wiki/Model_View_ViewModel
http://karlshifflett.wordpress.com/mvvm/ (lots of good information and demos)
You can do this through binding. Bind the Text value of the TextBox to a string property in your ViewModel and use that property throughout the code.
All the controls within your user control are accessible within your main page. If possible, write the click event of the button within the main page and you'll be able to access any control's property. Hope that work for you.

How can I tell which TextBox had focus last?

I have an MVVM application with various TextBox controls and a virtual keypad. (This application is to run on a touch screen system, with no keyboard). To change the value of a TextBox, the user has to touch the TextBox and then use the virtual keypad to enter a number. How can my VM know which TextBox to change when it gets the command from the keypad?
if you mean WPF use FocusManager.GetFocusedElement also look here
The ViewMoel is unconcerned with the View, and as such this should not be passed to the ViewMdel.
If I needed to track this, I would use the View's codebehind (I know, I know) or create a WPF behavior* that does this for me.
*using Attached DependencyProperties, is normally how I do this.

Silverlight databinding a textBlock in another user control

I have a small usercontrol that basically increments or decrements a value by one. The user control has two buttons(one to add and the other to subtract) and a textBlock that is used to display the value.
I am going to have multiple instance of this usercontrol in another usercontrol so I can manipulate values of a dataclass that has an INotifyPropertyChanged interface. My question is how can I databind the textBlock of the value changing usercontrol to the usercontrol I instansiated it in?
First, I want to state that Silverlight 2 does not support element to element binding. That feature is added in Silverlight 3 (out in Beta now). Having said that, I don't think you want to bind controls together anyway. It sounds like you're trying to build a NumericUpDown control and you probably have some class in code behind that's actually doing the incrementing and decrementing.
If that's the case, you can simply subscribe to the click handlers and call a method on your model like Increment or Decrement. Your model can expose a property for the current value and that property is what is bound to your text box.
Now if you're actually trying to build a NumericUpDown control, you might want to check out the Silverlight Toolkit. The toolkit already includes this control and it also supports data binding.
Check out the NumericUpDown Control here and download the toolkit here.
Finally, binding from a child control to a parent control really isn't any different. The parent UserControl has a DataContext and all child controls inherit that. Each individual child control can also have its DataContext set. Binding expressions are always relative to the DataContext and the DataContext can be set in code. In your case, probably to a model of some sort.
I hope that helps.

Resources