본문 바로가기

Programing (프로그래밍)/WPF & C# (C Sharp)

WPF & C# - 템플릿 내 오브젝트 선택하기 ( Template / object )

728x90
반응형


 WPF & C# - 템플릿 내 오브젝트 선택하기 ( Template / object )



object_in_Template.zip




MainWindow.xaml



1
2
3
4
5
6
7
8
9
<Button x:Name="btn" Height="100" Width="100" Click="btn_Click" Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
    <Button.Template>
        <ControlTemplate>
            <Grid Background="#FFD8D8D8">
                <CheckBox Name="chk1" Content="1"/>
            </Grid>
        </ControlTemplate>
    </Button.Template>
</Button>
cs




MainWindow.xaml.cs



1
2
3
4
5
private void btn_Click(object sender, RoutedEventArgs e)
{
    CheckBox chk = (CheckBox)btn.Template.FindName("chk1", btn);
    chk.Content = chk.IsChecked == true ? "Check" : "unCheck";
}
cs


728x90
반응형