Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 views
in Technique[技术] by (71.8m points)

c# - Open WPF form from a VSTO outlook addin

I have this code in Thisaddin.cs

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

the ServerList is a simple WPF form with listbox thats it but how to display the listofservers?

I can't find the listofserver.show();

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!! :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...