how to bind controls of two different wpf windows - wpf

I dont know how to bind two controls from different wpf windows (for example: textbox from mainwindow and textblock from window1).
I`ve been looking for any example for ages, but my attempts are in vain. Please, send a link with an example of this or write code..
any help will be appretiated
p.s. sorry, my english is bad.

I don't think there is a way to directly bind 2 controls from different windows but you could use the Datastore for this, open your project in Blend and follow these steps:
Step 1. Add a window to your project and name it whatever you want.
Step 2. Add a Textbox control to your mainwindow and to the new window you created.
Step 3. go to the "Data" window and pick "Create data source" \ "New Data Store".
Step 4. the new datastore you created is added to your project with 1 field now named Property1, by default blend adds a text string to that field "value" you'll need to clear that one out, click on the "Edit data store values" and clear anything in the value field.
Step 5. now all you need to do is to bind both textbox's text property to that datastore field, check this image:
https://postimg.org/image/8nz5xki13/

Related

GridView and Hyperlink

I am new to VB and programming in general, however, I am currently trying to develop a simple application where you can add and save daily records to a database. One of the columns in the database table will be used to input paths/directories to files in my computer (e.g. C:\Users\M\Documents). When I type in the the file location and run the application the column contents is viewed as text and not a hyperlink. Could someone explain how to convert text in a specified column to hyperlinks (clickable)?
Thank you
There is a column type DataGridViewLinkColumn, but you cannot edit the cells content at runtime in DataGridView (only from source code).
Another solution:
Use DataGridViewTextBoxColumn column type.
To link style: You can use the cell DefaultCellStyle property to make blue text.
To mouse icon: You can handle the DataGridView's CellMouseEnter event to change the DataGridView.Cursor property when the mouse is over the link column.
With the DataGridView's CellClick or CellContentClick event you can handle the click on link.

Tool to know Windows Form Application's Form fields

I am working on a WinForm Application.
The Form has many fields/components but is poorly built.
for example a field is used as user name on one case and used as folder path on the other case. Code is quite poorly maintaned.
Is is possible that when i run the application and GUI appears, i can use a tool like 'spy++' which can show me 'names' of the components (not ids). For instance the name of a button or name of a label.
Or if i can use SPY++ for 'names' please tell me?
I would solve the problem by adding a ToolTip control to your form and iterating over each control and adding a Tool Tip message to each control that is the name of the control.
First, add a ToolTip object to your form (from the Tools section of the designer.) You can rename it, but for the sake of my demo, I left it as the default name toolTip1.
Next, add a method similar to the one I'm posting below to the code page of your form. (I'm assuming this is for C# but the code is simple and can easily be modified for VB or C++).
public void AddNameToToolTip(Control c)
{
toolTip1.SetToolTip(c, c.Name);
foreach (Control child in c.Controls) AddNameToToolTip(child);
}
Finally, from within the Form constructor, add the following line of code after the call to InitializeComponent().
AddNameToToolTip(this);
This will add a ToolTip message to each control in your form. All you should have to do is hover your mouse over each control and the ToolTip will pop up a message after a second or two displaying the name of the underlying control.
Alternatively, you can recursively adding a MouseHover event to each control and when the event is fired, write the name of the control to the debugger. This would also work if you are already using a ToolTip control within your form.

Printing Multiple pages in wpf

I have a Scroll Viewer and inside that a text block with multiple pages contents.
How can I print everything within the Scroll Viewer.I'm Using WPF MVVM pattern.
Is text block is the right control for this?Or shall I go for any other WPF controls.?
Thanks in advance..
DocumentViewer ir a better control for paginated printing
I don't know what is exactly the problem,But something related to Printer.
From Control Panel->Printers & Fax
1.Right Click the Printer and take Printer preferences
2.Change the Source property to 'Manual Feed'& Apply.(Initially it was'AutoSelect')
3.Still got some error.
4.Again me changed the Source property back to 'Auto Select'& Apply.
5.Changed the Quick set Property to 'Defaults'& Apply
5.Now its Working Fine

Bind objects of different types to combobox in WPF

Requirement:
1. Show a list of all referral types in a combo box. (eg. Newspaper, Yellow Pages, Client)
2. Upon choosing client, a popup is shown where they can search for clients within the system.
3. From the popup, the user can choose one client.
4. Popup will be dismissed and the client name will be populated into the combobox.
I'm almost done with the implementation, wherein requirements 1 thru 3 are done. However, I'm stuck with number 4. The reason is that, the combobox is bound to referraltype objects. However, the chosen item from the popup is of type "client". Right now, I'm just displaying the chosen client in a separate textblock. However, the customer wants it to be displayed as part of the combobox itself.
Not sure how it could be done.
Any help would be appreciated.
Thanks
Bala
You could have a BaseReferralTypeViewModel which NewspaperViewModel, YellowPagesViewModel and ClientViewModel all inherit from. In the combo box resources in xaml declare DataTemplates which describe how to display these types in the combo box. In the case of the first two types its probably just a text block.
In the case of the ClientViewModel create an instance but don't initialise it with any client data.
The DataTemplate can detect this and just display the referral type.
Once the ClientViewModel is initialised with client data by the popup the DataTemplate will detect this and display the name.

C# & WPF : How to update an in-code declared textbox height on textbox content change?

I'm fairly new to C#, I'm on a C# & Wpf course.
Here my teacher has told us to inherit from UserControls and create a wpf control library of our own. In order for us to create a simple UML Editor, and right now I'm working on a Class Control.
The visual representation of a class as seen here: http://www.softwarefactories.com/ScreenShots/CD-1.JPG
Now, to make things easy for the end user and me as the developer, the fields contained
in the class control contain editable textboxes. The fields can dynamically be added to the
control, for instance if the class doesn't have any member variables, it won't need a "property" field, and if the user would like to add a "description", he/she may do so easily.
That part is done, but right now the TextBoxes don't adapt in size when edited;
the user can add a line, but it won't resize the textbox.
What I want to do is to create an eventhandler of some sort, and have a function
run whenever the user changes the content of the textbox.
-How is this done?
Yes, you were absolutely right it's just that I handled the layout wrong further up in the
code. Anyway, it uses only a constant set of textboxes, so i just defined those in xml and
set the height to auto like it should be. In a stackpanel, they align neatly on top of oneanother. Thanks for your help, dnr3!

Resources