C# Windows Phone内容属性
我在我的WindowsPhone8项目中使用UserControl,我想使用如下控件C# Windows Phone内容属性,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我在我的WindowsPhone8项目中使用UserControl,我想使用如下控件 <MyUserControl> <Grid Name="MyGrid"> ... </Grid> </MyUserControl> MyUserControl的XAML文件: <UserControl x:Name="RootUserControl" DataContext="{Binding RelativeSou
<MyUserControl>
<Grid Name="MyGrid">
...
</Grid>
</MyUserControl>
MyUserControl的XAML文件:
<UserControl x:Name="RootUserControl"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
...>
<Grid x:Name="LayoutRoot">
<ContentPresenter Name="Presenter" Content="{Binding MyContent, ElementName=RootUserControl}"/>
</Grid>
</UserControl>
这是工作,但也有一部分。当我尝试在MyUserControl中使用MyGrid或其他内容时,它返回null。怎么了?RootUserControl不是MyUserControl。此外,这不起作用,因为一个UI元素只能是另一个UI元素的子元素…我指定DataContext={Binding RelativeSource={RelativeSource Self}
<UserControl x:Name="RootUserControl"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
...>
<Grid x:Name="LayoutRoot">
<ContentPresenter Name="Presenter" Content="{Binding MyContent, ElementName=RootUserControl}"/>
</Grid>
</UserControl>