문제

이것은 약간의 멍청한 질문이지만 Usercontrol을 만들고 일부 어린이 요소의 이름을 la로 선택한다는 것을 깨달았습니다.

<UserControl x:Class="UserControls.uControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid x:Name="maingrid">

</Grid>

그런 다음 소비하는 XAML의 코드-비언어에서 명명 된 요소를 참조 할 수 있습니다. 그래서 위의 예에 대해서는 쓸 수 있습니다

uControl.mainGrid = new Grid();

왜 이것이 사실인지 궁금합니다. 더 중요한 것은 이러한 컨트롤을 안전하게 캡슐화 할 수있는 방법입니다.

평소와 같이, 모든 도움은 정말 감사 할 것입니다.

도움이 되었습니까?

해결책

당신이 원하는 것은 x:FieldModifier 기인하다:

<UserControl x:Class="UserControls.uControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="300" Height="300">
    <Grid x:Name="maingrid" x:FieldModifier="private">
    </Grid>
</UserControl>

기본값은입니다 내부, 몇 가지 이유. 그것에 대해 더 많이 읽을 수 있습니다 여기.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top