1

CheckBoxa を a の中に入れたいとしButtonます。コードでそのチェックボックスを参照する方法はありますか? つまり、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

1 に答える 1

4
CheckBox innerCheckBox = testButton.Template.FindName("innerCheckBox", testButton) as CheckBox;
于 2009-08-18T16:21:16.993 に答える