Skip to content

How to bind to the listview item's DataContext when using C# Markup? #16578

Answered by Xiaoy312
LITTOMA asked this question in Q&A
Discussion options

You must be logged in to vote

You can bind both Command and CommandParameter as such:

new MenuFlyoutItem()
	//.DataContext(page.DataContext) // remember to remove this line
	.Command(x => x.Source(page).DataContext<MainVM>().Binding(() => vm.DeleteCommand))
	.CommandParameter(() => f)
full example
public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.DataContext = new MainVM();
        this.DataContext<MainVM>((page, vm) => page
            .Background(ThemeResource.Get<Brush>("ApplicationPageBackgroundThemeBrush"))
            .Content(new ListView()
                .ItemsSource(() => vm.Files)
                .ItemTemplate<File>(item => new Grid()
                    .Children(new T…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@francoistanguay
Comment options

Answer selected by francoistanguay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants