locked
Window Popup and play to a video

    Question

  • Hello,

    Is there away to make a popup that I can place a media element to play a video (Win8 Store APP C#/XAML)? I want the user to click a button and a smaller windows will popup that allows a video to be played and a button to close the popup window. I think I have to use visibility to hide the popup but not really sure what to use? Anyone have any suggesting or pointers?

    Thanks,

    John


    John Lisenby developer of My PC Playbook

    Wednesday, July 16, 2014 11:34 PM

Answers

  • Hi John,

    I have some code for you, when click the button, a pupop shows and the MediaElement inside play the video, when the close button in popup be clicked, the popup closed.

    XAML:

            <Button Content="Button" HorizontalAlignment="Left" Height="110" 
                    Margin="364,300,0,0" VerticalAlignment="Top" Width="112" Click="popupOpen"/>
            <Popup x:Name="StandardPopup">
                <StackPanel>
                    <MediaElement x:Name="media" Width="600" Height="480" Source="Assets/1.mp4"></MediaElement>
                    <Button Click="popupClose">Close</Button>
                </StackPanel>
            </Popup>

    C#:

            private void popupOpen(object sender, RoutedEventArgs e)
            {
                if (!StandardPopup.IsOpen) { StandardPopup.IsOpen = true; }
                media.Play();
            }
    
    
            private void popupClose(object sender, RoutedEventArgs e)
            {
                if (StandardPopup.IsOpen) { StandardPopup.IsOpen = false; }
            }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, July 17, 2014 2:18 AM
    Moderator

All replies

  • Hi John,

    I have some code for you, when click the button, a pupop shows and the MediaElement inside play the video, when the close button in popup be clicked, the popup closed.

    XAML:

            <Button Content="Button" HorizontalAlignment="Left" Height="110" 
                    Margin="364,300,0,0" VerticalAlignment="Top" Width="112" Click="popupOpen"/>
            <Popup x:Name="StandardPopup">
                <StackPanel>
                    <MediaElement x:Name="media" Width="600" Height="480" Source="Assets/1.mp4"></MediaElement>
                    <Button Click="popupClose">Close</Button>
                </StackPanel>
            </Popup>

    C#:

            private void popupOpen(object sender, RoutedEventArgs e)
            {
                if (!StandardPopup.IsOpen) { StandardPopup.IsOpen = true; }
                media.Play();
            }
    
    
            private void popupClose(object sender, RoutedEventArgs e)
            {
                if (StandardPopup.IsOpen) { StandardPopup.IsOpen = false; }
            }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, July 17, 2014 2:18 AM
    Moderator
  • Note that when the popup which includes a MediaElement is closed( isOpen = false), the video/audio would be stopped. If you need the video/audio to keep playing, I suggest you just using it's visibility property.
    However, visibility will affect the layout.
    • Edited by Bo Song Thursday, July 17, 2014 3:21 AM
    Thursday, July 17, 2014 3:13 AM
  • Thanks Jamles it working like a champ!

    John Lisenby developer of My PC Playbook

    Thursday, July 17, 2014 1:13 PM