Silverlight를 배우고 있습니다. 이 과정에서 사용자 지정 사용자 정의 컨트롤을 작성하려고합니다. 나의 궁극적 인 목표는 XAML에 다음과 같은 문장을 쓸 수있다 : 컨트롤의Silverlight - 사용자 정의 바인딩
<my:CustomControl>
<my:CustomControl.MainControl>
<Canvas><TextBlock Text="Hello!" /></Canvas>
</my:CustomControl.MainContent>
</my:CustomControl>
내용은 사용자 정의 테두리 포장됩니다. 다시 한번, 이것은 단지 학습 일뿐입니다. 내 경계를 추가하려면, 나는 다음의 UserControl을 만들 수 있습니다
<UserControl x:Class="CustomControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<Grid x:Name="LayoutRoot">
<Border>
<!-- CustomControl Content -->
</Border>
</Grid>
</UserControl>
코드 숨김이 파일과 같은 위해 다음
public partial class CustomControl : UserControl
{
public UIElement MainContent
{
get { return (UIElement)GetValue(MainContentProperty); }
set { SetValue(MainContentProperty, value); }
}
public static readonly DependencyProperty MainContentProperty =
DependencyProperty.Register("MainContent", typeof(UIElement), typeof(CustomControl),
new PropertyMetadata(null));
public CustomControl()
{
InitializeComponent();
}
}
것은 내가 MainContent을 받고있는 문제가 있습니다를 내 CustomControl에 나타납니다. 나는 그것을 올바르게 설정하고 있다고 확신하지만 표시 방법을 잘 모르겠습니다. DependencyProperty이기를 원하기 때문에 데이터 바인딩과 애니메이션을 활용할 수 있습니다.
CustomControl에 MainContent를 표시하려면 어떻게합니까? 아동 속성에 MainControl 속성을 할당로드 이벤트에 다음
public CustomControl()
{
InitializeComponent();
Loaded += new RoutedEventHandler(CustomControl_Loaded);
}
- : 컨트롤의 나머지는 구문 분석 될 때까지 당신이로드 이벤트를 연결해야합니다 있도록 기다릴 필요가 당신에게