Search code examples
c#xamlwindowmediaelement

Add MediaElement inside Radiobutton Not working in windows 10 UWP


I am trying to add different kind of options for Radiobutton But MediaElement is not working in the below code.

Showing warning :

Object reference is not set to instance of an object

How to add MediaElement to a Radiobutton? Or is there any other way of doing this?

Thanks in advance.

<itemscontrol x:name="MultipleChoice" grid.row="3" itemssource="{x:Bind OptionsListForQuestion}"
    padding="0,10,0,0">
<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Vertical" Padding="20"/>
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
    <DataTemplate x:DataType="local:OptionsListNew">
        <RadioButton GroupName="options" IsChecked="False" Padding="0,5,10,0"  Checked="QuestionsRadio_Checked" >
            <StackPanel Padding="30,0,0,0" Loaded="optionsListR_Loaded">
                <TextBlock x:Name="OptionValueText" Text="{x:Bind optionPreview}" TextWrapping="Wrap" Visibility="Collapsed"></TextBlock>
                <TextBox x:Name="OthersOptionText" Visibility="Collapsed"></TextBox>
                <Image x:Name="OptionImage" Visibility="Collapsed" ></Image>
                <StackPanel>
                    <MediaElement x:Name="OptionAudioOrVideo"  Visibility="Collapsed" AutoPlay="False" AreTransportControlsEnabled="True" Volume="100"></MediaElement>
                </StackPanel>
            </StackPanel>
        </RadioButton>
    </DataTemplate>
</ItemsControl.ItemTemplate>
</itemscontrol>  

Solution

  • Maybe it's the xaml designer bug, if your app run ok, you can ignore this error.