Windows phone 8.1 Windows Phone MediaElement引发对象引用

Windows phone 8.1 Windows Phone MediaElement引发对象引用,windows-phone-8.1,Windows Phone 8.1,我正在开发一个包含Hub和Hub部分的windowsphone应用程序。 这是我的密码: <Hub Header="Music" Margin="0,93.167,0,10" Grid.Row="1" SectionsInViewChanged="SectionsInViewChanged"> <HubSection Header="Immediate Music" Name="DarkSideofPowerHubSection" Height=

我正在开发一个包含Hub和Hub部分的windowsphone应用程序。 这是我的密码:

        <Hub Header="Music" Margin="0,93.167,0,10" Grid.Row="1" SectionsInViewChanged="SectionsInViewChanged">
        <HubSection Header="Immediate Music" Name="DarkSideofPowerHubSection" Height="528" MinWidth="250">
            <DataTemplate>
                <Grid>
                    <TextBlock Margin="10,10,10,330" Text="Dark Side of Power" TextAlignment="Center"/>
                    <Image HorizontalAlignment="Left" Height="207" Margin="0,70,0,0" VerticalAlignment="Top" Width="341" Source="Assets/Time_Will_Remember_Us.jpg"/>
                    <MediaElement AutoPlay="False" Name="Music" Source="Assets/Sounds/Dark_Side_of_Power.mp3" Margin="10,50,150,150"/>
                </Grid>
            </DataTemplate>
        </HubSection>
    </Hub>

我的问题是我无法访问代码中的可变音乐。MediaElement行也有下划线,表示:“对象引用未设置为对象。”

有人知道我做错了什么,或者我不能在HubSection中使用MediaElement吗

谢谢

Claor

试着把

<MediaElement x:Name="Music"></MediaElement>


在集线器外部,而在datatemplate内部,搜索如何访问属于
datatemplate一部分的元素