Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- XAML:
- <TextBox Name="UserTextBox" TextChanged="TextBox_TextChanged"></TextBox>
- <Slider Margin="20" Name="TestSlider" ValueChanged="Slider_ValueChanged" Minimum="1" Maximum="10"></Slider>
- <TextBlock Margin="20" Name="SliderText"></TextBlock>
- <!-- -->
- <StackPanel>
- <TextBlock Name="TitleText" Margin="20" FontSize="30">Event testing!</TextBlock>
- <ListBox Margin="20" Name="CitiesListBox" SelectionChanged="CitiesListBox_SelectionChanged">
- <ListBoxItem>Helsinki</ListBoxItem>
- <ListBoxItem>Lontoo</ListBoxItem>
- <ListBoxItem>Tukholma</ListBoxItem>
- <ListBoxItem>Pariisi</ListBoxItem>
- </ListBox>
- <RadioButton GroupName="Newsletter" Checked="RadioButton_Checked">Kyllä</RadioButton>
- <RadioButton GroupName="Newsletter" Checked="RadioButton_Checked">Ei</RadioButton>
- <CheckBox Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked">Night mode</CheckBox>
- <Border Name="NightModeBorder" Width="100" Height="100"></Border>
- </StackPanel>
- <!-- NavigationView, taustavärin vaihtaminen -->
- <Page.Resources>
- <SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="LightSkyBlue"/>
- <SolidColorBrush x:Key="NavigationViewDefaultPaneBackground" Color="LightSkyBlue" />
- </Page.Resources>
- C#:
- private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- String txt = UserTextBox.Text;
- int amount = txt.Length;
- Debug.WriteLine("Käyttäjä kirjoittaa jotakin...");
- Debug.WriteLine(txt);
- }
- private void Page_KeyDown(object sender, KeyRoutedEventArgs e)
- {
- if (e.Key == VirtualKey.F2)
- {
- Debug.WriteLine("Painoit Help-nappia! Tähän tulee joskus hyvät ohjeet.");
- }
- }
- private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
- {
- String value = TestSlider.Value.ToString();
- Debug.WriteLine(value);
- // varmistetaan että SliderText on jo valmis ulkoasussa
- if (SliderText != null)
- {
- SliderText.Text = value;
- }
- }
- // toinen tiedosto
- private void CitiesListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- ListBoxItem lbi = CitiesListBox.SelectedItem as ListBoxItem;
- String txt = lbi.Content as String;
- TitleText.Text = txt;
- }
- private void RadioButton_Checked(object sender, RoutedEventArgs e)
- {
- RadioButton radio = sender as RadioButton;
- Debug.WriteLine(radio.Content.ToString());
- }
- private void CheckBox_Checked(object sender, RoutedEventArgs e)
- {
- SolidColorBrush mySolidColorBrush = new SolidColorBrush(Windows.UI.Colors.DarkOrange);
- // tämän jälkeen esim. Borderin (Name = SomeBorder) taustaväri:
- NightModeBorder.Background = mySolidColorBrush;
- }
- private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
- {
- SolidColorBrush mySolidColorBrush = new SolidColorBrush(Windows.UI.Colors.Transparent);
- // tämän jälkeen esim. Borderin (Name = SomeBorder) taustaväri:
- NightModeBorder.Background = mySolidColorBrush;
- }
- // tämä vaatii että Page-controlissa on: Loaded="Page_Loaded"
- private void Page_Loaded(object sender, RoutedEventArgs e)
- {
- Debug.WriteLine("Page_Loaded");
- }
- // parametrien siirtäminen Pagelta toiselle
- // parametrien lähettäminen ensimmäisellä sivulla
- // Aåå.xaml.cs -tiedosto, lisää: public Boolean NightMode { get; set; }
- private void Button_Click_4(object sender, RoutedEventArgs e)
- {
- (App.Current as App).NightMode = true;
- String param = "157834";
- this.Frame.Navigate(typeof(EventTesting), param);
- }
- // vastaanottaminen toisella sivulla
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- base.OnNavigatedTo(e);
- Debug.WriteLine(e.Parameter);
- Debug.WriteLine((App.Current as App).NightMode);
- }
- // jos halutaan siirtää monta parametria, tehdään oma apuluokka
- public class MovieParameters
- {
- public String Title { get; set; }
- public int Year { get; set; }
- }
- // vastaanottaminen
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- base.OnNavigatedTo(e);
- MovieParameters mp = e.Parameter as MovieParameters;
- Debug.WriteLine(mp.Title);
- }
- // lähettäminen
- private void Button_Click_4(object sender, RoutedEventArgs e)
- {
- MovieParameters mp = new MovieParameters();
- mp.Title = "Pulp Fiction";
- mp.Year = 1994;
- this.Frame.Navigate(typeof(EventTesting), mp);
- }
- // tämä MainPage() -konstruktoriin, jolloin ei tarvitse itse päivittää projektin nimeä
- // NavigationView -pohjaan
- projectName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
Add Comment
Please, Sign In to add comment