System.Windows.Controls.RadioButton problems - c#

I'm trying to test whether a radio button is checked, and I keep getting the error that Checked and isChecked are not valid methods for that RadioButton class. I'm using C# and Visual Studio 2010.
Example
if (radioButton4.Checked) maxTotal = 660;
This error seems specific to the System.Windows.Controls.RadioButton class. If I create a System.Windows.Forms.RadioButton from within the code, I don't get the errors. The problem is that the RadioButton that I drag onto the stage (I come from as3) from the WPF Controls Toolbox is of the System.Windows.Controls variety.
I need to figure out how to add the System.Windows.Forms variety of RadioButton to my toolbox, or figure out why the Checked property is not valid with the Controls version. It doesn't make sense. Everywhere I've looked says it should work.
I created the app as a WPF Application. I'm using one of the Forms controls to do something that I think couldn't be done without it. And from what I understand, the Forms components are meant to be used with a Windows Forms Application. So my problem might have something to do with that, but I don't know.

To check if a WPF toggle button is checked use the IsChecked property.
System.Windows.Controls.RadioButton is a descendant class of the ToggleButton.
You should not mix WPF and Windows Forms controls if it is not absolutely neccessary.

Related

Retrieve toolstripbutton using UIAutomation

Using UIAutomation on windows Forms, I'm trying to retrieve any control under mouse on a specific form.
The goal is to work on controls of an app, retrieving and acting on them.
The problem I'm facing since so many times is that I can't find a toolstripbutton.
Everytime I'm getting a pane (not parent nor child of the toolstripbutton I want, but parent's sibling).
This is the toolstripbutton I want to retrieve : .
The same control but in Inspect.exe (highlighted: the control I'm getting) :
I though that it was because of z order of the controls, then I tried using sibling controls, for controls where their bounds contains the mouse (for getting all controls under the cursor anyway their z order).
That fails because the toolstripbutton isn't retrieved.
I currently use UIAutomation and not CodedUI, because I need to run a custom program which retrieve controls and executes automatic tests on a specific server, but I actually have the Visual Studio Enterprise 2017 licence installed on my machine, but a second licence (for the server) and a third licence for a colleague for work with me on it would be a bit expensive.
Remembering that the programs have to retrieve dynamically the controls under the mouse, may someone gives me any idea which can help me to investigate deeper ?
Thanks & Greetings
Method used:
var aimed = AutomationElement.FromPoint(new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y));
Solved by work around.
I made a recursive method that search deeper in the children for controls which contains the mouse (BoundingRectangle.Contains` method).
In that way, I can find the controls within the toolstrip.
But AutomationElement.FromPoint method doesn't search inside the toolstrip.

WPF SpellCheck context menu in WinForms won't extend past control

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.

Integrate WinForms project into WPF

I've been working on a project for some time, and it requires alphablended non rectangular forms...
which in a little research I found can be easily done in WPF. So I decided to port my project from WinForms to WPF.
There are a few complications like a reference DLL based on WinForms I've been using doesn't work under WPF; it doesn't even show in the designer toolbox. I already tried loading it into the toolbox by right clicking and selecting Choose Items.., but it does not show there either.
I have never worked on WPF before, but it looks so promising for my requirements.
So is there anything I could do to integrate my project into WPF?
There is a control named 'WindowsFormsHost' in WPF. You can find it in toolbox. Drag it on the form and then you can use windows controls and user controls on it.
Hope this information will help.

WinForms - Enable DesignMode

For a OSS project, I'm trying to add controls programmatically to a WinForms view.. and I want to make these editable and resizeable as in the Visual Studio Designer. I've been playing around with adding programmatically, using Controls.Add(label).. but I'm struggling to work out how to make the UI editable.
I'm assuming it would make use of DesignMode - but I can only find getters and not setters for these properties. Simply put - is there any way of enabling and disabling DesignMode in WinForms programmatically?
I'm yet to investigate WPF - perhaps that would be able to have editable controls?
Many thanks, sorry to be a pain right after christmas..
T
Actually there is a way to make UI editable as in VS designer.You have to host the winforms designer on your form.
this info might help:
http://msdn.microsoft.com/en-us/magazine/cc163634.aspx
It is available in WinForm as explained by alexm. Unfortunately this is not true for the WPF designer. There you would have to implement your own designer.
As far as I know, the Designer functionality is implemented in Visual Studio, and is not part of the WinForms runtime libraries. The DesignMode property is read-only because it gives information about the execution context; this is not something that can be changed on the fly (as a side note: this property is not as easy to use as one would hope).
If you want to make the UI editable at runtime (i.e. changing the size/layout of controls), you would have to implement a lot of the behavior manually (e.g. OnMouseDown handlers, etc.). If you wanted to do things like drawing bounding boxes with grabbable corners, you might need to delve into custom drawing.
I'm not sure about WPF, as I have much less experience with it, but this question on SO has some information about making controls resizable at runtime.

How do I get an Expression Blend Keyspline control?

I need a control in my C# program that behaves exactly the same as MS Expression Blend keyspline control - is there any way to get hold of that control and add it to my application?
As a side note it'd be nice to use some of the other controls that appear in that applications as well
What do you mean by add it to your application? If you're developing a C# WPF application you can already add it using the Blend designer or programatically in Visual Studio.
You can inherit from all the WPF controls to create new ones that enhance the behaviour if needed. If you simply want to customise the feel of a control you can use styles within Expression Blend. If you want to customise the complete look, feel and behaviour of a control you also have the option of templates.
Ok sorry for uing the wrong terminology.
I want to add the control into Visual Studio 2005's toolbox (or indeed Expression Blend's Asset Library) so that I can drag and drop it into any C# WPF applications I create.
The problem is I don't know what the Expression Blend Keyspline control is called and how to get access to it (ie what dll to include as a reference)?
I can try and go through Expression Blend's dll's etc searching for the control but I'm not sure A) that this will work, B) that its a bit long winded, C) what the licensing is for such controls.
I think what you want to do is add a Storyboard, that's where you will then have the option to set the animations including KeySplines for your different controls. A KeySpline by itself is not actually a control it is an animation that acts on a control.
To add a Storyboard click the little plus icon at the top of the "Objects and Timeline" panel (to the right of where is says No Storyboard Open).

Categories