簡潔なタイトルを思いつくのは難しいかもしれません!
1 つのソリューションに 2 つの WPF プロジェクトがあります。最初に、WpfApplication は Class1 を定義します。2 番目の WpfControlLibrary は、Class1 から継承する Class2、Class2 から継承する Class3、および UserControl1 を定義します。以下にそれらを示します。
WpfApplication Class1
namespace WpfApplication5
{
public class Class1
{
public string Property1 { get; set; }
}
}
WpfControlLibrary Class2 および Class3
namespace WpfControlLibrary1
{
public class Class2
{
public string Property2 { get; set; }
}
public class Class3 : Class2
{
public string Property3 { get; set; }
}
}
要約すると、クラス 1 には Property1 があり、Class2 には Property1 (継承による) と Property2 があり、Class3 には Property1 と Property2 (両方とも継承による) と Property3 があります。ユーザー コントロールの XAML は次のとおりです。
<UserControl x:Class="WpfControlLibrary1.UserControl1"
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:b="clr-namespace:WpfApplication5;assembly=WpfApplication5"
xmlns:l="clr-namespace:WpfControlLibrary1"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<b:Class1 x:Key="test1" Property1="xxx" />
<l:Class2 x:Key="test2" Property1="xxx" Property2="yyy" />
<l:Class3 x:Key="test3" Property2="yyy" Property3="zzz" />
<l:Class3 x:Key="test4">
<l:Class3.Property1>xxx</l:Class3.Property1>
<l:Class3.Property2>yyy</l:Class3.Property2>
<l:Class3.Property3>zzz</l:Class3.Property3>
</l:Class3>
</UserControl.Resources>
<Grid>
</Grid>
問題は、XAML がコンパイルされず、次のエラーが発生することです。
The property 'Property1' does not exist in XML namespace 'clr-namespace:WpfControlLibrary1'.
The property 'Property1' was not found in type 'Class2'.
The attachable property 'Property1' was not found in type 'Class3'.
XAML は、別のアセンブリから継承されたプロパティを処理できないようです。そうですか、それとも私があまりにも長い間それを見てきましたか。Property1 と event を設定するさまざまな形式を試しましたが、どれも機能しb:Property1=
てb:Class1.Property1=
いないようです。それとも、あまりにも長くて複雑すぎるものを探していたのでしょうか?