UWP Inherit parent page from child page

득권 천 61 Reputation points
2022-04-12T00:01:13.393+00:00

Hello I am a student who has just started studying UWP

192101-image.png

A structure is a structure that has frames within a page and moves through navigation.

I want to create a button that is retrieved from a page belonging to a frame in the parent page and then override it so that the logic works when pressed in the lower page

ShellViewModel

public ShellViewModel()  
        {  
            Action_Search_Command = new DelegateCommand(Action_Search);  
        }  
  
        protected virtual void Action_Search()  
        {  
             
        }  

OM_01ViewModel

protected override void Action_Search()  
        {  
  
            base.Action_Search();  
  
            Set_Grid();  
        }  

I created a lookup button and command in the shell page and overridden it in the page corresponding to the frame to call the function to bind the datagrid, but it didn't work.

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,851 Reputation points
    2022-04-12T07:51:07.193+00:00

    Hello,
    Welcome to Microsoft Q&A!

    Your problem is more related with C# polymorphism. If you want to ShellViewModel could call the sub-class override method, you should use father reference point to sub-class instance.

    ShellPage

    public MainPage()  
    {  
        this.InitializeComponent();  
        Instance = this;  
        this.DataContext = new OM_01ViewModel() as ShellViewModel;  
        
    }  
    public static MainPage Instance;  
    

    SubPage

    public CorePage()  
    {  
        this.InitializeComponent();  
      
        this.DataContext = MainPage.Instance.DataContext as OM_01ViewModel;  
    }  
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful