locked
How would you Data Binding an MediaElement.

    Question

  • All,

    How would you data binding a MediaElement. I have tried the standard way to bind a simple video.  The video is located at “EulerDeepThoughts1_New”.

    Below is my code.

    DataContext = ref new VideoData("/Assets/NormandyDamage Control.mp4");

    <MediaElement Source="{Binding VideoData}" HorizontalAlignment="Center" Stretch="Fill" />

    Thanks,

    Grim


    Saturday, February 8, 2014 1:14 PM

Answers

  • Hi,

    You can code like below:

    In XAML:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Name="grid" DataContext="videoData">
            <MediaElement Source="{Binding Name}" HorizontalAlignment="Center" Stretch="Fill" />
        </Grid>

    Define a VideoData class in code-behind:

    public ref class VideoData sealed{
    		Platform::String^ _name;
    	public:
    		property Platform::String^ Name
    		{
    			Platform::String^ get()
    			{
    				return _name;
    			}
    			void set(Platform::String^ value)
    			{
    				_name = value;
    			}
    		}
    	};

    And define a VideoData in MainPage.xaml.h like below:

    auto videoData = ref new VideoData();

    code in MainPage.xaml.cpp like below:

    MainPage::MainPage()
    {
    	InitializeComponent();
    	videoData->Name = "Assets/NormandyDamage Control.mp4";
    
    
    }
    

    Also you can refer to XAML data binding sample to get more information.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; 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.

    • Marked as answer by A.B.P.Lambert Wednesday, February 12, 2014 2:53 PM
    Monday, February 10, 2014 7:46 AM

All replies

  • Hi,

    You can code like below:

    In XAML:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Name="grid" DataContext="videoData">
            <MediaElement Source="{Binding Name}" HorizontalAlignment="Center" Stretch="Fill" />
        </Grid>

    Define a VideoData class in code-behind:

    public ref class VideoData sealed{
    		Platform::String^ _name;
    	public:
    		property Platform::String^ Name
    		{
    			Platform::String^ get()
    			{
    				return _name;
    			}
    			void set(Platform::String^ value)
    			{
    				_name = value;
    			}
    		}
    	};

    And define a VideoData in MainPage.xaml.h like below:

    auto videoData = ref new VideoData();

    code in MainPage.xaml.cpp like below:

    MainPage::MainPage()
    {
    	InitializeComponent();
    	videoData->Name = "Assets/NormandyDamage Control.mp4";
    
    
    }
    

    Also you can refer to XAML data binding sample to get more information.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; 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.

    • Marked as answer by A.B.P.Lambert Wednesday, February 12, 2014 2:53 PM
    Monday, February 10, 2014 7:46 AM
  • Thanks !!!
    Wednesday, February 12, 2014 2:53 PM