代码之家  ›  专栏  ›  技术社区  ›  devlife

如何自定义Visual Studio 2010 RC StartPage最近的项目

  •  2
  • devlife  · 技术社区  · 16 年前

    我想尝试自定义Visual Studio 2010 RC起始页的最近项。对于我所想的,我需要定制数据源/数据绑定,但是我找不到信息的来源。

    <ScrollViewer Grid.Row="1" HorizontalAlignment="Stretch" 
        Style="{DynamicResource StartPage.ScrollViewerStyle}" 
        VerticalAlignment="Stretch"  VerticalScrollBarVisibility="Auto">
        <sp:MruListBox 
            DataContext="{Binding Path=RecentProjects}" 
            ItemsSource="{Binding Path=Items}"
            Background="Transparent"
            BorderThickness="0"
            AutomationProperties.AutomationId="MruList"/>
    </ScrollViewer>
    

    有人能给我指出正确的方向吗?我看到它对最近的项目有约束力,但这是从哪里来的呢?

    1 回复  |  直到 16 年前
        1
  •  0
  •   John Saunders    16 年前

    我找不到任何关于这个的真实文件。我想你知道 VS Docs 但它甚至不会划伤表面。

    由于绑定中使用了RecentProjects属性,因此应该有一个类型公开此类属性(或ICustomTypeDescriptor的实现,请参见 MSDN Magazine )TeamFoundationClientSupported“属性”上也存在绑定。

    我在Microsoft.VisualStudio.Shell.UI.Internal中的一个名为Microsoft.VisualStudio.PlatformUI.StartPageDataSource的类中找到了一个名为TeamFoundationClientSupported的属性,但它是私有的,因此不能像绑定中那样使用。 此类的构造函数包含很多这样的行:

    base.AddBuiltInProperty(StartPageDataSourceSchema.CustomizationEnabledName, GetUserSetting(StartPageDataSourceSchema.CustomizationEnabledName, false));
        ...
    base.AddBuiltInProperty(StartPageDataSourceSchema.TeamFoundationClientSupportedName, this.TeamFoundationClientSupported);
        ...
    base.AddBuiltInProperty(StartPageDataSourceSchema.RecentProjectsDataSourceName, source3);
        ...
    

    最后2个很有趣:它们“添加一个内置属性”,称为TeamFoundationClientSupported和RecentProjects…

    查看此方法的实现,可以看到一个简单的字典,其中键基于属性名(第一个参数),值是第二个参数。此字典由Microsoft.Internal.VisualStudio.PlatformUI.UidataSource中名为EnumProperties的方法使用。通过使用链,我们得到一个名为Microsoft.Internal.VisualStudio.PlatformUI.DataSource的类(在Microsoft.VisualStudio.Shell.10.0中),它实现ICustomTypeDescriptor。因此,它解释了绑定系统如何找到属性。我没有找到数据源类型描述符如何链接到StartPageDataSource类,但至少我们可以知道StartPageDataSource构造函数中支持的属性列表。