I found "Ruby in Steel," but that (I think) only works with visual studio 2008 and doesn't support the new WPF/XAML.
Is there such a thing or are these pipe dreams? :)
Look at DiskUse project in your IronRuby 1.1\Samples\ directory. It uses WPF and XAML. For example, it's how they load xaml:
module DialogUtil
def load_xaml(filename)
f = IO::FileStream.new(filename, IO::FileMode.Open, IO::FileAccess.Read)
begin
element = Markup::XamlReader::Load(f)
ensure
f.close
end
element
end
module_function :load_xaml
end
and then using it:
#window = DialogUtil.load_xaml("mainWindow.xaml")
#window.closing { #app.shutdown }
#windowTitle = #window.title
...
#window.show
And yes, it works OK with VS2010 - http://ironruby.codeplex.com/
The main installer for IronRuby does support VS 2010. It also supports Silverlight, but it doesn't seem to support WPF.
Maybe it would be possible to use it by manually editing the project file and writing the boilerplate code that VS usually generates yourself.
EDIT: After some testing, it seems you can use WPF from Iron Ruby without any problems, but you can't use XAML directly.
Related
In short:
I'm new to VisualStudio Extensibility and my goal is to create an extension with a ToolWindow (which already works) showing different views for each context of a VisualStudio solution, i. e. a view for the solution, a view for a project etc.. The window should be opened by clicking on a context menu entry in the context menus of the Solution Explorer, Class View, Object Browser and (ideally) any other window showing contents like projects, namespaces, classes etc..
After searching I found a lot of information, but for some points I couldn't find very helpful information. How do I ...
... create a context menu item for the VisualStudio views?
... get the currently open solution as an instance in code?
... get the projects of the solution and their contens as instances in code?
... add/remove items to/from a solution/project/class/... in code?
... react to selection changes in the Solution Explorer?
What I've done, so far:
I read the docs for Starting to Develop Visual Studio Extensions and downloaded the VSSDK-Extensibility-Samples. Especially the WPF_Toolwindow example was interesting for my purposes, so I built and ran it, which was successful, so far. Another interesting sample would have been the WPFDesigner_XML, but it always throws a NullReferenceException, so I decided to stick with the former ToolWindow, which is completely fine, for now.
Furtermore, I tried to understand the example by having a close look at each file in the project, running it in the debugger and analyzing what happened. I'm confident I understood it, but am also open for corrections of my possibly misguided thoughts following.
Now, I have created a new project, based on the WPF_Toolwindow sample, renamed and adapted to my needs (basically, I created new GUIDs, renamed the namespaces and removed things I won't use). This extension still works in the debugger. I even uninstalled everything from the experimental instance and debugged the extension from scratch.
What I try to achieve:
Have the ToolWindow load a specific view/viewmodel, when the selection changes in the Solution Explorer (or any other VisualStudio view). Alternatively, there should be a context menu item for every node's context menu in the Solution Explorer tree (or any other VisualStudio view).
Get the currently open solution, the containing projects and basically everything from the Solution Explorer's content as instances processable in my viewmodel. I need to properly add/remove
classes/structs/enums to/from
a folder in a project
a namespace
properties/fields to/from a class/struct
Generate code based on information of the solution and add the file properly to a project.
Does anyone know of examples for something like this or can anyone give me some hints, where I can find further information? Any help would be appreciated. Thanks in advance.
(1) The items already have a context menu and I want to add a new command to this menu.
if you want to add a sub menu to the context menu, the following link provide a complete sample
https://github.com/visualstudioextensibility/VSX-Samples/tree/master/CommandSubmenu
(3) Yes, basically adding a file to a project without manually manipulating the project file would be nice.
You can add the file to project via Project.ProjectItems.AddFromFile, and the following provide a sample for your reference.
https://www.mztools.com/Articles/2014/MZ2014009.aspx
Update:
I select a project and a similar event is fired. Are there such events I can subscribe to?
You could use IVsMonitorSelection to implement. here is the code which retrieve related project path for your reference.
IntPtr hierarchyPointer, selectionContainerPointer;
Object selectedObject = null;
IVsMultiItemSelect multiItemSelect;
uint projectItemId;
IVsMonitorSelection monitorSelection =
(IVsMonitorSelection)Package.GetGlobalService(
typeof(SVsShellMonitorSelection));
monitorSelection.GetCurrentSelection(out hierarchyPointer,
out projectItemId,
out multiItemSelect,
out selectionContainerPointer);
IVsHierarchy selectedHierarchy = Marshal.GetTypedObjectForIUnknown(
hierarchyPointer,
typeof(IVsHierarchy)) as IVsHierarchy;
if (selectedHierarchy != null)
{
ErrorHandler.ThrowOnFailure(selectedHierarchy.GetProperty(
projectItemId,
(int)__VSHPROPID.VSHPROPID_ExtObject,
out selectedObject));
}
Project selectedProject = selectedObject as Project;
string projectPath = selectedProject.FullName;
For more information about the usage, please refer to:
https://www.mztools.com/articles/2007/mz2007024.aspx
Using the suggestion from here, I managed to embed Excel 2007 in my WPF WebBrowser control. However, the ribbon doesn't show up. I tried various techniques and nothing makes it work.
I tried this:
_application.ExecuteExcel4Macro("SHOW.TOOLBAR(\"Ribbon\",True)");
I also tried to run this from a macro after the Excel workbook is constructed,
Sub hide_ribbon()
Application.ExecuteExcel4Macro ("Show.Toolbar(""Ribbon"", False)")
End Sub
Sub show_ribbon()
Application.ExecuteExcel4Macro ("Show.Toolbar(""Ribbon"", True)")
End Sub
but it doesn't work either, although the same macro works fine in native Excel.
Also tried this:
CommandBar cb = _workbook.CommandBars["Standard"];
cb.Visible = true;
cb.Enabled = true;
cb.Position = MsoBarPosition.msoBarTop;
Or tried changing "Standard" to "Ribbon", but nothing works.
Ctrl+F1 doesn't work either.
Anybody got a clue?
It took me over 3 weeks of digging to work this out - even then I still need to test that it all works as expected.
As you already know the ribbon is automatically hidden when embedding Excel and that you need to 'toggle' it back on again by sending an OLE command.
I assume that you are uisng the SHDocVw library wrapped in with an ActiveX container, in the manner described in the knowledge base article is article http://support.microsoft.com/kb/304662 and that you have set up the appropriate registry entries to get the browser to display Excel docs (I am sure that you must have done if all you are missing is the Ribbon).
I am using C#, so you may have to mess about a bit in VBA.
The article entitled "WebOCHostVB.exe Hosts the WebBrowser Control in Visual Basic .NET" in the MS support knowledge base looks promising however, the URL is "support.microsoft.com/kb/311303"
Once the document is opened, call ExecWB on the browser as follows :
object omissing = System.Reflection.Missing.Value ;
this.axExcelWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_HIDETOOLBARS,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
ref omissing, ref omissing);
This should toggle the Ribbon state - as it is off when we start, a single call should make it display. Doing this again should hide it - though I have not tried.
The constants are in the shdocvw.dll that you must reference from your project. Even though these are integer enumerations, I could not redefine them locally and get things to work.
You can find other OLE commands, that might also be useful for your application, here :
http://msdn.microsoft.com/en-us/library/ms691264%28v=VS.85%29.aspx
I don't know why this has to be so difficult, or why the behaviour of Excel is not consistent with that of Word.
Hope this helps.
I'm having difficulties with a set of activeX controls used for automation of lab instruments. I've got them all to work in VB, in forms applications - as they won't work in console applications. My company is working mainly with python and there would thus be a great advantage in writting our drivers in python, mainly for lims integration.
As such, I have tried to embed my activeX controls within ironpython windows forms. I've tried two different ways of introducing my controls in the forms:
1) with clr referencing the Ax dll after using AxImp on the original ocx. Then I add my instance of the control as a form control and try to run it from there. It throws System.Windows.Forms.AxHost+InvalidActiveXStateException.
import clr
clr.AddReferenceToFileAndPath(r"C:\dlls\AxVCode3Lib.dll")
clr.AddReferenceByPartialName("System.Windows.Forms")
import System.Windows.Forms as Forms
import AxVCode3Lib
class activeXform(Forms.Form):
def __init__(self):
a = AxVCode3Lib.AxVCode3()
self.Controls.Add(a)
for i in self.Controls:
r = i.Initialize("serial")
print r
form = activeXform()
raw_input(">exit")
2) Using SystemReflection and the ProgID, which throws a generic "Exception has been thrown by the target of an invocation". The following code was introduced in a basic ironpython windows form, however I was not able to add those objects as form controls.
import System.Type
import System.Reflection
import System.Array
oType = System.Type.GetTypeFromProgID("VCODE3.VCode3Ctrl.1")
o = System.Activator.CreateInstance(oType)
args = System.Array[str](['serial'])
try:
r = oType.InvokeMember("Initialize", System.Reflection.BindingFlags.InvokeMethod, None, o, args)
print r
except Exception as e:
print e
Now I suspect both those examples fail due to some properties missing in my forms. However I can't figure out what it is, in particular in case 1 when the instance is actually added as a control, it seems I am very close.
You cannot use the methods of the ActiveX control until its native handle is created. In other words, not until after you call the form's Show() method.
Make sure you get the basic outline of a Winforms application correct, peek in the Program.cs source code file of a sample C# Winforms app. The Application.Run() call is essential. Use the form's Load event (or override OnLoad) as the first event where you can actually start using the control.
I have a WPF Application with a subfolder that contains a WF Activity and a CodeActivity.
At compile-time on the Workflow that uses the CodeActivity, I get this error:
The tag 'Dictionary' does not exist in XML namespace 'clr-namespace:System.Collections.Generic;assembly=mscorlib'. Line 4 Position 8.
The portion of code that reports the error is generated by the Visual studio built-in Activity designer. E.g. this:
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">False</x:Boolean>
<av:Point x:Key="ShapeLocation">270,2.5</av:Point>
<av:Size x:Key="ShapeSize">60,75</av:Size>
<av:PointCollection x:Key="ConnectorLocation">300,77.5 300,107.5 300,112.5</av:PointCollection>
</scg3:Dictionary>
I'd like to know if I am trying to something that is not allowed or if I am missing something.
Thanks in advance,
Gianluca
I had a similar problem today; at least the same error message. The problem for me was that the build action of the .xaml file was set to Page. It needs to be set to XamlAppDef. If you open a vanilla Workflow console application project, you'll see that. You can't change it in the drop down, you need to edit the .csproj file (again, compare to vanilla VS workflow console project).
I'm working on a Windows Forms solution with many winform ui projects.
There is a class library project that contains some custom shared controls, named MyControls.
Now, when I create a control in MyControls
that is composed of one or more controls in the same project, I run into problems.
I either get compilation warnings: warning CS0436: The type 'MyType' in 'path-to\MyType.cs' conflicts with the imported type 'MyType' in 'MyControls.dll'. Using the type defined in 'path-to\MyType.cs'. Or I get a bunch of different compilation errors, all pointing to "MyControls.dll" (error CS0234 - "are you missing an assembly reference?").
I get either the errors, or the warnings, never both.
How to solve this?
Note
I added visual-studio-2010 because that's the version I experienced the problems with. No idea if this relates to other versions too.
I found that Visual Studio adds a self-reference to MyControls when I drop a control from the MyControls project on another control in MyControls:
<Reference Include="MyControls, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
My current work-around is to manually delete this reference from the MyControls.csproj using a text editor.
When I've done this, everything works fine, until I drop another control that triggers a self reference.
Better solutions are appreciated!
you can make a small and "legal" change in your solution and get the "legal" solution... lets say your project name is: "project01"
go to references folder in your project - one of your references called "project01" - just remove it...
the the warning is very fair! you design a form and in the other hand import your project as a reference!
I know this thread is a bit old, but I just went looking for a solution to this issue, and it seems that MS doesn't have anything other than what Marijn suggested earlier:
https://connect.microsoft.com/VisualStudio/feedback/details/613502/automatically-add-self-reference
Hopefully it's fixed in VS 2012.