WPF自定义控件DependencyProperty无法识别或访问成员

时间:2017-02-03 19:36:02

标签: c# wpf visual-studio-2015

尝试在多台机器上创建了一个新控件,但仍有问题,所以我做错了我确定

以下是我使用控件的方式:

<controls:Pip Text="1" Color="Blue" />

属性显示在建议的属性列表中,但标记为无法识别或可访问。

Designer拒绝显示它,但它有效......编译并运行没有问题

我已尝试在线程中发布的常见解决方案:清除缓存,清理并重建,设置为AnyCPU构建

控件类:

    /// <summary>
    /// Interaction logic for Pip.xaml
    /// </summary>
    public partial class Pip : UserControl {
        /// <summary>
        /// Register the Text property of the control
        /// </summary>
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
            "Text", typeof(string), typeof(Pip), new PropertyMetadata("#"));
        public string Text {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        /// <summary>
        /// Register the Color property of the control
        /// </summary>
        public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(
            "Color", typeof(Color), typeof(Pip), new PropertyMetadata(Colors.Blue));
        public Color Color {
            get { return (Color)GetValue(ColorProperty); }
            set { SetValue(ColorProperty, value); }
        }

        public Pip() {
            InitializeComponent();
        }
    }

XAML:

<UserControl x:Class="testing.Controls.Pip" x:Name="pip"
             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" 
             xmlns:local="clr-namespace:gbtis.Controls"
             mc:Ignorable="d" 
             Height="30" Width="30">
    <UserControl.Background>
        <SolidColorBrush Color="{Binding Path=Color, ElementName=pip, UpdateSourceTrigger=PropertyChanged}" />
    </UserControl.Background>
    <Viewbox>
        <Border>
            <TextBlock Padding="5" FontWeight="Bold" Foreground="White" Text="{Binding Path=Text, ElementName=pip, UpdateSourceTrigger=PropertyChanged}">
                <TextBlock.Effect>
                    <DropShadowEffect BlurRadius="2" Direction="0" ShadowDepth="0"/>
                </TextBlock.Effect>
            </TextBlock>
        </Border>
    </Viewbox>
</UserControl>

0 个答案:

没有答案