さまざまなユーザー コントロールがあり、いくつかの依存関係プロパティを使用してそれらの基本クラスを作成できるかどうかを確認しようとしています。
具体的には、私のユーザーコントロールのほとんどはこの形式に従います...
<UserControl DataContext="{Binding MyDataContext}" >
<Expander IsExpanded="{Binding MyExpandedByDefault}">
<TextBlock>Some text</TextBlock>
</Expander>
</UserControl>
もちろん、通常、これが 1 回限りの場合は、上記のユーザー コントロールのコード ビハインドに依存関係プロパティを記述します。しかし、同じ形式のユーザーコントロールが複数あるので、以下のようなものを基底クラスに入れたいのですが...
public bool ExpandedByDefault
{
get { return (bool)GetValue(ExpandedByDefaultProperty); }
set { SetValue(ExpandedByDefaultProperty, value); }
}
public static readonly DependencyProperty ExpandedByDefaultProperty =
DependencyProperty.Register("ExpandedByDefault", typeof(bool), typeof(MyBaseView), new UIPropertyMetadata());
それをどこかに継承したいので、メインウィンドウで次のようなことができます....
<Window>
<StackPanel>
<my:Alpha ExpandedByDefault="True" />
<my:Bravo ExpandedByDefault="False" />
</StackPanel>
</Window>
ありがとう
編集:
私はそのような基本クラスを作りました...
public class ViewBase : UserControl
{
public static readonly DependencyProperty ExpandedByDefaultProperty =
DependencyProperty.Register("ExpandedByDefault",
typeof(bool),
typeof(FiapaDbViewerBase),
new FrameworkPropertyMetadata());
public bool ExpandedByDefault
{
get
{
return (bool)this.GetValue(ExpandedByDefaultProperty);
}
set
{
this.SetValue(ExpandedByDefaultProperty, value);
}
}
}
しかし、ユーザーコントロールのコードビハインドでそれを継承しようとすると....
public partial class MyUserControl : ViewBase
{
public MyUserControl()
{
InitializeComponent();
}
}
というエラーが表示されます
Partial declarations of 'MyUserControl' must not specify different base classes
そして、ソリューションで部分クラスの他の部分が見つかりませんか??? ソリューション全体で検索してみました...