black1stallion2
black1stallion2

Reputation: 139

WP Binding Button Command in a DataTemplate

Im tring to create a button in a datatemplate usually its

  <Button x:Name="SomeButton" Click="SomeButton_Click"></Button> //XAML
  <private void SomeButton_Click(object sender, RoutedEventArgs e)  //CS
 {
     // Code
 }

But i can't seem to firgure out how to this with a simple button in a datatemplate all a want to do is open a popup from MainPage.xaml

Upvotes: 1

Views: 295

Answers (1)

Chubosaurus Software
Chubosaurus Software

Reputation: 8161

If it is in a <DataTemplate> best bind your action to Command and CommandParameter inside your ViewModel

<Button Command="{Binding myCommand}"
        CommandParameter="{Binding Extra}"
        x:Name="mybutton" Width="200" Height="50"/>

Full example using a ListView / MVVM

MVVM ListView + Command Button

Upvotes: 1

Related Questions