search合约
using Windows.ApplicationModel.DataTransfer;
SearchPane.GetForCurrentView().SuggestionsRequested += OnSuggestionsRequested;
//当点击右边的search 按钮是触发
void OnSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args)
{ string query = args.QueryText.ToLower();
string[] terms = { "salt", "pepper", "water", "egg", "vinegar", "flour", "rice", "sugar", "oil" };
foreach(var term in terms)
{
if (term.StartsWith(query))
args.Request.SearchSuggestionCollection.AppendQuerySuggestion(term);
}
}
分享合约using Windows.ApplicationModel.DataTransfer;
DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;
void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args) { var request = args.Request; var item = (RecipeDataItem)this.flipView.SelectedItem; request.Data.Properties.Title = item.Title; request.Data.Properties.Description = "Recipe ingredients and directions"; // Share recipe text var recipe = "\r\nINGREDIENTS\r\n"; recipe += String.Join("\r\n", item.Ingredients); recipe += ("\r\n\r\nDIRECTIONS\r\n" + item.Directions); request.Data.SetText(recipe);
// Share recipe image
var reference = RandomAccessStreamReference.CreateFromUri(new Uri(item.ImagePath.AbsoluteUri));
request.Data.Properties.Thumbnail = reference;
request.Data.SetBitmap(reference); }
DataTransferManager.GetForCurrentView().DataRequested -= OnDataRequested;
关于Settings and Preferences
using Windows.UI.ApplicationSettings; using Callisto.Controls; using Windows.UI;
SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested; void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args) { // Add an About command var about = new SettingsCommand("about", "About", (handler) => { var settings = new SettingsFlyout(); settings.Content = new AboutUserControl(); settings.HeaderBrush = new SolidColorBrush(_background); settings.Background = new SolidColorBrush(_background); settings.HeaderText = "About"; settings.IsOpen = true; }); args.Request.ApplicationCommands.Add(about); } //AboutUserControl 是自定义usercontrol
关于漫游数据
a. Open PreferencesUserControl.xaml and add a Toggled attribute to the ToggleSwitch control:
<ToggleSwitch x:Name="Remember" Header="Remember where I was" Toggled="OnToggled" />
b. Open PreferencesUserControl.xaml.cs and add the following using statement: using Windows.Storage;
c. Then add the following method:
private void OnToggled(object sender, RoutedEventArgs e)
{ ApplicationData.Current.RoamingSettings.Values["Remember"] = Remember.IsOn; }
d. Add the following statements to the PreferencesUserControl constructor, after the call to InitializeComponent, to initialize the toggle switch each time the preferences page is displayed:
// Initialize the ToggleSwitch from roaming settings
if (ApplicationData.Current.RoamingSettings.Values.ContainsKey("Remember"))
Remember.IsOn = (bool)ApplicationData.Current.RoamingSettings.Values["Remember"];