0

我需要一点启动来在 2015 版中创建 Visual Studio“起始页”。有旧信息(https://msdn.microsoft.com/en-us/library/Ee663382(v=vs.120).aspx)那里和 Visual Studio Galery 上的一些项目(例如“BetterStartPage”或“SolutionStartPage”。特别是“自定义起始页项目模板”已过时:-(

我确实使用本教程开始了一个项目:https ://msdn.microsoft.com/en-us/library/ff425532(v=vs.140).aspx 但是步骤和信息非常......简短。

这是我的问题:我编译了自定义控件库项目并按照文章中提到的手动安装步骤进行操作。我可以选择我的自定义起始页,但它不会启动我的自定义控制。页面只是空的。就像没有执行DLL中的代码一样。

这是 test-XAML 文件:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:MyNamespace="clr-namespace:StartPageControl;assembly=StartPageControl"
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns:MeineControls="clr-namespace:StartPageControl"
xmlns:local="clr-namespace:StartPageControl"
 x:Class="StartPageControl.UserControl1" 
mc:Ignorable="d"
 Height="350" Width="525">
<Grid>
    <Grid x:Name="LayoutGrid" >
        <Button Click="Button_Click" Content="push me" Foreground="black" />      
        <Label x:Name="label" Content="Label" HorizontalAlignment="Left" Margin="720,171,-295,0" VerticalAlignment="Top" Width="100"/>
    </Grid>
</Grid>
</UserControl>

UserControl1.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StartPageControl
{
/// <summary>
/// Interaktionslogik für UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl { 
    public UserControl1()
    {
        InitializeComponent();
        ButtonApp ButtonApp1 = new ButtonApp();
        LayoutGrid.Children.Add(ButtonApp1 as UIElement);
    }

    private void Button_Click(object sender, RoutedEventArgs e) {
        label.Content = "Something happend!";
    }
}
}

编辑:

以下是我执行的步骤:

  • 创建一个新的 WPF 控件库项目
  • 添加新的 XAML 并添加/更改命名空间
  • 添加一些“代码背后”,例如带有点击事件的按钮
  • 编译
  • 将 XAML 文件复制到 %USERPROFILE%\My Documents\Visual Studio 2015\StartPages\
  • 将项目 .DLL 复制到 \Common7\IDE\PrivateAssemblies\
  • 启动一个新的VS并选择新的Startpage
  • 得到错误(从德语翻译):“System.Windows.Markup.XamlParseException”......“从文本'Button_Click'创建'Click'时出错”..所以我尝试在UserControl中使用UserControl(如您所见在上面的代码中)。出现消息“无法创建 {clr-namespace:StartPageControl}ButtonApp”

:-(在我看来,VS不使用“代码背后”/ DLL ...

我知道这是一个分散的问题。知道有人更好的起点吗?

编辑 2:粘贴所有测试代码。

4

0 回答 0