Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows Phone内容属性_C#_Xaml_Windows Phone 8 - Fatal编程技术网

C# Windows Phone内容属性

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

我在我的WindowsPhone8项目中使用UserControl,我想使用如下控件

<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>