0

単純なクラスがあり、xaml を介してクラスのインスタンスを単純に作成したいと考えています。しかし、「'Test' member is not valid because it does not have a qualified type name.」のようなエラーが引き続き発生します。

UserControl1.xaml.cs:

namespace WpfTestApplication1
{
    public class UserControl1 : UserControl
    {
        public string Test { get; set; }

        public UserControl1()
        {
        }
    }
}

UserControl1.xaml:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:local="clr-namespace:WpfTestApplication1">
    <local:UserControl1>
        <Setter Property="Test" Value="aaaa" />
    </local:UserControl1>
</ResourceDictionary>

助けてください。

4

4 に答える 4

0

最後に私はそれを見つけました。xamlでコントロールを次のように定義しました

<local:UserControl1 x:Key="xxx" Test="aaaa"/>

プロパティを直接定義するだけで、セッターとプロパティステートメントを使用せずに。手伝ってくれてありがとう!

于 2013-10-18T09:33:33.493 に答える
0

@ us3rが言ったように... DependencyPropertyはあなたが探しているものです。

あなたがしなければならないことは次のとおりです。

// Dependency Property
public static readonly DependencyProperty TestProperty = 
     DependencyProperty.Register( "Test", typeof(string),
     typeof(UserControl1 ));

// .NET Property wrapper
public string Test
{
    get { return GetValue(TestProperty ).; }
    set { SetValue(TestProperty , value); }
}
于 2013-10-18T09:08:08.157 に答える