私はアプリの特定のコンテンツと目的をあまり話さずにこれを説明するために最善を尽くします。私はちょうどあなたがそれらを占有するために選択することができる項目のための3つの空の "スロット"がメインページにあると言うでしょう。 1つをクリックすると、そのスロットの特定の項目を選択する別のページに移動します。ここでは、より良い説明するためのコードは次のとおりです。ここでWP7 Appのページ間で文字列の値を設定する
<TextBlock Text="{Binding FirstSelectionName}" />
<TextBlock Text="{Binding FirstSelectionType}" />
<HyperlinkButton Content="Choose First Option"
Name="firstHyperLink"
NavigateUri="/Pages/FirstChoices.xaml"
/>
<TextBlock Text="{Binding SecondSelectionName}" />
<TextBlock Text="{Binding SecondSelectionType}" />
<HyperlinkButton Content="Choose Second Option"
Name="secondHyperLink"
NavigateUri="/Pages/SecondChoices.xaml"
/>
<TextBlock Text="{Binding ThirdSelectionName}" />
<TextBlock Text="{Binding ThirdSelectionType}" />
<HyperlinkButton Content="Choose Third Option"
Name="thirdHyperLink"
NavigateUri="/Pages/ThirdChoices.xaml"
/>
は、コードは次のXAMLページの背後にある:
XMLファイルには、ループスルーし、クラスの新しいインスタンスに保存された選択ページでpublic class FirstSelection
{
public string FirstSelectionName { get; set; }
public string FirstSelectionType { get; set; }
}
public class SecondSelection
{
public string SecondSelectionName { get; set; }
public string SecondSelectionType { get; set; }
}
public class ThirdSelection
{
public string ThirdSelectionName { get; set; }
public string ThirdSelectionType { get; set; }
}
。ユーザーがボタン押下でそのリストから特定のオプションを選択すると、メインページの対応するスロットをその選択と同じに設定したいと思います。ここでは最初のスロットの選択ページの一例です:
<ListBox Name="firstOptionsList">
<ListBox.ItemTemplate>
<DataTemplate>
<Button BorderThickness="3"
Click="setSelectedToFirst">
<StackPanel Orientation="Vertical">
<TextBlock Name="nameTextBlock"
Text="{Binding Name}"
/>
<TextBlock Name="typeTextBlock"
Text="{Binding Type}"
/>
</StackPanel>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
そして最後にセレクチンのページの背後にあるコード:
public FirstOptionsPage()
{
InitializeComponent();
Dispatcher.BeginInvoke((Action)(() => firstList.ItemsSource = firstdata));
WebClient firstWebClient = new WebClient();
firstWebClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(first_DownloadStringCompleted);
firstWebClient.DownloadStringAsync(new Uri("http://www.website.com/firstoptions.xml"));
}
void first_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
XElement xmlitem = XElement.Parse(e.Result);
var firstdata = new List<FirstOptionsClass>();
foreach (XElement item in xmlitem.Elements("entry"))
{
var name = item.Element("name");
var namevalue = (name == null) ? null : name.Value;
var type = item.Element("type");
var typevalue = (type == null) ? null : type.Value;
firstdata.Add
(new FirstOptionsClass
{
Name = namevalue,
Type = typevalue,
}
);
}
firstList.ItemsSource = firstdata;
}
public class FirstOptionsClass
{
public string Name { get; set; }
public string Type { get; set; }
}
public System.Collections.IEnumerable firstdata { get; set; }
private void setSelectedToFirst(object sender, RoutedEventArgs e)
{
//THIS IS THE PART WHERE I'M NOT SURE HOW TO SET FirstOptionsClass Name = FirstSelectionName on the MainPage.xaml
}
私の主な問題のためのクリックイベントでのコメント行を参照してください。どのようにこれらの値をこれらのページにわたって互いに等しく設定するのですか?私はそれがここで混乱のように見えるかもしれないことを知っているので、私は助けに感謝します。
特定の項目でユーザーがクリックすると、setSelectedToFirstが発生します。 – Dan
あなたは何をクリックするかを保存するためのいくつかの選択肢があります。それらの1つはIsolatedStorageSettingsを使用しています。 colletion +を保存する必要があります。 http://dotnet.dzone.com/articles/using-application-settingsの例がたくさんあります。 App.xaml.csには、ユーザーの選択肢を保存するシングルトンもあります。 var myApp =(アプリケーション)Application.Current; myApp.Singleton; –