プログラミングに新しい、7日間の検索の後に解決策が見つかりませんでした。 私の "MainPage"が開き、クリックすると、コアDispatcherを持つ新しいスレッドウィンドウで開く "SecondaryPage"が開きます。私の "MainPage"には "TextBlock1"を更新するボタンClickイベントがあります。私が達成できないことは、この値を "SecondPage" "TextBlock2"に渡すことです。UWP C#別のスレッドに変数を渡す
下記のMainPage.xaml。
<StackPanel>
<Button Click="Button_Click_NewWindow" Content="Start a new window" FontSize="30"/>
<TextBlock Name="Textblock1" Text="Empty" FontSize="30"/>
<Button Click="Button_Click_Add" Content="+1" FontSize="30"/>
</StackPanel>
SecondPage.xaml
の背後にあるコード<StackPanel>
<TextBlock Name="Textblock2" Text="Empty" FontSize="30"/>
</StackPanel>
MainPage.xaml.cs私はDispatcherは私のメインページの表示に取り組んでいるが、私は指示するコードを見つけ出すカント参照
namespace MulitViewV1
{
public sealed partial class MainPage : Page
{
public int T1G = 0;
public MainPage()
{
this.InitializeComponent();
}
private async void Button_Click_NewWindow(object sender, RoutedEventArgs e)
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
{
Frame frame = new Frame();
frame.Navigate(typeof(SecondPage), null);
Window.Current.Content = frame;
// You have to activate the window in order to show it later.
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
private async void Button_Click_Add(object sender, RoutedEventArgs e)
{
T1G = T1G + 1;
Textblock1.Text = T1G.ToString();
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() =>
{
//UI code here
// NOT WORKING error "TextBlock2" does not exist in the current context
Textblock2.Text = T1G.ToString();
});
}
}
}
SecondPage "newViewID"に送信します。あなたは
string TextBoxText = Textblock1.Text;
frame.Navigate(typeof(SecondPage), TextBoxText);
そして、あなたのSecondPage
で以下のようにTextBlock
からテキストを渡し、
frame.Navigate(typeof(SecondPage), null);
代わりにヌルを呼び出しているあなたのButton_Click_NewWindow
で
私と一緒にお越しいただきありがとうございます。私のButton_Click_NewWindowでは、2番目のウィンドウが開きます。コード::frame.Navigate(typeof(SecondPage)、T1G);変数を渡します。次にButton_Click_Add、新しい更新変数を2番目に開いたウィンドウに渡すにはどうすればいいですか? – Static
@Static私の更新された答えを確認 – AVK
私は十分にありがとう、私はこれを把握しようと1週間立ち往生してきた。 – Static