Windows8 App2013.12.04 13:29
private async void GetFile()
       {
           Uri source = new Uri(imgUrl);
           StorageFile destinationFile;
           try
           {
               destinationFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                   "downloadimage.jpg", CreationCollisionOption.GenerateUniqueName);
           }
           catch (FileNotFoundException ex)
           {
               return;
           }
           BackgroundDownloader downloader = new BackgroundDownloader();
           DownloadOperation download = downloader.CreateDownload(source, destinationFile);
           await download.StartAsync();
 
           //ResponseInformation response = download.GetResponseInformation();
           var stream = await download.ResultFile.OpenReadAsync();
 
           BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
           InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
           BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(ras, decoder);
 
           BitmapBounds bounds = new BitmapBounds();
           bounds.Height = 274;
           bounds.Width = 382;
           bounds.Y = 0;
           bounds.X = 0;
 
           enc.BitmapTransform.Bounds = bounds;
           await enc.FlushAsync();
 
           BitmapImage bImg = new BitmapImage();
           bImg.SetSource(ras);
           xImage.Source = bImg;
 
           //2
           InMemoryRandomAccessStream ras2 = new InMemoryRandomAccessStream();
           BitmapEncoder enc2 = await BitmapEncoder.CreateForTranscodingAsync(ras2, decoder);
           BitmapBounds bounds2 = new BitmapBounds();
           bounds2.Height = 274;
           bounds2.Width = 382;
           bounds2.Y = 274;
           bounds2.X = 0;
 
           enc2.BitmapTransform.Bounds = bounds2;
           await enc2.FlushAsync();
 
           BitmapImage bImg2 = new BitmapImage();
           bImg2.SetSource(ras2);
           xImage2.Source = bImg2;
 
           var filed = await ApplicationData.Current.LocalFolder.GetFilesAsync();
 
           foreach (var item in filed)
           {
               //그냥 모두 삭제 삭제 안된 파일이 있을경우 파일이 커지는경우를 방지
               await item.DeleteAsync();
           }
       }

 

참고

다운로드

http://stackoverflow.com/questions/19272878/how-to-save-image-downloaded-from-urlserver-to-local-folder-in-windows-store-a

 

crop

http://stackoverflow.com/questions/12349611/how-to-resize-image-in-c-sharp-winrt-winmd

 

삭제:

http://stackoverflow.com/questions/14978526/how-delete-file-in-localstorage-on-winrt

Posted by 동동(이재동)
Windows8 App2013.11.22 16:21
testText.Text = "Testing 123" + Environment.NewLine + "Testing ABC";
 
StringBuilder builder = new StringBuilder();
builder.Append(Environment.NewLine);
builder.Append("Test Text");
builder.Append(Environment.NewLine);
builder.Append("Test 2 Text");
testText.Text += builder.ToString();

http://stackoverflow.com/questions/15582398/programmatic-textblock-entry-with-linebreaks

Posted by 동동(이재동)
Windows8 App2013.10.15 10:19

롯데시네마 같은 경우는 API를 따로 프로젝트로 빼내었다 유닛테스트에서도 사용하고 여러곳에서 유연하게 사용하기 위함

 

하지만 그렇게 함으로써 메세지박스를 뛰우지를 못해서 error 메세지만 따로 보내야 하는 경우가 생겼다..

 

그럴때 이렇게 하였다.

 

protected async Task<T> GetObjectAsync<T>(string url, HttpContent content) where T : ResultBase, new()
        {
            var uri = new Uri(BASE_DOMAIN + url);
            HttpResponseMessage result = null;
            try
            {
                result = await _httpClient.PostAsync(uri, content);
            }
            catch (Exception ex)
            {
                //var temp = new ResultBase() { err_message = ex.Message };
                return new T() { err_message = ex.Message };

            }

 

이부분을 잘보면 된다.

protected async Task<T> GetObjectAsync<T>(string url, HttpContent content) where T : ResultBase, new()

 

그래서 리턴을 이런식으로 가능하였다.

 return new T() { err_message = ex.Message };

참고한곳

http://stackoverflow.com/questions/4712567/c-sharp-generic-method-return-values

 

 


 


 

Posted by 동동(이재동)
TAG generic, return, T
Windows8 App2013.07.23 13:16

com error나 thread error가 나는걸 보니 분명히 dispatcher 를 쓰면 될꺼 같은데 라는 생각이 들었다.

 

networkchanged이벤트를 받아서 인터넷이 끊겼을때 ui를 변경 시켜야하는건데

 

networkchanged이벤트를 app.xaml에서 주는걸 그대로 쓰지말고 해당 xaml.cs에 한번더 이벤트를 건후

 

Windows.Networking.Connectivity.NetworkInformation.NetworkStatusChanged += delegate { DownloadNetworkState(); };
 
        private async void DownloadNetworkState()
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {                
                MelonAppBar.SetDownloadToogleButtonContent();
            });
        }

 

 

이렇게 dispatcher를 이용했다…

 

근데 Windows.current.dispatcher는 쓰임이 다르니 다를때 사용할것(이것때문에 삽질 했다는 ㅠㅠ)

Posted by 동동(이재동)
Windows8 App2013.07.11 16:29

 

설정페이지를 커스터마이징하는건 구글에 많았지만 순수 오리지널을 보이게 하는부분은 없었다.

 

간단하다.

 

SettingsPane.Show();

 

셋팅하는건 여기를 참조

 

http://cyanbyfuchsia.wordpress.com/2013/04/29/winrt-settings-with-caliburn-micro/

 

혹은 winrt flyout으로 검색하면 된다.

Posted by 동동(이재동)
Windows8 App2013.07.05 11:23

 

 

void detectScreenType()
 {
     double dpi = DisplayProperties.LogicalDpi;
     var bounds = Window.Current.Bounds;
     double h;
     switch (ApplicationView.Value)
     {
         case ApplicationViewState.Filled:
             h = bounds.Height;
             break;
 
         case ApplicationViewState.FullScreenLandscape:
             h = bounds.Height;
             break;
 
         case ApplicationViewState.Snapped:
             h = bounds.Height;
             break;
 
         case ApplicationViewState.FullScreenPortrait:
             h = bounds.Width;
             break;
 
         default:
             return;
     }
     double inches = h / dpi ;
     string screenType = "Slate";
     if (inches < 10)
     {
         screenType = "Slate";
     } else if (inches < 14) {
         screenType = "WorkHorsePC";
     }
     else 
     {
         screenType = "FamilyHub";
     }
     ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
     localSettings.Values["screenType"] = screenType;
 }

 

머 거창해 보이지만 실제로는

 

var bounds = Window.Current.Bounds;

 

이렇게만 얻어오면 된다.

 

참조 : http://stackoverflow.com/questions/10828179/how-to-get-the-resolution-of-screen-for-a-winrt-app

Posted by 동동(이재동)
Windows8 App2013.06.17 18:03

 

종료  이벤트

 

      Application.Current.Suspending += Current_Suspending;
        }

        private void Current_Suspending(object sender, SuspendingEventArgs e)
        {
            //Debug.WriteLine("종료!");
            TileManager.StopTileUpdate();
        }

 

http://stackoverflow.com/questions/16264435/windows-store-app-metro-on-closed-suspend-event-does-not-work

Posted by 동동(이재동)