2009-02-26 47 views
0
ResourceDictionary ResourceDictionary

ResourceDictionary resourcedictionaryにあるボタンのclickイベントをトラップする

ResourceDictionaryResourceDictionaryResourceDictionaryResourceDictionary MyResourceDictionay.xaml.csは次のようになります。 xamlは次のようになります。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Class="WindowsApplication1.MyResourceDictionary" 
    x:ClassModifier="public"> 

    <ControlTemplate x:Key="ExpandablePropertyEditorTemplate"> 
    <Button x:Name="Crap" Foreground="White" Background="White"> 
     <Image Source="Controls\check.png"/> 
    </Button> 
    </ControlTemplate> 
</ResourceDictionary> 

何か助けてください。

答えて

0

リソースディクショナリの内部を検索する場合は、GetTemplateChild(string)ではなくFindName(string)関数を使用する必要があります。

現在のコントロールのテンプレート内で子コントロールを検索している場合でも、GetTemplateChild(string)ではなくTemplate.FindName(string、FrameworkElement templatedParent)を使用する必要があります。

これが解決しない場合は、説明を拡張してください。

コードビハインドファイルをお持ちの場合は、XAMLにハンドラを追加して、コードを後ろに付けることができます(通常、コントロールが辞書に含まれていてもそうすることができます)。

こちらがお役に立てば幸いです。

関連する問題