2009-08-18 4 views
1

Button 안에 CheckBox을 넣고 싶습니다. 그 체크 박스를 코드로 참조 할 수 있습니까? 즉 Window1.cs에서 다음과 같이 쓰고 싶습니다. testButton.innerCheckBox.DoStuff();컨트롤 템플릿 안의 요소를 어떻게 참조 할 수 있습니까?

<ControlTemplate TargetType="{x:Type Button}">       
     <Microsoft_Windows_Themes:ButtonChrome SnapsToDevicePixels="true" x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" ThemeColor="NormalColor"> 
     <Grid Width="32.083" Height="13.277"> 
      <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Stretch" Margin="{TemplateBinding Padding}" VerticalAlignment="Stretch" RecognizesAccessKey="True" d:LayoutOverrides="Width, Height"/> 
      <CheckBox x:Name="innerCheckBox" HorizontalAlignment="Left" VerticalAlignment="Top" Content="CheckBox"/> 
     </Grid> 
     </Microsoft_Windows_Themes:ButtonChrome> 
    </ControlTemplate> 

답변

4
CheckBox innerCheckBox = testButton.Template.FindName("innerCheckBox", testButton) as CheckBox; 
+0

나는이 사이트를 사랑 해요. 신속한 대응에 감사드립니다. – Kelly

관련 문제