Hello,
Welcome to Microsoft Q&A!
If you want to pass current page to the ViewModel by command parameter. you could bind current page like this.
- Give your page a name in xaml
<Page x:Class="ListViewDrag.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Core="using:Microsoft.Xaml.Interactions.Core" xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:ListViewDrag" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="MyPage"
- Make Button Command method in the ViewModel
}public class MainPageViewModel { public MainPageViewModel() { } public ICommand ButonAddCommand { get { return new CommadEventHandler<Page>((s) => { // s is current page instance }); } }
- Bind current page with command parameter by using ElementName markup
<Button VerticalAlignment="Bottom" Command="{Binding ButonAddCommand}" CommandParameter="{Binding ElementName=MyPage}" Content="Add" />
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.