728x90
반응형
728x170
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="800"
Height="600"
Title="MediaElement 클래스 사용하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid Margin="10 10 10 10">
<Grid.RowDefinitions>
<RowDefinition Height="100*" />
<RowDefinition Height="10" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Border Grid.Row="0"
BorderBrush="Black"
BorderThickness="1">
<MediaElement x:Name="mediaElement"
LoadedBehavior="Manual"
UnloadedBehavior="Manual"
ScrubbingEnabled="True"/>
</Border>
<StackPanel Grid.Row="2"
Orientation="Horizontal"
HorizontalAlignment="Center">
<Button x:Name="openButton"
Width="100"
Margin="0,0,10,0"
Content="열기" />
<Button x:Name="playButton"
Width="100"
Margin="0,0,10,0"
Content="재생" />
<Button x:Name="stopButton"
Width="100"
Margin="0,0,10,0"
Content="중단" />
</StackPanel>
</Grid>
</Window>
728x90
▶ MainWindow.xaml.cs
using Microsoft.Win32;
using System;
using System.Windows;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
this.openButton.Click += openButton_Click;
this.playButton.Click += playButton_Click;
this.stopButton.Click += stopButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 열기 버튼 클릭시 처리하기 - openButton_Click(sender, e)
/// <summary>
/// 열기 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void openButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = "미디어 소스";
openFileDialog.Filter = "미디어 파일|*.avi;*.wmv";
if(openFileDialog.ShowDialog(this).GetValueOrDefault() == true)
{
this.mediaElement.Source = new Uri(openFileDialog.FileName);
this.mediaElement.Pause();
}
}
#endregion
#region 재생 버튼 클릭시 처리하기 - playButton_Click(sender, e)
/// <summary>
/// 재생 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void playButton_Click(object sender, RoutedEventArgs e)
{
this.mediaElement.Play();
}
#endregion
#region 중단 버튼 클릭시 처리하기 - stopButton_Click(sender, e)
/// <summary>
/// 중단 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void stopButton_Click(object sender, RoutedEventArgs e)
{
this.mediaElement.Stop();
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] LinearGradientBrush 클래스 : MappingMode 속성 사용하기 (0) | 2018.03.10 |
---|---|
[C#/WPF] Type 클래스 : GetProperties 메소드 사용하기 (0) | 2018.03.10 |
[C#/WPF] Window 클래스 : Background 속성을 사용해 배경색 변경하기 (0) | 2018.03.10 |
[C#/WPF] Application, Window 클래스 상속하기 (0) | 2018.03.10 |
[C#/WPF] XAML에서 특수 문자 사용하기 (0) | 2018.03.04 |
[C#/WPF] RotateTransform 엘리먼트 : 마우스 진입시 이미지 회전하기 (0) | 2018.02.18 |
[C#/WPF] DoubleAnimation 엘리먼트 : 스크롤 슬라이드 사용하기 (0) | 2018.02.18 |
[C#/WPF] 이미지 뒤집기 (0) | 2018.02.18 |
[C#/WPF] 이미지 뒤집기 (0) | 2018.02.18 |
[C#/WPF] 이미지 슬라이드 쇼 보여주기 (0) | 2018.02.18 |
댓글을 달아 주세요