Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

How do you call the mainpage of a static class?

05.07.2018 (👁5541)

How do you call the mainpage of a static class?

05.07.2018 (👁7)


 

problem

I want to access the main page in UWP from a common method in UWP.

How to reach or refer to the MainPage?

 

In the main page MainPage inserts a static reference to the current element

public static MainPage Current_Mainpage;

And activates this during initialization

Current_Mainpage = this;

 

C # Code of the MainPage page in C #

 

namespace app_Robot

{

    public sealed partial class MainPage : Page

    {

 

public static MainPage Current_Mainpage;

public string Text_Log

{

    get

    { return Textbox_Log.Text; }

    set

    { Textbox_Log.Text = value; }

}

 

public MainPage()

{

    this.InitializeComponent();

    Current_Mainpage = this;

 

    optStop.IsChecked = false;

    init_DB();

}

 

 

https://readdy.net/User_Files/Notes/Images/Image_556_0_blog.jpg" width="1022" height="624">

 

 

On the other pages of the application or even static classes, you can then refer to a simple reference to the current MainPage

        MainPage mainPage = MainPage.Current_Mainpage;

        string sText = mainPage.Text_Log;

 

 

 

Example: System message should be output on the current MainPage

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

//< using >

using Windows.UI.Popups;    //*MessageDialog

using app_Robot; //*MainPage

//</ using >

 

public static class clsSys

{

    public async static void show_Message(string sMessage)

    {

        MessageDialog dialog = new MessageDialog(sMessage, "Information");

        await dialog.ShowAsync();

    }

 

    public static void fx_Log(string sLog)

    {

        //------------< fx_Log() >------------

        //* log Text to Textbox

 

        MainPage mainPage = MainPage.Current_Mainpage;

        string sText = mainPage.Text_Log;

        sText = DateTime.Now + " " + sLog + Environment.NewLine + sText;

        if (sText.Length > 50000) { sText = sText.Substring(50000); }

        mainPage.Text_Log = sText;

        mainPage.UpdateLayout();

 

        //< refresh > 

 

        //</ refresh > 

        //------------</ fx_Log() >------------

    }

}

 

 

 

https://readdy.net/User_Files/Notes/Images/Image_556_1_blog.jpg" width="1022" height="576">

 

 

MainPage output control

I want to output the text to the XAML TextBlock element

<TextBox x:Name="Textbox_Log"  Height="385" Margin="20,244,-317,0" TextWrapping="Wrap" Text=".." VerticalAlignment="Top"/>

 

https://readdy.net/User_Files/Notes/Images/Image_556_2_blog.jpg" width="1022" height="421">