tuomasvaltanen

Untitled

Mar 21st, 2022 (edited)
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.21 KB | None | 0 0
  1. XAML:
  2.  
  3. <Page
  4. x:Class="ExtraFeatures2022.MainPage"
  5. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  6. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  7. xmlns:local="using:ExtraFeatures2022"
  8. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  9. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  10. mc:Ignorable="d"
  11. Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  12.  
  13. <StackPanel Margin="20">
  14. <Button Click="Button_Click" Margin="20">Käynnistä raskas operaatio</Button>
  15. <Button Margin="20">Testipainike</Button>
  16. <TextBlock Name="ResultText" Margin="20" FontSize="28" FontWeight="Bold"></TextBlock>
  17.  
  18.  
  19. <!-- nappi jolla vaihdetaan aktiivista kieltä -->
  20. <Button Click="Button_Click_1" Margin="20">FI/EN</Button>
  21.  
  22. <!-- x:Uid hakee Strings-kansiosta aktiivisen kielen kansiosta -->
  23. <!-- Resources-tiedostosta Greeting.Text nimisen kielikäännöksen -->
  24. <!-- ks. ohje https://docs.microsoft.com/en-us/windows/uwp/app-resources/localize-strings-ui-manifest -->
  25. <TextBlock x:Uid="Greeting" FontSize="28" FontWeight="Bold" Margin="20"></TextBlock>
  26. </StackPanel>
  27. </Page>
  28.  
  29.  
  30. <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  31. <StackPanel>
  32. <TextBox Name="Input_Box"></TextBox>
  33. <Button Click="AddData">Add</Button>
  34. <ListView Name="Output">
  35. <ListView.ItemTemplate>
  36. <DataTemplate>
  37. <TextBlock Text="{Binding}"/>
  38. </DataTemplate>
  39. </ListView.ItemTemplate>
  40. </ListView>
  41. </StackPanel>
  42. </Grid>
  43.  
  44. <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  45. <StackPanel>
  46. <TextBox Name="Input_Box"></TextBox>
  47. <Button Click="AddData">Add</Button>
  48. <ListView Name="Output" RightTapped="ListView_RightTapped">
  49. <ListView.ItemTemplate>
  50. <DataTemplate>
  51. <TextBlock Text="{Binding}"/>
  52. </DataTemplate>
  53. </ListView.ItemTemplate>
  54. <ListView.Resources>
  55. <MenuFlyout x:Name="allContactsMenuFlyout">
  56. <MenuFlyout.Items>
  57. <MenuFlyoutItem x:Name="Edit" Text="Edit" />
  58. <MenuFlyoutItem x:Name="Remove" Text="Remove" Click="Remove_Click" />
  59. </MenuFlyout.Items>
  60. </MenuFlyout>
  61. </ListView.Resources>
  62. </ListView>
  63. </StackPanel>
  64. </Grid>
  65.  
  66. <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  67. <StackPanel>
  68. <TextBox Name="Input_Box"></TextBox>
  69. <Button Click="AddData">Add</Button>
  70. <ListView Name="Output" RightTapped="ListView_RightTapped">
  71. <ListView.ItemTemplate>
  72. <DataTemplate>
  73. <TextBlock Text="{Binding}"/>
  74. </DataTemplate>
  75. </ListView.ItemTemplate>
  76. <ListView.Resources>
  77. <MenuFlyout x:Name="allContactsMenuFlyout">
  78. <MenuFlyout.Items>
  79. <MenuFlyoutItem x:Name="Edit" Text="Edit" />
  80. <MenuFlyoutItem x:Name="Remove" Text="Remove" Click="Remove_Click" />
  81. </MenuFlyout.Items>
  82. </MenuFlyout>
  83. </ListView.Resources>
  84. </ListView>
  85. <Button Click="Button_Click">FI/EN</Button>
  86. </StackPanel>
  87. </Grid>
  88.  
  89. C#:
  90.  
  91. using System;
  92. using System.Collections.Generic;
  93. using System.ComponentModel;
  94. using System.Diagnostics;
  95. using System.IO;
  96. using System.Linq;
  97. using System.Net;
  98. using System.Net.Http;
  99. using System.Runtime.InteropServices.WindowsRuntime;
  100. using System.Threading.Tasks;
  101. using Windows.Foundation;
  102. using Windows.Foundation.Collections;
  103. using Windows.Globalization;
  104. using Windows.Storage;
  105. using Windows.UI.Core;
  106. using Windows.UI.Xaml;
  107. using Windows.UI.Xaml.Controls;
  108. using Windows.UI.Xaml.Controls.Primitives;
  109. using Windows.UI.Xaml.Data;
  110. using Windows.UI.Xaml.Input;
  111. using Windows.UI.Xaml.Media;
  112. using Windows.UI.Xaml.Navigation;
  113.  
  114. // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
  115.  
  116. namespace ExtraFeatures2022
  117. {
  118. /// <summary>
  119. /// An empty page that can be used on its own or navigated to within a Frame.
  120. /// </summary>
  121. public sealed partial class MainPage : Page
  122. {
  123. public MainPage()
  124. {
  125. this.InitializeComponent();
  126. }
  127.  
  128. // jos event handlerissa on await-komento, metodin pitää olla async
  129. // private void Button_Click(object sender, RoutedEventArgs e)
  130. private async void Button_Click(object sender, RoutedEventArgs e)
  131. {
  132. //SlowCode();
  133. //_ = BigWorkBackground();
  134. //var t = Task.Run(() => TaskWorkBackground());
  135. //await AwaitBackgroundWork();
  136. //DownloadVideosNoThreadingAsync();
  137. await DownloadVideosThreaded();
  138. }
  139.  
  140. private async Task AwaitBackgroundWork()
  141. {
  142. Debug.WriteLine("Vaihe 1");
  143. ResultText.Text = "Vaihe 1...";
  144.  
  145. await Task.Delay(3000);
  146. Debug.WriteLine("Vaihe 2");
  147. ResultText.Text = "Vaihe 2...";
  148. await Task.Delay(3000);
  149. Debug.WriteLine("Vaihe 3");
  150. ResultText.Text = "Vaihe 3...";
  151. await Task.Delay(3000);
  152.  
  153. ResultText.Text = "Kaikki työ tehty!";
  154. }
  155.  
  156. public async Task TaskWorkBackground()
  157. {
  158. Debug.WriteLine("Aloitetaan työ");
  159. // jos haluamme Taskin sisällä päästä käsiksi UI Threadiin, eli käyttöliittymään, tarvitsemme Dispatcheria:
  160. await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
  161. ResultText.Text = "Aloitetaan työ.";
  162. });
  163.  
  164. // simuloidaan kolme vaihetta, await-versio Thread.Sleepistä
  165. await Task.Delay(3000);
  166. await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
  167. ResultText.Text = "Vaihe 1";
  168. });
  169.  
  170. await Task.Delay(3000);
  171. await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
  172. ResultText.Text = "Vaihe 2";
  173. });
  174. await Task.Delay(3000);
  175.  
  176. await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
  177. ResultText.Text = "Vaihe 3";
  178. });
  179.  
  180.  
  181. Debug.WriteLine("Kaikki työ tehty.");
  182. // jos haluamme Taskin sisällä päästä käsiksi UI Threadiin, eli käyttöliittymään, tarvitsemme Dispatcheria:
  183. await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
  184. ResultText.Text = "Kaikki työ tehty!";
  185. });
  186.  
  187. }
  188.  
  189. // backgroundworker-versio säikeistämisestä
  190. // ei suositeltava tapa enää nykyään
  191. public async System.Threading.Tasks.Task BigWorkBackground()
  192. {
  193. // luodaan worker
  194. BackgroundWorker workerThread = new BackgroundWorker();
  195.  
  196. // tässä tapauksessa emme mahdollista säikeen peruuttamista
  197. workerThread.WorkerSupportsCancellation = false;
  198.  
  199. // haluamme kuitenkin antaa välitietoja miten työ etenee
  200. workerThread.WorkerReportsProgress = true;
  201.  
  202. workerThread.DoWork += delegate (object s, DoWorkEventArgs args)
  203. {
  204.  
  205. // simuloidaan hidasta koodia Thread.Sleepin avulla
  206. Debug.WriteLine("Vaihe 1");
  207. workerThread.ReportProgress(1);
  208. System.Threading.Thread.Sleep(3000);
  209. Debug.WriteLine("Vaihe 2");
  210. workerThread.ReportProgress(2);
  211. System.Threading.Thread.Sleep(3000);
  212. Debug.WriteLine("Vaihe 3");
  213. workerThread.ReportProgress(3);
  214. System.Threading.Thread.Sleep(3000);
  215.  
  216.  
  217. };
  218.  
  219. workerThread.ProgressChanged += delegate (object s, ProgressChangedEventArgs e)
  220. {
  221. ResultText.Text = "Vaihe " + e.ProgressPercentage;
  222. };
  223.  
  224. // kun DoWork on suoritettu loppuun
  225. workerThread.RunWorkerCompleted += delegate (object s, RunWorkerCompletedEventArgs args)
  226. {
  227. ResultText.Text = "Kaikki työt suoritettu!";
  228. };
  229.  
  230. // käynnistä säie!
  231. workerThread.RunWorkerAsync();
  232.  
  233. }
  234.  
  235. private void SlowCode()
  236. {
  237. // simuloidaan hidasta koodia Thread.Sleepin avulla
  238. Debug.WriteLine("Vaihe 1");
  239. ResultText.Text = "Vaihe 1";
  240. System.Threading.Thread.Sleep(3000);
  241. Debug.WriteLine("Vaihe 2");
  242. ResultText.Text = "Vaihe 2";
  243. System.Threading.Thread.Sleep(3000);
  244. Debug.WriteLine("Vaihe 3");
  245. ResultText.Text = "Vaihe 3";
  246. System.Threading.Thread.Sleep(3000);
  247.  
  248. ResultText.Text = "Kaikki tehty.";
  249. }
  250.  
  251. private async Task DownloadVideosThreaded()
  252. {
  253. // haetaan ohjelman tallennuskansio Windowsista
  254. Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
  255.  
  256. // luodaan apukansio "myvideos"
  257. // korvataan vanha kansio, jos se löytyy entuudestaan
  258. StorageFolder newFolder = await storageFolder.CreateFolderAsync("myvideos", CreationCollisionOption.ReplaceExisting);
  259.  
  260. // tulostetaan testimielessä kansion sijainti konsoliin
  261. Debug.WriteLine(storageFolder.Path.ToString());
  262.  
  263. // lisätään pari testivideota ladattavaksi listaan
  264. List<string> videos = new List<string>();
  265. videos.Add("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/VolkswagenGTIReview.mp4");
  266. videos.Add("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4");
  267. videos.Add("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4");
  268.  
  269. // pidetään muuttujassa yllä seuraavaksi tallennettavan videon numero
  270. int fileNumber = 1;
  271.  
  272. // luodaan http-client, jolla voimme ladata internetistä dataa
  273. // joudumme awaitin vuoksi käyttämään tätä, sillä WebClient ei toimi awaitin kanssa
  274. // tämä johtuu siitä, että WebClient on itse toteuttanut säikeistämisen eri tavalla
  275. HttpClient httpc = new HttpClient();
  276.  
  277. // käydään videot silmukassa läpi
  278. foreach (String video in videos)
  279. {
  280. // päivitetään tilanneviestit
  281. Debug.WriteLine("Start download: " + video);
  282. ResultText.Text = "Downloading video " + fileNumber;
  283.  
  284. // ladataan videon sisältö tavutaulukkoon
  285. byte[] stringData = await httpc.GetByteArrayAsync(video);
  286.  
  287. // tehdään uudelle videolle uusi tiedosto apukansioon (myvideos)
  288. Windows.Storage.StorageFile file = await storageFolder.CreateFileAsync(@"\myvideos\video" + fileNumber + ".mp4",
  289. Windows.Storage.CreationCollisionOption.ReplaceExisting);
  290.  
  291. // tulostetaan testimielessä kansion polku konsoliin,
  292. // jotta voimme testata helpommin sitä
  293. Debug.WriteLine(storageFolder.Path.ToString());
  294.  
  295. // kirjoitetaan videon sisältö uuteen tiedostoon
  296. await Windows.Storage.FileIO.WriteBytesAsync(file, stringData);
  297.  
  298. // kasvatetaan numeroa seuraavaa tiedostoa varten
  299. fileNumber += 1;
  300. Debug.WriteLine("Download finished.");
  301. }
  302.  
  303. ResultText.Text = "All downloads done!";
  304. }
  305.  
  306. private async Task DownloadVideosNoThreadingAsync()
  307. {
  308. // testivideot otettu täältä: https://gist.github.com/jsturgis/3b19447b304616f18657
  309. List<string> videos = new List<string>();
  310. videos.Add("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/VolkswagenGTIReview.mp4");
  311. videos.Add("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4");
  312.  
  313. // haetaan sovelluksen tallenuspaikka, ja luodaan uusi kansio videoille
  314. Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
  315. StorageFolder newFolder = await storageFolder.CreateFolderAsync("myvideos", CreationCollisionOption.ReplaceExisting);
  316.  
  317. // tulostetaan konsoliin testaamista varten kansion polku
  318. Debug.WriteLine(storageFolder.Path.ToString());
  319.  
  320. // ensimmäinen tiedosto alkaa numerosta 1
  321. int fileNumber = 1;
  322.  
  323. // luodaan web client
  324. var client = new WebClient();
  325.  
  326. // ladataan yksitellen videot
  327. foreach (String video in videos)
  328. {
  329.  
  330. Debug.WriteLine("Downloading video " + fileNumber);
  331.  
  332. // jos käytössä BackgroundWorker, tämä pitää olla päällä
  333. //workerThread.ReportProgress(fileNumber);
  334.  
  335. // lataa tiedosto ja tallenna se tallennustilaan
  336. client.DownloadFile(new Uri(video), storageFolder.Path.ToString() + @"\myvideos\video" + fileNumber + ".mp4");
  337. Debug.WriteLine(storageFolder.Path.ToString() + @"\myvideos\video" + fileNumber + ".mp4");
  338.  
  339. // kasvata numeroa seuraavaa tiedostoa varten
  340. fileNumber += 1;
  341.  
  342. }
  343. }
  344.  
  345. private void Button_Click_1(object sender, RoutedEventArgs e)
  346. {
  347. // vaihdetaan kieleksi joko suomi tai englanti, riippuu
  348. // kumpi on vaktiivinen
  349. if(ApplicationLanguages.PrimaryLanguageOverride == "fi")
  350. {
  351. ApplicationLanguages.PrimaryLanguageOverride = "en-US";
  352. }
  353. else
  354. {
  355. ApplicationLanguages.PrimaryLanguageOverride = "fi";
  356. }
  357.  
  358. // navigoidaan sivulle uudestaan jotta vaihdettu kieli näkyy
  359. Frame.Navigate(this.GetType());
  360. }
  361. }
  362. }
  363.  
  364. public App()
  365. {
  366. this.InitializeComponent();
  367. this.Suspending += OnSuspending;
  368.  
  369. DataAccess.InitializeDatabase();
  370. }
  371.  
  372. // DataAccess
  373.  
  374. public static class DataAccess
  375. {
  376.  
  377. public async static void InitializeDatabase()
  378. {
  379. await ApplicationData.Current.LocalFolder.CreateFileAsync("sqliteSample.db", CreationCollisionOption.OpenIfExists);
  380. string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db");
  381. using (SqliteConnection db =
  382. new SqliteConnection($"Filename={dbpath}"))
  383. {
  384. db.Open();
  385.  
  386. String tableCommand = "CREATE TABLE IF NOT " +
  387. "EXISTS MyTable (Primary_Key INTEGER PRIMARY KEY, " +
  388. "Text_Entry NVARCHAR(2048) NULL)";
  389.  
  390. SqliteCommand createTable = new SqliteCommand(tableCommand, db);
  391.  
  392. createTable.ExecuteReader();
  393. }
  394. }
  395.  
  396. public static void AddData(string inputText)
  397. {
  398. string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db");
  399. using (SqliteConnection db =
  400. new SqliteConnection($"Filename={dbpath}"))
  401. {
  402. db.Open();
  403.  
  404. SqliteCommand insertCommand = new SqliteCommand();
  405. insertCommand.Connection = db;
  406.  
  407. // Use parameterized query to prevent SQL injection attacks
  408. insertCommand.CommandText = "INSERT INTO MyTable VALUES (NULL, @Entry);";
  409. insertCommand.Parameters.AddWithValue("@Entry", inputText);
  410.  
  411. insertCommand.ExecuteReader();
  412.  
  413. db.Close();
  414. }
  415.  
  416. }
  417.  
  418. public static void RemoveRow(string inputText)
  419. {
  420. string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db");
  421. using (SqliteConnection db =
  422. new SqliteConnection($"Filename={dbpath}"))
  423. {
  424. db.Open();
  425.  
  426. SqliteCommand insertCommand = new SqliteCommand();
  427. insertCommand.Connection = db;
  428.  
  429. // Use parameterized query to prevent SQL injection attacks
  430. insertCommand.CommandText = "DELETE FROM MyTable WHERE Text_Entry = @Entry;";
  431. insertCommand.Parameters.AddWithValue("@Entry", inputText);
  432.  
  433. insertCommand.ExecuteReader();
  434.  
  435. db.Close();
  436. }
  437. }
  438.  
  439. public static List<String> GetData()
  440. {
  441. List<String> entries = new List<string>();
  442.  
  443. string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db");
  444. using (SqliteConnection db =
  445. new SqliteConnection($"Filename={dbpath}"))
  446. {
  447. db.Open();
  448.  
  449. SqliteCommand selectCommand = new SqliteCommand
  450. ("SELECT Text_Entry from MyTable", db);
  451.  
  452. SqliteDataReader query = selectCommand.ExecuteReader();
  453.  
  454. while (query.Read())
  455. {
  456. entries.Add(query.GetString(0));
  457. }
  458.  
  459. db.Close();
  460. }
  461.  
  462. return entries;
  463. }
  464. }
  465.  
  466.  
  467. public sealed partial class MainPage : Page
  468. {
  469. public MainPage()
  470. {
  471. this.InitializeComponent();
  472.  
  473. Output.ItemsSource = DataAccess.GetData();
  474. }
  475.  
  476. private void AddData(object sender, RoutedEventArgs e)
  477. {
  478. DataAccess.AddData(Input_Box.Text);
  479.  
  480. Output.ItemsSource = DataAccess.GetData();
  481. }
  482.  
  483. private String activeRow = "";
  484.  
  485. private void ListView_RightTapped(object sender, RightTappedRoutedEventArgs e)
  486. {
  487. ListView listView = (ListView)sender;
  488. allContactsMenuFlyout.ShowAt(listView, e.GetPosition(listView));
  489. var a = ((FrameworkElement)e.OriginalSource).DataContext;
  490. activeRow = a.ToString();
  491. }
  492.  
  493. private void Remove_Click(object sender, RoutedEventArgs e)
  494. {
  495. DataAccess.RemoveRow(activeRow);
  496. Output.ItemsSource = DataAccess.GetData();
  497.  
  498. }
  499. }
  500.  
  501. public sealed partial class MainPage : Page
  502. {
  503. public MainPage()
  504. {
  505. this.InitializeComponent();
  506.  
  507. Output.ItemsSource = DataAccess.GetData();
  508. }
  509.  
  510. private void AddData(object sender, RoutedEventArgs e)
  511. {
  512. DataAccess.AddData(Input_Box.Text);
  513.  
  514. Output.ItemsSource = DataAccess.GetData();
  515. }
  516.  
  517. private String activeRow = "";
  518.  
  519. private void ListView_RightTapped(object sender, RightTappedRoutedEventArgs e)
  520. {
  521. ListView listView = (ListView)sender;
  522. allContactsMenuFlyout.ShowAt(listView, e.GetPosition(listView));
  523. var a = ((FrameworkElement)e.OriginalSource).DataContext;
  524. activeRow = a.ToString();
  525. }
  526.  
  527. private void Remove_Click(object sender, RoutedEventArgs e)
  528. {
  529. // varmistetaan käyttäjältä että hän varmasti haluaa poistaa rivin
  530. DisplayDeleteRowDialog();
  531.  
  532. }
  533.  
  534. private async void DisplayDeleteRowDialog()
  535. {
  536. ContentDialog deleteFileDialog = new ContentDialog
  537. {
  538. Title = "Poistetaanko rivi?",
  539. Content = "Poistettua riviä ei voi enää palauttaa.",
  540. PrimaryButtonText = "Kyllä",
  541. CloseButtonText = "Ei"
  542. };
  543.  
  544. ContentDialogResult result = await deleteFileDialog.ShowAsync();
  545.  
  546. // Delete the file if the user clicked the primary button.
  547. /// Otherwise, do nothing.
  548. if (result == ContentDialogResult.Primary)
  549. {
  550. // Delete the file.
  551. DataAccess.RemoveRow(activeRow);
  552. Output.ItemsSource = DataAccess.GetData();
  553. }
  554. else
  555. {
  556. // The user clicked the CLoseButton, pressed ESC, Gamepad B, or the system back button.
  557. // Do nothing.
  558. }
  559. }
  560. }
  561.  
  562.  
  563. public sealed partial class MainPage : Page
  564. {
  565. public MainPage()
  566. {
  567. this.InitializeComponent();
  568.  
  569. Output.ItemsSource = DataAccess.GetData();
  570. }
  571.  
  572. private void AddData(object sender, RoutedEventArgs e)
  573. {
  574. DataAccess.AddData(Input_Box.Text);
  575.  
  576. Output.ItemsSource = DataAccess.GetData();
  577. }
  578.  
  579. private String activeRow = "";
  580.  
  581. private void ListView_RightTapped(object sender, RightTappedRoutedEventArgs e)
  582. {
  583. ListView listView = (ListView)sender;
  584. allContactsMenuFlyout.ShowAt(listView, e.GetPosition(listView));
  585. var a = ((FrameworkElement)e.OriginalSource).DataContext;
  586. activeRow = a.ToString();
  587. }
  588.  
  589. private void Remove_Click(object sender, RoutedEventArgs e)
  590. {
  591. // varmistetaan käyttäjältä että hän varmasti haluaa poistaa rivin
  592. DisplayDeleteRowDialog();
  593.  
  594. }
  595.  
  596. private async void DisplayDeleteRowDialog()
  597. {
  598. // ladataan kielikäännös resurssitiedostosta
  599. // tässä tapauksessa projektissa Strings-kansio, jossa en-US ja fi-kansiot. molemmissa Resources.resw
  600. var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
  601.  
  602. ContentDialog deleteFileDialog = new ContentDialog
  603. {
  604. // Resourcesissa on DeleteTitle.Text => käytetään / -merkkiä pisteen sijasta
  605. Title = resourceLoader.GetString("DeleteTitle/Text"),
  606. Content = "Poistettua riviä ei voi enää palauttaa.",
  607. PrimaryButtonText = "Kyllä",
  608. CloseButtonText = "Ei"
  609. };
  610.  
  611. ContentDialogResult result = await deleteFileDialog.ShowAsync();
  612.  
  613. // Delete the file if the user clicked the primary button.
  614. /// Otherwise, do nothing.
  615. if (result == ContentDialogResult.Primary)
  616. {
  617. // Delete the file.
  618. DataAccess.RemoveRow(activeRow);
  619. Output.ItemsSource = DataAccess.GetData();
  620. }
  621. else
  622. {
  623. // The user clicked the CLoseButton, pressed ESC, Gamepad B, or the system back button.
  624. // Do nothing.
  625. }
  626. }
  627.  
  628. private void Button_Click(object sender, RoutedEventArgs e)
  629. {
  630. // vaihdetaan kieleksi joko suomi tai englanti, riippuu
  631. // kumpi on vaktiivinen
  632. if (ApplicationLanguages.PrimaryLanguageOverride == "fi")
  633. {
  634. ApplicationLanguages.PrimaryLanguageOverride = "en-US";
  635. }
  636. else
  637. {
  638. ApplicationLanguages.PrimaryLanguageOverride = "fi";
  639. }
  640.  
  641. // navigoidaan sivulle uudestaan jotta vaihdettu kieli näkyy
  642. Frame.Navigate(this.GetType());
  643. }
  644. }
Advertisement
Add Comment
Please, Sign In to add comment