Open WPF form from a VSTO outlook addin

后端 未结 3 1069
栀梦
栀梦 2020-12-17 21:17

I have this code in Thisaddin.cs

public void Search(string input)
{           
    ServerList listofservers = new ServerList();            
    listofservers         


        
相关标签:
3条回答
  • 2020-12-17 21:39

    Change UserControl with Window as already answered in XAML and c# class.

    Keep in mind that in VSTO applications, which are normally based on Windows Forms, it is important to remember to add System.XAML to references, otherwise you will probably get errors composing your forms layouts.

    This could happen in VS2015 as I recently experienced, where the wizard procedure did not work as expected, missing to update class references.

    Here some references: The type 'Window' does not support direct content

    0 讨论(0)
  • 2020-12-17 21:45

    So first of all there is no item called WPF Form, there is only User Control for WPF. So once the WPF UserControl is created in the XAML you notice that this is the code

    <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>
    

    So i have looked thru the XAML code. So as you can see that the whole thing is USERCONTROL you have to change it to WINDOW then you will be able to see the .Show()

    But take note that you also have to change the code in the xaml.cs

    cause it will be like this by default

    public partial class ServerList : UserControl
    

    Change it to

    public partial class ServerList : Window
    

    well for obvious reasons!! :)

    0 讨论(0)
  • 2020-12-17 21:52

    you can also host it in a layout panel, like:

    1. Open Form1 in the Windows Forms Designer.
    2. In the Toolbox, drag a TableLayoutPanel control onto the for
    3. On the TableLayoutPanel control's smart tag panel, select Remove Last Row.
    4. Resize the TableLayoutPanel control to a larger width and height.
    5. In the Toolbox, double-click UserControl1 to create an instance of UserControl1 in the first cell of the TableLayoutPanel control.
    6. The instance of UserControl1 is hosted in a new ElementHost control named elementHost1.
    7. In the Toolbox, double-click UserControl1 to create another instance in the second cell of the TableLayoutPanel control.
    8. In the Document Outline window, select tableLayoutPanel1. For more information, see Document Outline Window.
    9. In the Properties window, set the value of the Padding property to 10, 10, 10, 10.
    10. Both ElementHost controls are resized to fit into the new layout.
    0 讨论(0)
提交回复
热议问题