Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 运行WPF UserControl的简单应用程序_C#_.net_Wpf - Fatal编程技术网

C# 运行WPF UserControl的简单应用程序

C# 运行WPF UserControl的简单应用程序,c#,.net,wpf,C#,.net,Wpf,我刚刚编写了一个新的WPF用户控件。现在我想试试。我能写的运行它的最简单的程序是什么 到目前为止我有 static class Program { static void Main(string[] args) { var grid = new CorrelationsGrid(); } } 但应用程序运行并立即关闭,而不在屏幕上显示我的控件。救命啊 在VisualStudio中 选择文件->新建->项目 选择WPF应用程序 然后将用户控件添加到项目中

我刚刚编写了一个新的WPF用户控件。现在我想试试。我能写的运行它的最简单的程序是什么


到目前为止我有

static class Program
{
    static void Main(string[] args)
    {
        var grid = new CorrelationsGrid();
    }
}
但应用程序运行并立即关闭,而不在屏幕上显示我的控件。救命啊

在VisualStudio中

选择文件->新建->项目

选择WPF应用程序

然后将用户控件添加到项目中

最后在XAML中,将UserControl添加到MainWindow.XAML,它将为您处理所有显示。

在Visual Studio中

选择文件->新建->项目

选择WPF应用程序

然后将用户控件添加到项目中


最后,在XAML中,将UserControl添加到MainWindow.XAML,它将为您处理所有显示。

创建一个新的WPF应用程序,并将其放入MainWindow.XAML的网格中。当然,这假设“最容易”是指“最少的麻烦”,而不是“最简单的”。

创建一个新的WPF应用程序,并将其放入MainWindow.xaml的网格中。当然,这假设“最简单”是指“最少的麻烦”,而不是“最简单的”。最简单的方法应该是这样

一旦编写并构建了控件,该控件将成为“工具箱”的一部分,这意味着所有可用控件都可见并分组的窗口

您可以使用Visual Studio将控件从“工具箱”窗口添加到空WPF项目中的主窗口。 这将在MainWindow.xaml文件中添加几行关于控件的代码


现在,您可以像其他控件一样自定义用户控件的属性。

最简单的方法应该是这样

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:myuct="clr-namespace:namespaceofyourusercontrol"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <myuct:myusercontrol/>
</Grid>
一旦编写并构建了控件,该控件将成为“工具箱”的一部分,这意味着所有可用控件都可见并分组的窗口

您可以使用Visual Studio将控件从“工具箱”窗口添加到空WPF项目中的主窗口。 这将在MainWindow.xaml文件中添加几行关于控件的代码

现在,您可以像其他控件一样自定义用户控件的属性。


<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:myuct="clr-namespace:namespaceofyourusercontrol"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <myuct:myusercontrol/>
</Grid>



你在使用Visual Studio吗?@DavidPilkington当然可以我的答案对你有用。对你有用吗@上校:你在用Visual Studio吗?@DavidPilkington是的当然我的答案对你有用。对你有用吗@上校,你的解决方案救了我。谢谢你,我们的解决方案救了我。非常感谢