2009-02-26 5 views
0
ResourceDictionary ResourceDictionary에있는 단추에 대해 Click 이벤트를 트랩하려고하는데 오류가 발생합니다.

resourcedictionary에있는 단추의 click 이벤트를 트랩합니다.

'WpfApplication1.MyResourceDictionary' does not contain a definition for 'GetTemplateChild' and no extension method 'GetTemplateChild' accepting a first argument of type 'WpfApplication1.MyResourceDictionary' could be found (are you missing a using directive or an assembly reference?) 

MyResourceDictionay.xaml.cs는 다음과 같습니다.

namespace WindowsApplication1 
{ 
    partial class MyResourceDictionary 
    { 
    public virtual void OnApplyTemplate() 
    { 
    Button myButton = this.GetTemplateChild("Crap") as Button; 
    } 
    } 
} 

MyResourceDictionay. 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에서 처리기를 추가하고 코드를 뒤 코드에 첨부 할 수 있습니다 (컨트롤이 사전에 포함되어 있어도이 작업을 자주 수행 할 수 있음).

이 정보가 도움이되기를 바랍니다.

관련 문제