A Microsoft framework for building cross-platform mobile apps using .NET and C# with native performance and user interfaces.
Try this:
CommandParameter="{Binding Source={RelativeSource Self}, Path=BindingContext}"
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Following strange behaviour when using swipe view with command and command parameter. The command is called, but the parameter is null. However, when I save the xaml view and the hot-reload is triggered (even without changing any code) - the parameter is assigned properly.
Code snippets:
Xaml:
<CollectionView Margin="0,0,0,0" x:Name="ItemsListView"
ItemsSource="{Binding Items}"
SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate>
<SwipeView >
<SwipeView.RightItems>
<SwipeItems Mode="Reveal">
<SwipeItem Command="{Binding BindingContext.DeletePositionCommand, Source={x:Reference BrowsePosPage}}" CommandParameter="{Binding .}" Text="Delete" BackgroundColor="Red" />
</SwipeItems>
</SwipeView.RightItems>
<ScrollView Margin="0">
<StackLayout>
<Grid Margin ="0,0,0,0" Padding="0,0,0,0" RowSpacing="2" ColumnSpacing="2" x:DataType="model:GetPositions">
...
ViewModel
public Command DeletePositionCommand { get; }
public GetPositionsMasterViewModel() {
DeletePositionCommand = new Command<GetPositions>(async (position) => await ExecuteDeletePositionsCommand(position));
async Task ExecuteDeletePositionsCommand(GetPositions position)
{
// position is null. Only when xaml is hot reloaded the position gets set.
if(position != null)
{
....
}
}
A Microsoft framework for building cross-platform mobile apps using .NET and C# with native performance and user interfaces.
Try this:
CommandParameter="{Binding Source={RelativeSource Self}, Path=BindingContext}"
Just deleted bin/obj, cleaned and rebuild. The error remains. The parameter is null and remains null even if I change pages within the app etc. But when I save this particular xaml file in visual studio (I have tried to save other xaml files but this does not have any effect) and the hot reload is complete - the parameter is correctly available. Obviously this all happens in a debug session. I will compile as a release version in the coming days and revert with the result.