Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- XAML:
- <!-- Parallax-efekti valokuvalla --!
- <Grid>
- <ParallaxView Source="{x:Bind ForegroundElement}" VerticalShift="50">
- <!-- Background element -->
- <Image x:Name="BackgroundImage" Source="/Assets/mountain.jpg"
- Stretch="UniformToFill"/>
- </ParallaxView>
- <!-- Foreground element -->
- <ListView x:Name="ForegroundElement" Width="400">
- <ListViewItem Margin="10" Background="White">Valinta 1</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 2</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 3</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 4</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 5</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 6</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 7</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 8</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 9</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 10</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 11</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 12</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 13</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 14</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 15</ListViewItem>
- <ListViewItem Margin="10" Background="White">Valinta 16</ListViewItem>
- </ListView>
- </Grid>
- <!-- RatingControl, arvostelu-elementti -->
- <StackPanel>
- <TextBlock FontWeight="Bold" FontSize="44" Margin="20"><Run Text="Exercise 4!"/></TextBlock>
- <Viewbox Width="600">
- <RatingControl ValueChanged="RatingControl_ValueChanged">
- <RatingControl.Resources>
- <SolidColorBrush x:Key="RatingControlSelectedForeground" Color="DarkSlateBlue" />
- <SolidColorBrush Color="LightSteelBlue" x:Key="RatingControlUnselectedForeground" />
- </RatingControl.Resources>
- </RatingControl>
- </Viewbox>
- <TextBlock FontWeight="Bold" FontSize="44" Margin="20" Name="RatingText"></TextBlock>
- </StackPanel>
- C#:
- private void RatingControl_ValueChanged(RatingControl sender, object args)
- {
- RatingText.Text = sender.Value.ToString();
- if(sender.Value == 5)
- {
- RatingText.Text = "VIIS KAUTTA VIIS!";
- }
- }
- // TIEDOSTOON KIRJOITTAMINEN JA TIEDOSTOSTA LUKEMINEN
- private async System.Threading.Tasks.Task ReadFileAsync()
- {
- // haetaan Windowsista kansio, johon tällä ohjelmalla on kirjoitusoikeus
- Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
- Windows.Storage.StorageFile file = await storageFolder.GetFileAsync("testUWP_2022.txt");
- // luetaan tiedoston sisältö muuttujaan
- string text = await Windows.Storage.FileIO.ReadTextAsync(file);
- // tulostetaan myös tiedoston polku että tiedetään mihin se oikeasti tallentui
- Debug.WriteLine(file.Path);
- Debug.WriteLine(text);
- }
- private async System.Threading.Tasks.Task WriteFileAsync()
- {
- Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
- Windows.Storage.StorageFile file = await storageFolder.CreateFileAsync("testUWP_2022.txt",
- Windows.Storage.CreationCollisionOption.OpenIfExists);
- // kirjoitetaan tiedostoon, RatingText on TextBlock XAMLissa
- await Windows.Storage.FileIO.WriteTextAsync(file, RatingText.Text);
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- // tallennetaan tiedostoon
- _ = WriteFileAsync();
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- // luetaan tiedostosta
- // alaviiva on ns. "discard", eli jos funktio/metodi ReadFileAsync() palauttaa jotain dataa
- // discard heittää palautetun datan saman tien pois käytöstä
- _ = ReadFileAsync();
- }
- // sovelluksen teemaa voi vaihtaa App-luokasta käsin, esim.
- // muista tällöin ottaa App.xaml:ista "RequestedTheme" pois kokonaan
- public App()
- {
- this.RequestedTheme = ApplicationTheme.Light;
- this.InitializeComponent();
- this.Suspending += OnSuspending;
- }
- // teeman vaihtaminen napista, pohja mistä lähteä liikkeelle
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- // Set theme for window root.
- if (Window.Current.Content is FrameworkElement frameworkElement)
- {
- Debug.WriteLine(frameworkElement.RequestedTheme.ToString());
- frameworkElement.RequestedTheme = ElementTheme.Dark;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment