C
C#2w ago
Zee

Binding a class to a button

so I am trying to make it so when the user clicks the view details button a message box pop ups showing extra details but I am getting this error System.ArgumentException: 'Parameter "parameter" (object) cannot be of type MS.Internal.NamedObject, as the command type requires an argument of type SharedModels.BookedFlight. Arg_ParamName_Name
4 Replies
Zee
ZeeOP2w ago
<Page x:Class="FakeFlightBookingApp.View.ProfilePageView"
...
Loaded="Page_Loaded"
Title="ProfilePage">
</StackPanel>

<!-- Flight Table on the Right -->
<DataGrid Grid.Row="1" Grid.Column="1" ItemsSource="{Binding BookedFlights}" AutoGenerateColumns="False" Margin="20">
<DataGrid.Columns>
<DataGridTextColumn Header="Destination" Binding="{Binding Destination}"/>
<DataGridTextColumn Header="Price" Binding="{Binding Price}"/>
<DataGridTextColumn Header="Tickets" Binding="{Binding NumberOfTickets}"/>
<DataGridTemplateColumn Header="Actions">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="View Details"
Command="{Binding DataContext.ViewFlightDetailsCommand, RelativeSource={RelativeSource AncestorType=Page}}"
CommandParameter="{Binding .}">
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>

<!-- Buttons at the Bottom Center -->
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="10">
<Button Content="Delete Account" Background="Red" Foreground="White" Width="120" Margin="5" Command="{Binding DeleteAccountCommand}"/>
<Button Content="Go Back" Width="120" Margin="5" Command="{Binding GoBackCommand}"/>
</StackPanel>
</Grid>
</Page>
<Page x:Class="FakeFlightBookingApp.View.ProfilePageView"
...
Loaded="Page_Loaded"
Title="ProfilePage">
</StackPanel>

<!-- Flight Table on the Right -->
<DataGrid Grid.Row="1" Grid.Column="1" ItemsSource="{Binding BookedFlights}" AutoGenerateColumns="False" Margin="20">
<DataGrid.Columns>
<DataGridTextColumn Header="Destination" Binding="{Binding Destination}"/>
<DataGridTextColumn Header="Price" Binding="{Binding Price}"/>
<DataGridTextColumn Header="Tickets" Binding="{Binding NumberOfTickets}"/>
<DataGridTemplateColumn Header="Actions">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="View Details"
Command="{Binding DataContext.ViewFlightDetailsCommand, RelativeSource={RelativeSource AncestorType=Page}}"
CommandParameter="{Binding .}">
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>

<!-- Buttons at the Bottom Center -->
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="10">
<Button Content="Delete Account" Background="Red" Foreground="White" Width="120" Margin="5" Command="{Binding DeleteAccountCommand}"/>
<Button Content="Go Back" Width="120" Margin="5" Command="{Binding GoBackCommand}"/>
</StackPanel>
</Grid>
</Page>
namespace FakeFlightBookingApp.View
{
/// <summary>
/// Interaction logic for ProfilePageView.xaml
/// </summary>
public partial class ProfilePageView : Page
{
private readonly HttpClient _httpClient;

public ProfilePageView()
{
InitializeComponent();

}

private void Page_Loaded(object sender, RoutedEventArgs e)
{
var viewModel = (ProfilePageViewModel)App.ServiceProvider.GetService(typeof(ProfilePageViewModel));

if (viewModel != null)
{
DataContext = viewModel;
viewModel.LoadBookedFlightsCommand.Execute(null);
}
else
{
MessageBox.Show("ViewModel could not be resolved.");
}
}

}
}
namespace FakeFlightBookingApp.View
{
/// <summary>
/// Interaction logic for ProfilePageView.xaml
/// </summary>
public partial class ProfilePageView : Page
{
private readonly HttpClient _httpClient;

public ProfilePageView()
{
InitializeComponent();

}

private void Page_Loaded(object sender, RoutedEventArgs e)
{
var viewModel = (ProfilePageViewModel)App.ServiceProvider.GetService(typeof(ProfilePageViewModel));

if (viewModel != null)
{
DataContext = viewModel;
viewModel.LoadBookedFlightsCommand.Execute(null);
}
else
{
MessageBox.Show("ViewModel could not be resolved.");
}
}

}
}
Zee
ZeeOP2w ago
Zee
ZeeOP2w ago
full error is this
Zee
ZeeOP2w ago
I know its something to do with my bidning and I am not sure what I tried using Binding BookedFlights instead but that did not work

Did you find this page helpful?