Excel按钮来调用WPF窗口 [英] Excel buttons to call WPF windows
问题描述
代码看起来像
private void OnNewButtonAction(object sender,RibbonControlEventArgs e)
{
var window = new View.MyWindow()
{
DataContext = new ViewModel .MyViewModel(),
};
window.Show();
}
其中MyWindow是一个类型为System.Windows.Window的类。 MyWindow有自己的xaml文件,它有单选按钮,文本字段等。当我尝试运行这个 - 并点击按钮,我得到一个XML解析异常为 - '提供价值在'System.Windows.StaticResourceExtension'投掷一个例外。
是否可以从excel加载项中调用wpf窗口?我做错了什么?
编辑:我已经看过
使用WPF控件在Office解决方案,它不起作用。它会添加一个单独的窗格到excel,这不是我正在看的。
你应该使用Excel-DNA。它是一个非常有用的软件,只为这样的东西设计,它有助于实现Excel与WPF,你不应该再有任何问题。
你可以得到它 Here
然而,如果你不希望在这里有一个一步一步的教程如何做到这一点。
您可以尝试将WPF窗口定义为自定义控件,并将其添加到单词的自定义窗格中。看看下面的链接,很高兴:
您还可以查看此链接:
Office 2007 Excel Addin - WPF ComboBox在展开时崩溃
将WPF控件添加到custompane的常见方法是:
-
创建Excel加载项目
-
添加用户控件(WPF)名称UserControl1并添加对System.xaml的引用
-
编写WPF控件并成功构建项目
-
从Window Form集合中添加用户控件,将控件命名为UserControl2
-
将UserControl1拖放到UserControl2,根据需要分配位置
-
编写Thi sAddIn.cs以这种方式:
UserControl1 myWPF;
UserControl2 winformControl;
Microsoft.Office.Tools.CustomTaskPane窗格;
System.Windows.Forms.Integration.ElementHost myHost;
private void ThisAddIn_Startup(object sender,System.EventArgs e)
{
myWPF = new UserControl1();
winformControl = new UserControl2();
pane = CustomTaskPanes.Add(winformControl,WPFControl);
pane.Visible = true;
pane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
}
我们可以使用按钮来控制窗格的可见属性。
美好的一天。
I have a CSharp (.NET) application that has created an add-in with a ribbon in Excel. I have buttons in the ribbon. I want to be able to click on the buttons, and open WPF windows.
The code looks like
private void OnNewButtonAction(object sender, RibbonControlEventArgs e)
{
var window = new View.MyWindow()
{
DataContext = new ViewModel.MyViewModel(),
};
window.Show();
}
Where MyWindow is a class of type System.Windows.Window. MyWindow has its own xaml file, which has radio buttons, text fields etc. When I try to run this - and click on the button, I get an XML parse exception as - "'Provide value on 'System.Windows.StaticResourceExtension' threw an exception".
Is it possible to invoke wpf windows from excel add-ins? What am I doing wrong?
Edit: I have already looked at Using WPF Controls in Office Solutions and it doesn't work. And it adds a separate pane to excel, which is not what I am looking at.
You should use Excel-DNA. Its a really useful piece of software designed just for things like this, it helps to implement Excel with WPF, and you shouldn't have any problems again.
you can get it Here
If however you don't want that there is a step by step tutorial here on how to do it.
You may try to define a WPF window as a custom control and add it to the custom pane of the word. Have a look at the following link, pleases:
Using WPF Controls in Office Solutions
You may have a look at this link as well:
Office 2007 Excel Addin - WPF ComboBox Collapses when Expanded
The common way we add WPF control to custompane is:
Create an Excel add-in project
Add user control (WPF) name UserControl1 and add reference to System.xaml
Code the WPF control and Build the project successfully
Add User Control from Window Form collection, named the control as UserControl2
Drag and drop a UserControl1 to UserControl2, assign the position as you like
Code the ThisAddIn.cs in this way:
UserControl1 myWPF; UserControl2 winformControl; Microsoft.Office.Tools.CustomTaskPane pane; System.Windows.Forms.Integration.ElementHost myHost; private void ThisAddIn_Startup(object sender, System.EventArgs e) { myWPF = new UserControl1(); winformControl = new UserControl2(); pane = CustomTaskPanes.Add(winformControl, "WPFControl"); pane.Visible = true; pane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight; }
We can use the button to control the pane's visible property.
Good day.
这篇关于Excel按钮来调用WPF窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!