tuomasvaltanen

Untitled

Feb 7th, 2022 (edited)
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. XAML:
  2.  
  3. <TextBox Name="UserTextBox" TextChanged="TextBox_TextChanged"></TextBox>
  4.  
  5.  
  6. <Slider Margin="20" Name="TestSlider" ValueChanged="Slider_ValueChanged" Minimum="1" Maximum="10"></Slider>
  7. <TextBlock Margin="20" Name="SliderText"></TextBlock>
  8.  
  9. <!-- -->
  10.  
  11. <StackPanel>
  12. <TextBlock Name="TitleText" Margin="20" FontSize="30">Event testing!</TextBlock>
  13. <ListBox Margin="20" Name="CitiesListBox" SelectionChanged="CitiesListBox_SelectionChanged">
  14. <ListBoxItem>Helsinki</ListBoxItem>
  15. <ListBoxItem>Lontoo</ListBoxItem>
  16. <ListBoxItem>Tukholma</ListBoxItem>
  17. <ListBoxItem>Pariisi</ListBoxItem>
  18. </ListBox>
  19.  
  20. <RadioButton GroupName="Newsletter" Checked="RadioButton_Checked">Kyllä</RadioButton>
  21. <RadioButton GroupName="Newsletter" Checked="RadioButton_Checked">Ei</RadioButton>
  22.  
  23. <CheckBox Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked">Night mode</CheckBox>
  24.  
  25. <Border Name="NightModeBorder" Width="100" Height="100"></Border>
  26.  
  27. </StackPanel>
  28.  
  29. <!-- NavigationView, taustavärin vaihtaminen -->
  30. <Page.Resources>
  31. <SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="LightSkyBlue"/>
  32. <SolidColorBrush x:Key="NavigationViewDefaultPaneBackground" Color="LightSkyBlue" />
  33. </Page.Resources>
  34.  
  35. C#:
  36.  
  37. private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  38. {
  39. String txt = UserTextBox.Text;
  40. int amount = txt.Length;
  41. Debug.WriteLine("Käyttäjä kirjoittaa jotakin...");
  42. Debug.WriteLine(txt);
  43. }
  44.  
  45. private void Page_KeyDown(object sender, KeyRoutedEventArgs e)
  46. {
  47. if (e.Key == VirtualKey.F2)
  48. {
  49. Debug.WriteLine("Painoit Help-nappia! Tähän tulee joskus hyvät ohjeet.");
  50. }
  51.  
  52. }
  53.  
  54. private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
  55. {
  56. String value = TestSlider.Value.ToString();
  57. Debug.WriteLine(value);
  58.  
  59. // varmistetaan että SliderText on jo valmis ulkoasussa
  60. if (SliderText != null)
  61. {
  62. SliderText.Text = value;
  63. }
  64. }
  65.  
  66. // toinen tiedosto
  67.  
  68. private void CitiesListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  69. {
  70. ListBoxItem lbi = CitiesListBox.SelectedItem as ListBoxItem;
  71. String txt = lbi.Content as String;
  72.  
  73. TitleText.Text = txt;
  74. }
  75.  
  76. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  77. {
  78. RadioButton radio = sender as RadioButton;
  79.  
  80. Debug.WriteLine(radio.Content.ToString());
  81. }
  82.  
  83. private void CheckBox_Checked(object sender, RoutedEventArgs e)
  84. {
  85. SolidColorBrush mySolidColorBrush = new SolidColorBrush(Windows.UI.Colors.DarkOrange);
  86.  
  87. // tämän jälkeen esim. Borderin (Name = SomeBorder) taustaväri:
  88. NightModeBorder.Background = mySolidColorBrush;
  89. }
  90.  
  91. private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
  92. {
  93. SolidColorBrush mySolidColorBrush = new SolidColorBrush(Windows.UI.Colors.Transparent);
  94.  
  95. // tämän jälkeen esim. Borderin (Name = SomeBorder) taustaväri:
  96. NightModeBorder.Background = mySolidColorBrush;
  97. }
  98.  
  99. // tämä vaatii että Page-controlissa on: Loaded="Page_Loaded"
  100. private void Page_Loaded(object sender, RoutedEventArgs e)
  101. {
  102. Debug.WriteLine("Page_Loaded");
  103. }
  104.  
  105. // parametrien siirtäminen Pagelta toiselle
  106.  
  107. // parametrien lähettäminen ensimmäisellä sivulla
  108. // Aåå.xaml.cs -tiedosto, lisää: public Boolean NightMode { get; set; }
  109. private void Button_Click_4(object sender, RoutedEventArgs e)
  110. {
  111. (App.Current as App).NightMode = true;
  112.  
  113. String param = "157834";
  114. this.Frame.Navigate(typeof(EventTesting), param);
  115. }
  116.  
  117. // vastaanottaminen toisella sivulla
  118. protected override void OnNavigatedTo(NavigationEventArgs e)
  119. {
  120. base.OnNavigatedTo(e);
  121. Debug.WriteLine(e.Parameter);
  122.  
  123. Debug.WriteLine((App.Current as App).NightMode);
  124. }
  125.  
  126. // jos halutaan siirtää monta parametria, tehdään oma apuluokka
  127.  
  128. public class MovieParameters
  129. {
  130. public String Title { get; set; }
  131. public int Year { get; set; }
  132. }
  133.  
  134. // vastaanottaminen
  135. protected override void OnNavigatedTo(NavigationEventArgs e)
  136. {
  137. base.OnNavigatedTo(e);
  138.  
  139. MovieParameters mp = e.Parameter as MovieParameters;
  140. Debug.WriteLine(mp.Title);
  141.  
  142. }
  143.  
  144. // lähettäminen
  145. private void Button_Click_4(object sender, RoutedEventArgs e)
  146. {
  147.  
  148. MovieParameters mp = new MovieParameters();
  149. mp.Title = "Pulp Fiction";
  150. mp.Year = 1994;
  151.  
  152. this.Frame.Navigate(typeof(EventTesting), mp);
  153. }
  154.  
  155. // tämä MainPage() -konstruktoriin, jolloin ei tarvitse itse päivittää projektin nimeä
  156. // NavigationView -pohjaan
  157.  
  158. projectName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
Add Comment
Please, Sign In to add comment