Advertisement
tuomasvaltanen

Untitled

Mar 4th, 2021 (edited)
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. XAML:
  2.  
  3. <Button Click="Button_Click_1" Margin="20">Vaihda sivua!</Button>
  4.  
  5. <Button Click="Button_Click_2">RelativePanel!</Button>
  6.  
  7. <Button Click="Button_Click_3">Grid!</Button>
  8.  
  9. <Button Click="Button_Click_4">Tapahtumat!</Button>
  10.  
  11. ---------------------
  12.  
  13. <ComboBox Name="FoodList" SelectionChanged="ComboBox_SelectionChanged">
  14. <ComboBoxItem>Peruna</ComboBoxItem>
  15. <ComboBoxItem>Vichy</ComboBoxItem>
  16. <ComboBoxItem>Kahvi</ComboBoxItem>
  17. </ComboBox>
  18.  
  19. <TextBlock Margin="30" FontSize="30" Name="FoodText"></TextBlock>
  20.  
  21. -------------
  22. <Grid>
  23. <Grid.ColumnDefinitions>
  24. <ColumnDefinition Width="*" />
  25. <ColumnDefinition Width="300" />
  26. </Grid.ColumnDefinitions>
  27. <Grid.RowDefinitions>
  28. <RowDefinition Height="200" />
  29. <RowDefinition />
  30. </Grid.RowDefinitions>
  31.  
  32. <Rectangle Grid.Row="0" Grid.Column="0" Fill="DarkSalmon" />
  33. <Rectangle Grid.Row="0" Grid.Column="1" Fill="Green" />
  34. <Rectangle Grid.Row="1" Grid.Column="0" Fill="NavajoWhite" />
  35. <Rectangle Grid.Row="1" Grid.Column="1" Fill="Pink" />
  36.  
  37. </Grid>
  38. ---------------
  39. <Grid>
  40. <Grid.ColumnDefinitions>
  41. <ColumnDefinition Width="*" />
  42. <ColumnDefinition Width="150"/>
  43. <ColumnDefinition Width="300" />
  44. </Grid.ColumnDefinitions>
  45. <Grid.RowDefinitions>
  46. <RowDefinition Height="200" />
  47. <RowDefinition />
  48. </Grid.RowDefinitions>
  49.  
  50. <Rectangle Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Fill="DarkSalmon" />
  51.  
  52.  
  53. <Rectangle Grid.Row="1" Grid.Column="0" Fill="NavajoWhite" />
  54. <Rectangle Grid.Row="1" Grid.Column="1" Fill="Pink" />
  55. <Rectangle Grid.Row="1" Grid.Column="2" Fill="SandyBrown" />
  56.  
  57. </Grid>
  58.  
  59. --------------
  60. <StackPanel Margin="30">
  61.  
  62. <Border>
  63. <TextBlock Name="MouseText"
  64. PointerEntered="MouseText_PointerEntered"
  65. PointerExited="MouseText_PointerExited"
  66. FontSize="60"
  67. Width="120">
  68. OFF
  69. </TextBlock>
  70. </Border>
  71.  
  72. <TextBox TextChanged="TextBox_TextChanged"></TextBox>
  73.  
  74. <Slider Name="NumberSlider" Minimum="1" Maximum="5" ValueChanged="NumberSlider_ValueChanged" />
  75. <TextBlock Name="SliderText"></TextBlock>
  76.  
  77. <CheckBox Margin="10">Hyväksyn käyttöehdot</CheckBox>
  78. <RadioButton Margin="10" GroupName="confirmation">Kyllä</RadioButton>
  79. <RadioButton Margin="10" GroupName="confirmation">Ei</RadioButton>
  80.  
  81. </StackPanel>
  82.  
  83.  
  84. C#:
  85.  
  86.  
  87. private void Button_Click_1(object sender, RoutedEventArgs e)
  88. {
  89. // vaihdetaan sivua toiseen Pageen
  90. this.Frame.Navigate(typeof(SecondPage));
  91. }
  92.  
  93. private void Button_Click_2(object sender, RoutedEventArgs e)
  94. {
  95. // vaihdetaan sivua toiseen Pageen
  96. this.Frame.Navigate(typeof(RelativeTesting));
  97. }
  98.  
  99. private void Button_Click_3(object sender, RoutedEventArgs e)
  100. {
  101. this.Frame.Navigate(typeof(GridTesting));
  102. }
  103.  
  104. private void Button_Click_4(object sender, RoutedEventArgs e)
  105. {
  106. this.Frame.Navigate(typeof(EventTesting));
  107. }
  108. -------------------
  109.  
  110. // navigoidaan toiselle sivulle, esim Button Clickissä
  111. // jos sivu on SecondPage.xaml, silloin:
  112. this.Frame.Navigate(typeof(SecondPage));
  113.  
  114. -----------------
  115. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  116. {
  117. // ensin haetaan aktiivinen ComboBoxItem...
  118. ComboBoxItem cb = FoodList.SelectedItem as ComboBoxItem;
  119.  
  120. // ... ja sitten ComboBoxItemistä haetaan teksti
  121. string value = cb.Content.ToString();
  122.  
  123. // asetetaan teksti TextBlockiin
  124. FoodText.Text = value;
  125. }
  126.  
  127. ---------------------------
  128.  
  129.  
  130. private void MouseText_PointerEntered(object sender, PointerRoutedEventArgs e)
  131. {
  132. MouseText.Text = "ON!";
  133. }
  134.  
  135. private void MouseText_PointerExited(object sender, PointerRoutedEventArgs e)
  136. {
  137. MouseText.Text = "OFF";
  138. }
  139.  
  140. private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  141. {
  142. Debug.WriteLine("Joku kirjoittaa nyt jotakin!");
  143. }
  144.  
  145. private void NumberSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
  146. {
  147. Debug.WriteLine(NumberSlider.Value.ToString());
  148.  
  149. if (SliderText != null)
  150. {
  151. SliderText.Text = NumberSlider.Value.ToString();
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement