コントロールを再利用したいが、シナリオの1つにコンテキストメニューが必要で、それ以外のものは必要ありません。ここに私の試みです。UserControl内のDependencyプロパティへのバインドXAML
<ctls:RP8Grid UseContextMenu="False"/>
今の部分は、私は、ユーザーコントロール内のUseContextMenuにアクセスしないか、離れて正方形ではないことができます。プロパティを使用する
public partial class RP8Grid : UserControl {
public bool UseContextMenu {
get { return (bool)GetValue(UseContextMenuProperty); }
set { SetValue(UseContextMenuProperty, value); }
}
// Using a DependencyProperty as the backing store for UseContextMenu. This enables animation, styling, binding, etc...
public static readonly DependencyProperty UseContextMenuProperty =
DependencyProperty.Register("UseContextMenu", typeof(bool), typeof(RP8Grid), new PropertyMetadata(false));
public RP8Grid() {
InitializeComponent();
}
}
そして、XAMLで?結果と
<DataGrid>
<DataGrid.ContextMenu>
<ContextMenu IsEnabled="{Binding UseContextMenu,RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}}">
</DataGrid.ContextMenu>
</DataGrid>
:
'RelativeSource FindAncestor、AncestorType =' System.Windows.Controls.UserControl参照して結合するためのソースを見つけることができません」、 は、私は、次の試してみましたAncestorLevel = '1'
あなたは正しいです、私はpropa insteaをヒットしたと思いますdのpropdp。私の最初の実装。 RelativeSource、そして祖先のチェーンを通って? – markokstate
' ' –
私の試行で質問を更新できませんでした – markokstate