cant get data to save using element host - c#

In my winform app, I'm using elementhost to display the xaml. The xaml uses properties from a viewmodel. Unfortunately, when I click on the save button, (this button is a winform button), I'm not able to get any data I typed in the xaml. Can anyone advise?

this should do it just in case someone may come across this issue.
CarView car = (CarView) CarHost.Child;
CarViewModel cvm = (CarViewModel) car.DataContext;

Related

Unable to select data from combo box using CodedUI

I am using CodedUI technology to do the automation.I have a combo box control and a grid inside as an item. I can find the combo box and managed to open the grid as shown in Fig (01) Control with properties. Now,for further testing I need to click on row item inside the grid.
Issue : I couldn't find the grid and failed to navigate using the search properties. As you see in Fig (01) , the parent level is in desktop client and not bound to our application. Even though the grid belongs to the combo box visually, still it is not listed either parent or the application window.
Solution required: I need to select/click on row item in the grid using hand coded coded ui.
Code Snippet
Note : Playback control also failed to do the desire output.Clicking on the row based on mouse co-ordinates is not much appreciated.
Looking for the solution and thanks much in advance.
Try identifying the grid/Table with combobox as a parent instead of your main application.Something like this
if cboName is your combobox then
HtmlTable tbldata = new HtmlTable(cboName);
Provide any of the columnheaders or one of the Search Property to identify it.
Hope it helps
Hope you must have tried highlighting the grid and checked the parent.
Just try to do record and play u r case and generate code .And see code is getting generated ,how it is maintaing child parent relationship.Than u will get some idea and parameterized the thing in your code

Updating two labels in two different WPF Windows

I've recently built a Volley Scoreboard Application in Windows Forms that I'm trying to convert to WPF.
My first Window has all the controls to manage the game, while the second one is the window that will be projected on the big screen.
In Windows Forms I was able to update both labels (example, home_score on both Main and Projected) from a single point in code, but I don't seem to find a way to do this in WPF.
Any chance I'm missing something? Relatively new to WPF.
If it makes sense to have both pages (Views) utilizing the same View Model; which it sounds like it might given your use case, then the answer is simple:
Bind both labels (really, TextBlocks) to the same property. When the
property is updated; the binding engine will update both UIs.
If that isn't an option; the "master" View Model could invoke a method on the Model that would raise an event (ScoreUpdated). The "display" View Model would register for this event and update an appropriate property so that its View will pick up the change.
You need to:
to name the label (TextBlock Probably) in the xaml (Name="ScoreLabel")
keep a reference to the instance of the window.
after this:
otherWin.ScoreLabel.Text = "123";

Accessing a button control of a page from another class Windows phone?

The problem I'm facing is that, I'm unable to access a control(button) which is in the MenuPanoramaPage.xaml from another page which is MyProfile.xaml.
I wanted to change the content within the button when I select the radio button which is in the MyProfile.xaml. How could I make this?
I tried using this within the button tag in xaml:
x:FieldModifier="public"
But it didn't work out. How can I work on this?
Thanks in advance.
I suggest you to use MVVM Pattern in which use can handle these kind of problems like handling data of one page from other page.
I give you a simple scenario :-
Suppose you want to change the content of a button that is on another page then what you have done basically is.
Some Points :-
1- > Define a string property in viewmodel of the page that contain button. and bind this property to the content property of the button.
2 -> So suppose you want to change it from other page then all you have to do is send a message from another page to change this property. And it will be automatically updated on button(you will get it after some example setup).
3 -> It is not related to some simple string contents. You handle whole data that will be displayed on that page and other View related properties too.(Basically MVVM is much more powerful than you can thought of).
4 -> Last point If you want to make a quality Windows Phone app then MVVM pattern is a good fit.
Links :-
How to implement MVVM in Windows Phone
Basic one from Channel9
What actually MVVM is ?
Explore those. You will not regret. Cheers :)
Sorry, but this is not possible. You only have direct access to the controls on the page you are on. In this case you can only change the controls in MyProfile.xaml.
But what you could do is sending an event or message (if you are using mvvm) to the MenuPanoramaPage.xaml / ViewModel.

WPF C# Change button content from child window

I'm developing a touchscreen app. I have a form with buttons with the content "new player" and then a keyboard with a textbox is shown for the user to enter his name. Now I need that when I close (or while inputting the name) the button from the parent window change the content to the name that the user typed. But I cant make a binding to the parent.. how can I do it??
Are you implementing the Model-View-ViewModel pattern in your WPF application, or using databinding at all?
You don't have to use MVVM, but you should really be using databinding in some fashion.
With databinding, you'd bind the button content to a string property of some object (a view-model in MVVM). That object needs to implement the INotifyPropertyChanged interface. You can bind the textbox on the child window to the same property of the same object.
With that in place, the button will be updated automatically when the user types in a new player name.
If you need more details, please comment and I'll be glad to elaborate.
You can try something like:
var button = this.Parent.Controls.OfType<Button>().Select(b => b.Name == "NameOfControl").First();
button.Content = name;
Edit: And Jay's idea is the right way at going at this, i was just offering an alternative way of accessing the controls from their parent using LINQ.

WPF MVVM UserControl Binding to create a Wizard UI

I m working in a WPF MVVM Project and I am using one Wpf Window. In this window i have a space for one usercontrol and two buttons next and back. When i click the next button I want usercontrol1 to be replaced with usercontrol2. etc.
Sounds like you're trying to create a wizard-style user interface.
This Code Project article may help. And right here is a good place for getting started too.
You can have Wizard user control which is binded to WizardModel, In the Wizard control put ContentPresenter control, and bind it to WizardModel's WizardPage property. And by changing that WizardPage property, you can change wizard page from model.
Hope this helps, here used the same mechanism for changing views

Categories