How to Use WPF Controls Inside an Excel Actions Pane? - c#

There are several resources out there that explain how to add WinForms controls to Excel. See these two:
http://msdn.microsoft.com/en-us/library/vstudio/e3zbk0hz%28v=vs.100%29.aspx
http://www.clear-lines.com/blog/post/create-excel-2007-vsto-add-in-wpf-control.aspx
Both of them mention the more up-to-date option of using WPF controls (the one I need). Unfortunately, both resources are lacking the fundamental part. There is a missing link:
(1) The Microsoft site mentions some video -with the exact title that matches my requirement- but all videos in that web site have been removed, it seems.
(2) The Clear-Lines site contains an outstanding, step-by-step project but alas, when the critical part is mentioned, the author uses some facility (the "WPF Interoperability section of the Toolbox") that does not exist in VS-2010+
Based on the above screenshots, and other sites, I have come to the conclusion that the missing link, the connection between my WPF UserControl and its appearance in Excel is some ElementHost.
Addendum for #HighCore. See Toolbox below:

Esteemed Self:
Your problem is that you are trying to place a WPF Control inside another WPF Control.
You need to create an old-fashioned WinForm Control and next you use the Toolbox as depicted here:
Notice that the section ElementHost Tasks has been renamed WPF Interoperability but it is otherwise very much alive.
From MSDN Magazine:
http://msdn.microsoft.com/en-us/magazine/cc163292.aspx#S4

I'm not sure why you think there's a "missing link". The ElementHost is the standard way to host WPF content on winforms, and it's perfectly documented in the link above, and also here.
given any winforms container (such as a Form or Panel), simply do:
var elementHost = new ElementHost
{
Child = new YourWPFContentHere()
};
this.Controls.Add(elementHost);
make sure you add references to these assemblies:
PresentationCore
PresentationFramework
System.Xaml
WindowsBase
WindowsFormsIntegration

Related

Is it possible to read data from Pane control type?

I've started using FlaUI for Automating my thick client .net application. The application is Windows Form based. The start was good and Login Form was identified and I could Login, but after that came the dead end and I found that almost everything in the application is developed as Pane control type.
So, there is grid, table etc. but they all just appear as Pane type when I see the object hierarchy using Inspect.exe or FLAUInspect tools. And nothing really appears in thier property, so it seems that nothing could be read. But before giving up I just wanted to check with experienced audience on this forum if there is really any way to get the data from Pane objects.
Please suggest if there is any way, even that means using other libraries like UIAutomation, TestStack.White, etc.
UPDATE: I now understand little more about this. So, the objects that are there in the pane are developed in syncfusion and devexpress. Is it possible to identify objects developed in syncfusion and devexpress using FlaUI or UIAutomation or TestStack.White, etc ?
I don't know if you have already tried the following steps. Have you add automationId's to your objects in xaml code with:
AutomationProperties.AutomationId="AnyID"
In the testcode, first initialize the main window of the application.
MainWindow = fApplication.GetMainWindow(fAutomation, null)?.AsWindow()
After that you can find your objects by the automationId's, like:
MainWindow .FindFirstDescendant(cf => cf.ByAutomationId(AnyID))
I did it this way, and don't have to know the hierarchy of my application. Maybe this will work?
Most UI Frameworks nowadays fully support UI Automation. So first make sure that you have a recent version of your framework (syncfusion, devexpress). In addition, some frameworks provide settings to enable UI Automation. Like for devexpress, you need to set
ClearAutomationEventsHelper.IsEnabled = false;
at the start of your application to test so it exposes way more things (like tabs) to FlaUI.

How to create user accessible controls(Like labels, Buttons..) dynamically Using Windows Application (C#)

1.Need to create Dynamically controls like Labels, Buttons.
2.After created dynamically control(label,button),that I can able to select that control and moving to other location on that form.
This is a large question and it's impossible to give you a short answer.
There is a quite good sample for a starting point available at codeproject and csharpcorner. Version #2 of this sample is also available.
There is also WPF designer available at github.

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.

How to make custom form control in c#

I was trying to do something in visual studio the other day when I realized, if I could just make a form control to do it for me it would be allot easier, except I have no idea how to do that, I want the form control to have grids, each square having its own color property, if anyone knows how to make form controls, or even better knows how to make something like what I just described, I would be very happy :D
This MSDN article is a basic step by step outline of how you can write a customer control.
Unfortunatly MS has not figured out how to do avoid link rot -- so you may need to search creating custom winform controls to find this if you come in the future.
You are usually best servered by subclassing an existing control and customizing it.
You might also find some of the freely available winform control projects a gold-mine of useful info if you get serious about this.
However, it sounds likely what you should consider doing is creating a "User Control", this is usually simpler for a composite of few existing controls. This
article on the types of controls for winforms may be a useful overview for you.
Beyond that you really should use S/O if you are trying to resolve a specific problem you are having when you are coding. Google is a more appropriate tool for finding tutorials, etc.
1) Inside your project: Solution Explorer --> Right Click the .csproj --> Add UserControl
2) Drag and drop gridBox or any control you want into your custom control.
3) Check the ToolBox, your custom control should be located at the very first selection

What control should I use for this UI?

I'm relatively new to WPF, so could anyone give me some guidelines on how to build this UI (it's main panel of Paint on Windows)
I prefer code style over XAML (just for the learning purpose), so a general idea on what controls should be used would be more than enough, I can handle the detail of each element.
There are online templates. I think that you are searching for Ribbon Control Template.
Then, Codeproject has a great article about this.
You can check this msdn article, too.
In these links you have a lot of examples.
To use it you will create a new project with an online template, like in the image bellow (you see: it's selected WPF Ribbon Application:
That is a Ribbon control.
You can check this out: Introducing Microsoft Ribbon for WPF
Probably want to use the Ribbon Control? http://www.microsoft.com/en-us/download/details.aspx?id=11877
When I had the same question in my mind, I did an analysis of all ribbon controls and collected their links.
Here are they
http://fluent.codeplex.com/
http://wpf.codeplex.com/wikipage?title=WPF%20Ribbon%20Preview&ProjectName=wpf
http://www.microsoft.com/en-us/download/details.aspx?id=11877
Code Project Links:
http://www.codeproject.com/Articles/24062/A-Demonstration-for-WPF-Ribbon-Control-Library
http://www.codeproject.com/Articles/23199/WPF-C-Ribbon-Control-Library
http://www.codeproject.com/Articles/23343/A-Graphical-WPF-Ribbon-Control-Builder

Categories