첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.02MB

▶ 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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요