首页 > 解决方案 > 无法访问 XAML 代码隐藏中的继承属性

问题描述

我正在使用SharpShell制作属性表外壳扩展。最初我尝试将 WinForms 用于 Property 页面,但 PropertyGrid、ListView 等控件的限制使我选择了 WPF。所以我创建了一个 WPF 用户控件库项目,并将 SharpShell 从 Nuget 添加到我的项目中。

我创建了一个新页面,我猜,我是 VS 和 WPF 的新手,但它显示“构建操作”为“页面”。现在我的代码隐藏看起来像这样:

using SharpShell.SharpPropertySheet;
using SharpShell.Attributes;
using System.Runtime.InteropServices;

namespace FLPShellExtension
{
    [ComVisible(true)]
    [COMServerAssociation(AssociationType.ClassOfExtension, ".flp")]
    public partial class FLPPropertyPage : SharpPropertyPage
    {
        public FLPPropertyPage()
        {
            InitializeComponent();
            PageTitle = "Project Info";
        }
    }
}

XAML 看起来像这样:

<UserControl x:Class="FLPShellExtension.FLPPropertyPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:wc="clr-namespace:FLPShellExtension;assembly=SharpShell"
             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="450" d:DesignWidth="800">
    <Grid></Grid>
</UserControl>

在这里,VS 抱怨两件事:

CS0103:当前上下文中不存在名称“PageTitle”

XAML1103:命名空间“wc”是不必要的

PageTitle = "Project Info"WinForms 中工作。它是在public string中定义的SharpPropertyPage。我从其他地方提出的类似问题中发现了这个wc命名空间。

标签: c#wpfxamlinheritance

解决方案


推荐阅读