[英]Open WPF form from a VSTO outlook addin
我在Thisaddin.cs中有这个代码
public void Search(string input)
{
ServerList listofservers = new ServerList();
listofservers.Visibility;
}
ServerList
是一个简单的WPF表单,其中包含listbox但是如何显示listofservers
?
我找不到listofserver.show();
首先,没有名为WPF Form的项目,只有WPF的用户控件。 因此,一旦在XAML中创建了WPF UserControl,您就会注意到这是代码
<UserControl x:Class="SQL_openertak2.ServerList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="454" d:DesignWidth="259" SizeToContent="WidthAndHeight">
<Grid>
<ListBox Height="410" HorizontalAlignment="Left" Margin="12,12,0,0" Name="listBox1" VerticalAlignment="Top" Width="242" />
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="12,427,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</UserControl>
所以我看过XAML代码。 因此,您可以看到整个事情是USERCONTROL,您必须将其更改为WINDOW,然后您将能够看到.Show()
但请注意,您还必须更改xaml.cs中的代码
因为它默认是这样的
public partial class ServerList : UserControl
将其更改为
public partial class ServerList : Window
很明显的原因!! :)
您也可以在布局面板中托管它,例如:
在XAML和c#class中已经回答了用Window更改UserControl 。
请记住,在通常基于Windows窗体的VSTO应用程序中,记住将System.XAML添加到引用非常重要,否则您可能会收到构成窗体布局的错误。
这可能发生在我最近经历的VS2015中,其中向导过程没有按预期工作,缺少更新类引用。
这里有一些参考: “窗口”类型不支持直接内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.