tuomasvaltanen

Untitled

Feb 21st, 2022 (edited)
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. XAML:
  2.  
  3. <!-- Parallax-efekti valokuvalla --!
  4.  
  5. <Grid>
  6. <ParallaxView Source="{x:Bind ForegroundElement}" VerticalShift="50">
  7.  
  8. <!-- Background element -->
  9. <Image x:Name="BackgroundImage" Source="/Assets/mountain.jpg"
  10. Stretch="UniformToFill"/>
  11. </ParallaxView>
  12.  
  13. <!-- Foreground element -->
  14. <ListView x:Name="ForegroundElement" Width="400">
  15. <ListViewItem Margin="10" Background="White">Valinta 1</ListViewItem>
  16. <ListViewItem Margin="10" Background="White">Valinta 2</ListViewItem>
  17. <ListViewItem Margin="10" Background="White">Valinta 3</ListViewItem>
  18. <ListViewItem Margin="10" Background="White">Valinta 4</ListViewItem>
  19. <ListViewItem Margin="10" Background="White">Valinta 5</ListViewItem>
  20. <ListViewItem Margin="10" Background="White">Valinta 6</ListViewItem>
  21. <ListViewItem Margin="10" Background="White">Valinta 7</ListViewItem>
  22. <ListViewItem Margin="10" Background="White">Valinta 8</ListViewItem>
  23. <ListViewItem Margin="10" Background="White">Valinta 9</ListViewItem>
  24. <ListViewItem Margin="10" Background="White">Valinta 10</ListViewItem>
  25. <ListViewItem Margin="10" Background="White">Valinta 11</ListViewItem>
  26. <ListViewItem Margin="10" Background="White">Valinta 12</ListViewItem>
  27. <ListViewItem Margin="10" Background="White">Valinta 13</ListViewItem>
  28. <ListViewItem Margin="10" Background="White">Valinta 14</ListViewItem>
  29. <ListViewItem Margin="10" Background="White">Valinta 15</ListViewItem>
  30. <ListViewItem Margin="10" Background="White">Valinta 16</ListViewItem>
  31. </ListView>
  32. </Grid>
  33.  
  34.  
  35. <!-- RatingControl, arvostelu-elementti -->
  36.  
  37. <StackPanel>
  38. <TextBlock FontWeight="Bold" FontSize="44" Margin="20"><Run Text="Exercise 4!"/></TextBlock>
  39.  
  40. <Viewbox Width="600">
  41. <RatingControl ValueChanged="RatingControl_ValueChanged">
  42. <RatingControl.Resources>
  43. <SolidColorBrush x:Key="RatingControlSelectedForeground" Color="DarkSlateBlue" />
  44. <SolidColorBrush Color="LightSteelBlue" x:Key="RatingControlUnselectedForeground" />
  45. </RatingControl.Resources>
  46. </RatingControl>
  47. </Viewbox>
  48.  
  49. <TextBlock FontWeight="Bold" FontSize="44" Margin="20" Name="RatingText"></TextBlock>
  50.  
  51.  
  52. </StackPanel>
  53.  
  54. C#:
  55.  
  56. private void RatingControl_ValueChanged(RatingControl sender, object args)
  57. {
  58. RatingText.Text = sender.Value.ToString();
  59.  
  60. if(sender.Value == 5)
  61. {
  62. RatingText.Text = "VIIS KAUTTA VIIS!";
  63. }
  64. }
  65.  
  66. // TIEDOSTOON KIRJOITTAMINEN JA TIEDOSTOSTA LUKEMINEN
  67.  
  68. private async System.Threading.Tasks.Task ReadFileAsync()
  69. {
  70. // haetaan Windowsista kansio, johon tällä ohjelmalla on kirjoitusoikeus
  71. Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
  72. Windows.Storage.StorageFile file = await storageFolder.GetFileAsync("testUWP_2022.txt");
  73.  
  74. // luetaan tiedoston sisältö muuttujaan
  75. string text = await Windows.Storage.FileIO.ReadTextAsync(file);
  76.  
  77. // tulostetaan myös tiedoston polku että tiedetään mihin se oikeasti tallentui
  78. Debug.WriteLine(file.Path);
  79. Debug.WriteLine(text);
  80.  
  81. }
  82.  
  83. private async System.Threading.Tasks.Task WriteFileAsync()
  84. {
  85. Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
  86. Windows.Storage.StorageFile file = await storageFolder.CreateFileAsync("testUWP_2022.txt",
  87. Windows.Storage.CreationCollisionOption.OpenIfExists);
  88.  
  89. // kirjoitetaan tiedostoon, RatingText on TextBlock XAMLissa
  90. await Windows.Storage.FileIO.WriteTextAsync(file, RatingText.Text);
  91.  
  92. }
  93.  
  94. private void Button_Click(object sender, RoutedEventArgs e)
  95. {
  96. // tallennetaan tiedostoon
  97. _ = WriteFileAsync();
  98. }
  99.  
  100. private void Button_Click_1(object sender, RoutedEventArgs e)
  101. {
  102. // luetaan tiedostosta
  103. // alaviiva on ns. "discard", eli jos funktio/metodi ReadFileAsync() palauttaa jotain dataa
  104. // discard heittää palautetun datan saman tien pois käytöstä
  105. _ = ReadFileAsync();
  106. }
  107.  
  108. // sovelluksen teemaa voi vaihtaa App-luokasta käsin, esim.
  109. // muista tällöin ottaa App.xaml:ista "RequestedTheme" pois kokonaan
  110.  
  111. public App()
  112. {
  113. this.RequestedTheme = ApplicationTheme.Light;
  114.  
  115. this.InitializeComponent();
  116.  
  117. this.Suspending += OnSuspending;
  118. }
  119.  
  120. // teeman vaihtaminen napista, pohja mistä lähteä liikkeelle
  121.  
  122. private void Button_Click(object sender, RoutedEventArgs e)
  123. {
  124. // Set theme for window root.
  125. if (Window.Current.Content is FrameworkElement frameworkElement)
  126. {
  127. Debug.WriteLine(frameworkElement.RequestedTheme.ToString());
  128. frameworkElement.RequestedTheme = ElementTheme.Dark;
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment