I have a mysql database that I am using my Windows form application to view and fill data in.
I'm running into a problem when I try to use binding sources in a user control. All I'm doing is clicking and dragging a label from the data sources toolbar.
When I run the program, the label can't reference the fields in my database. The correct data sources are displayed at the bottom of the design view and in the Designer code.
But, when I do the same thing in the form, it works perfectly well.
What changes between the form data binding and the user control data binding? I've tried digging in the Designer code, creating an entirely new project so I don't have any messy code in the way.
Edit: The article,
Walkthrough: Creating a Windows Form user control that supports simple data binding
makes it look like I can simply drag an drop on the user control, no question asked. However, this does not work for me
Related
So I have an odd issue while trying to use a WPF TextBox with SpellCheck enabled inside a Winforms form, using the custom control defined in this post.
This works just fine, I've tried using it in my own sandbox project and it looks great. The problem is when I try to replace the Winforms TextBoxes inside one of our existing forms. The SpellCheck context menu is "trapped" inside the control, so all I can see are the up/down arrows of the menu.
I'm not too familiar with Winforms, as I mostly work with WPF, so I'm having a hard time determining the problem. The text box shown above is the custom control as mentioned in the linked post. The control is contained in a forms TableLayoutPanel. How can I get the context menu to expand and actually be visible?
Edit
First, to clarify, the context menu appears normally when displayed in a console application that opens the form. I did a little more testing and created a new web project (what the original problem project is) with a button that opens the form, and then the problem behavior occurs. What difference between the console application and the web application would cause this?
Edit 2
I tried the suggestions in this post, thinking maybe the context menu really was just being automatically sized incorrectly (to fit the parent control). But none of those solutions seemed to make any difference either.
Edit 3
After using snoop to look at the differences between the working context menu (windows application) and the not-working one (xbap) the only difference I could see was that the DesiredSize of the xbap instance's context menu has a smaller size, I just have no idea why.
The wpf control is a control which is hosted in winforms via the ElementHost.
Hence it lives within the area provided by the parent.
The only way is to expand it, is to change the size of the parent. Give it a try by creating a winform supersized textbox as a quick debug example. Note whether the size change works on not. If it does can the GUI accommodate that change? I can't answer that.
I would like to write a program that uses several tabs, each showing a data grid. The data of all the grids is stored in a single data source. Each tab should look identical except for the number of colums/rows and the values of course.
So I am now trying to put the grid view into a user control and create a .dll. If a tab is added I put the user control into it - this works already. The grid works in virtual mode and if a new tab/grid is created it calls the event to load the data into the grid.
Now I have the problem that the grid and the LoadData event are in the user control while the data source is in my main program. So in the user control the data source is undefined. I thought that this would be ok because you do not run the user control alone and once it is used in the main program the data source should be available to the LoadData event. However, it does not seems to be possible to generate the .dll while the data source is unknown.
On the other hand I do not want to put the data source into the user control because then it is dublicated every time a new tab is created.
I hope you can give me a hint what is the best way to implement it.
thank you very much!
I don't know what answer (how detailed) you expect, but I think this is a very good example to:
reuse one control
use MVVM architecture pattern
I would try to seperate class which would execute logic responsible for creating ViewModel. Control (grid in your purpose) would be always binded to this ViewModel, and this Control would be reuse in different Views. Depend on where it would be placed you can add some additional features if it is necessary (Decorator design pattern). If you expected more detailed (not conceptual) solution than sorry.
Anyone come up with a way that I can design a panel without a form?
On the surface usercontrol doesn't seem the way to go.
Background:
I come from a text editor world and VS is new to me. We did everything with panels instead of forms. So open for learning. Specifically have a base class panel (ExtendedPanel) that defines some basic controls: Cancel, Save, Save and Close. This ExtendedPanel then will be used for ClientExtendedPanel that is tied to a bindingsouce clientBindingSource. This is all tied to my entity framework model. So I will add, edit and delete sql datarows for my Client table. If no changes have happened by Save button will not be enabled. If I make a change but hit cancel it will warn me. I've done all this before but since I left that company I don't have access to the code base and they didn't use VS (text editor only)so it wasn't really transportable anyway.
All that background so I can ask: Is usercontrol the way to go, or is there something that will allow me to visually add controls to a panel like it is a form?
Yes, a UserControl provides a form-like canvas in the designer for you to add other controls (buttons, etc).
You can do this too by inheriting a panel and writing the code to add the buttons and wire their events, etc, but you won't get the designer support.
I am doing a UI automation for a WPF application using the Microsoft UI Automation library and it works well.
However my app has four screens in a TabControl. Even when I click the tab item through code its child control tree isnt populated. The only control I can see is the "thumb" Control. Same happens when I see the control tree with UISpy.
However if the window is clicked then all the controls appear. As a Workaround I am simulating a mouseclick through code and it works. I wanted to know if there is some better way of doing it.
I ran into a problem similar to this. What was happening was some data was being retrieved on threads and the controls were not generated at the point automation peers were generated. I would suggest if you have access to the code base for the application you are attempting to automate looking into whether threading is being used. In my specific case it was because BeginInvokes were used to retrieve the data, I switched them to Invokes and it worked fine.
Also from what I could tell the reason the controls were being show on mouse over was because the tool tip generated a popup and caused the automation peers to be updated.
Why don't you click the control using mouse events if that is what works.
(Now, if you still are having that problem..)
How to simulate Mouse Click in C#?
All in WPF:
Developing a wizard application, user has to answer a number of simple questions before brought to the main app. The main app is then prefilled with the information obtained from the wizard.
I started with a Window which I then planned to add usercontrols to. The main window would have the user control in the first row, then Next and Previous buttons to control moving between the controls in the second row. This way I could easily control the logic to switch between screens like:
WizardControl1.IsVisible = false;
WizardControl2.IsVisible = true;
But for some reason, user controls do not have setter for IsVisible. Hurray.
So then I thought I would just use seperate windows for each section of the wizard. The problem with this approach is that now when stepping between, the window opens in random positions, and by steppign through the wizard with next, the next window pops up randomly which is really distracting and frustrating.
So how can I develop a wizard properly? I don't get why this is so hard...not exactly rocket science... replacing text and controls and storing input after pressing next/previous!
Thanks
Check this link:
http://www.codeproject.com/KB/WPF/InternationalizedWizard.aspx
This is the article about building wizard in WPF by Josh Smith, it's seems to be nice pattern.
I found it's helpful for me, hope you'll too.
There is also an open source Avalon Wizard control on codeplex.
I'd probably aproach this using data binding and template selectors. Have the wizard form bind to a "WizardData" class, which exposes a list of "WizardPage" base classes.
The WizardData class can expose properties defining the correct info on the forms, and display a control for the main page that uses a template selector to determine the proper control to display based on the actual type of the particular wizard page.
It sounds like more work than it is, really. It also gives you the benefit of good separation between code and UI (all "work" is done by the WizardData and WizardPage classes), and the ability to test logic independent of the UI.
It's also a very WPF/MVVM way of approaching the problem.
I recognize this does not directly address your question, but I thought I'd mention it as a possible alternative. I've used Actipro's Wizard control with pretty good results, and when I have needed support, they have been very responsive. I am not affiliated with them in any way; I just like not having to write the plumbing to manage a wizard.
The property is called "Visibility".
I find that I do better when I dynamically add and removing controls rather than hide them.
I was looking for a Wizard solution too. I have the need to stick with stock WPF components so I implemented the wizard using a standard form and a tab control.
I only hide the tabs at runtime so there available in the IDE. At runtime just use Back, Next, Finish... to navigate thru the tab items
works good