1. Navigation
在 Page 中:
this.Frame.Navigate(typeof(MainPage));
其他:
Frame frame = Window.Current.Content as Frame;
frame.Navigate(typeof(MainPage));
在页面之间传递信息:
page1.xaml.cs
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(page2), tb1.Text);
}
page2.xaml.cs
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { string name = e.NavigationParameter as string; if (!string.IsNullOrWhiteSpace(name)) { tb1.Text = "Hello, " + name; } else { tb1.Text = "Name is required. Go back and enter a name."; } }
2.用c# 设置 button的 color
button.Background = new SolidColorBrush(Colors.Yellow);
namespace of color : Windows.UI
自定义 SolodColorBrush:
SolidColorBrush greenBrush = new SolidColorBrush(Colors.Green);
SolidColorBrush myBrush = new SolidColorBrush(Color.FromArgb(255, 20, 20, 90));
3. SearchBox
<SearchBox x:Name="mySearchBox" FocusOnKeyboardInput="True" QuerySubmitted="mySearchBox_QuerySubmitted" Height="35" />
private void mySearchBox_QuerySubmitted(SearchBox sender, SearchBoxQuerySubmittedEventArgs args) { this.Frame.Navigate(typeof(SearchResultsPage1), args.QueryText); }
4. Handle Back Button
如果用手机自带的返回键,需要在app.xaml.cs 中处理 BackPressedEvent
private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
Frame frame = Window.Current.Content as Frame;
if (frame == null)
{
return;
}
if (frame.CanGoBack)
{
frame.GoBack();
e.Handled = true;
}
}
如果用app中的返回键:
则自定义button的点击事件:
private void Back_Click(object sender, RoutedEventArgs e)
{
Frame frame = Window.Current.Content as Frame;
if (frame == null)
{
return;
}
if (frame.CanGoBack)
{
frame.GoBack();
}
}
5. WebView
xaml:
<WebView Name="webView1" Width="1000" Height="800"/>
c#:
protected override void OnNavigatedTo(NavigationEventArgs e) { Uri targetUri = new Uri(@"http://www.bing.com/"); webView.Navigate(targetUri); }
6. Handle Orientation
http://blog.jerrynixon.com/2013/12/the-two-ways-to-handle-orientation-in.html
7. Implementing search in windows 8.1 app
http://irisclasson.com/2013/12/05/implementing-search-in-windows-store-apps-8-1-screenshot-guide/
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868180.aspx
8. Zoom in/out content in webView
https://code.msdn.microsoft.com/How-to-zoom-inout-the-5a42229b
https://code.msdn.microsoft.com/windowsapps/XAML-ScrollViewer-pan-and-949d29e9