Windows Store-Apps

Message dialog (JS)

var dialog = new Windows.UI.Popups.MessageDialog('Hello World', 'Title');
dialog.showAsync();

Message dialog with callback (JS)

var dialog = new Windows.UI.Popups.MessageDialog('Hello World', 'Title');
dialog.showAsync().done(function(){
  document.getElementById('textBox').innerHTML = 'Toast closed.'
});

Message dialog (C#)

 MessageDialog dialog = new MessageDialog("Hello World", "Title");
dialog.ShowAsync();

Select an item in a ComboBox

Markup (XAML)

<TextBlock x:Name="pageTitle" />
 
<ComboBox x:Name="MyComboBox" SelectedIndex="0" SelectionChanged="MyComboBox_SelectionChanged">
  <ComboBoxItem Content="First Entry" />
</ComboBox>

Code Behind (C#)

private void MyComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  if (MyComboBox != null)
  {
    ComboBoxItem item = (ComboBoxItem) MyComboBox.SelectedItem;
    if (item != null)
    {
      pageTitle.Text = item.Content.ToString();
    }
  }
}

Dynamically add a new ComboBox item

Code Behind (C#)

ComboBoxItem item = new ComboBoxItem();
item.Content = "Second Entry";
MyComboBox.Items.Add(item);

Set different styles in snapped view

Markup (XAML)

<!-- Snapped View -->
<VisualState x:Name="Snapped">
  <Storyboard>
    <!-- Disable fullscreen style -->
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="fullScreenGrid" Storyboard.TargetProperty="Visibility">
      <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
    </ObjectAnimationUsingKeyFrames>
    <!-- Enable snapped style -->
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="snappedPanel" Storyboard.TargetProperty="Visibility">
      <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
    </ObjectAnimationUsingKeyFrames>
    <!-- Set page title properties -->
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
    </ObjectAnimationUsingKeyFrames>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Text">
      <DiscreteObjectKeyFrame KeyTime="0" Value="Hello World"/>
    </ObjectAnimationUsingKeyFrames>
  </Storyboard>
</VisualState>
</VisualStateGroup>

Programmatically respond to Snapped View

Code Behind (C#)

public MainPage()
{
  this.InitializeComponent();
  Window.Current.SizeChanged += OnSizeChanged;
}
 
private void OnSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
{
  switch (Windows.UI.ViewManagement.ApplicationView.Value)
  {
    case Windows.UI.ViewManagement.ApplicationViewState.Snapped:
      pageTitle.Text = "Snapped";
      break;
    default:
      pageTitle.Text = "Unsnapped";
      break;
  }
}

How to use StaticResource with C# or XAML

XAML

<TextBlock x:Name="pageTitle" Style="{StaticResource PageHeaderTextStyle}"/>

C#

pageTitle.Style = (Style) Application.Current.Resources["PageHeaderTextStyle"];

Troublefinder

Falls sowas Probleme macht:

foreach (var item in Tutorials.Instance.Categories) {}

Dann hilft:

if (Tutorials.Instance != null && Tutorials.Instance.Categories != null)
{
  foreach (var item in Tutorials.Instance.Categories) {}
}

Change grid column programmatically

<ListBox x:Name="TableOfContents" 
         Grid.Column="0"
         Grid.Row="1" 
         ...
>
TableOfContents.SetValue(Grid.ColumnProperty, 1);

Change margin programmatically

Siehe: [link]5122[/link]

TableOfContents.Margin = new Thickness(0, 0, 0, 0);

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.