728x90
반응형
728x170
▶ MainPage.xaml
<Page x:Class="TestProject.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image Name="image" Grid.Row="0"
Stretch="Uniform" />
<Button Name="setButton" Grid.Row="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="100"
Height="30"
Content="설정" />
</Grid>
</Page>
728x90
▶ MainPage.xaml.cs
using System;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.System.UserProfile;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
namespace TestProject
{
/// <summary>
/// 메인 페이지
/// </summary>
public sealed partial class MainPage : Page
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainPage()
/// <summary>
/// 생성자
/// </summary>
public MainPage()
{
InitializeComponent();
this.setButton.Click += setButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 설정 버튼 클릭시 처리하기 - setButton_Click(sender, e)
/// <summary>
/// 설정 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private async void setButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker picker = new FileOpenPicker
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
FileTypeFilter = { ".jpg", ".jpeg", ".png", ".bmp" }
};
StorageFile file = await picker.PickSingleFileAsync();
if(file != null)
{
try
{
await LockScreen.SetImageFileAsync(file);
IRandomAccessStream stream = LockScreen.GetImageStream();
if(stream != null)
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(stream);
this.image.Source = bitmapImage;
}
else
{
this.image.Source = null;
}
}
catch(Exception)
{
this.image.Source = null;
}
}
else
{
this.image.Source = null;
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > UWP' 카테고리의 다른 글
[C#/UWP] ItemsReorderAnimation 클래스 : SetDuration 정적 메소드를 사용해 GridView 항목 애니메이션 사용하기 (0) | 2021.06.02 |
---|---|
[C#/UWP] 태스크 모니터 사용하기 (0) | 2021.05.31 |
[C#/UWP] ControlTemplate 엘리먼트 : Slider 엘리먼트 정의하기 (0) | 2021.05.19 |
[C#/UWP] 사진 앨범 만들기 (0) | 2021.05.19 |
[C#/UWP] Launcher 클래스 : QueryUriSupportAsync 정적 메소드를 사용해 UWP 앱 설치 여부 구하기 (0) | 2021.05.11 |
[C#/UWP] FileOpenPicker 클래스 : PickSingleFileAsync 메소드를 사용해 파일 선택하기 (0) | 2021.05.05 |
[C#/UWP] ContentDialog 클래스 : ShowAsync 메소드를 사용해 대화 상자 표시하기 (0) | 2021.05.04 |
[C#/UWP] StorageFolder 클래스 : GetFolderAsync 메소드를 사용해 자식 저장소 폴더 구하기 (0) | 2021.05.04 |
[C#/UWP] KnownFolders 클래스 : PicturesLibrary 정적 속성을 사용해 사진 저장소 폴더 구하기 (0) | 2021.05.04 |
[C#/UWP] StorageFile 클래스 : 패키지 내 특정 폴더에서 저장소 파일 리스트 구하기 (0) | 2021.05.04 |
댓글을 달아 주세요