0

I want to have two kind of status**(SmallPay,Credit)**, but that is decided by previous UserControl(ItemDetail.xaml)

ItemDetail.xaml

<Border Background="#fb5106" CornerRadius="8" Cursor="Hand">
    <Border.InputBindings>
       <MouseBinding MouseAction="LeftClick" Command="{Binding Path=ClickPhoneNumberCommand}" CommandParameter="A"/>
    </Border.InputBindings>
    <TextBlock Text="SmallPay" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" FontSize="32" />
</Border>

<Border Grid.Column="2" Background="#e7001f" CornerRadius="8" Cursor="Hand">
    <Border.InputBindings>
        <MouseBinding MouseAction="LeftClick" Command="{Binding Path=ClickPhoneNumberCommand}" CommandParameter="B"/>
        </Border.InputBindings>
    <TextBlock Text="Credit" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" FontSize="32" />
</Border>

ViewModel.cs

public DelegateCommand ClickItemCommand
{
    get
    {
        return new DelegateCommand(delegate ()
        {
            SelectedPopupType = PopupTypes.ItemDetail;
                IsShowPopup = true;
        });
    }
}

public DelegateCommand ClickPhoneNumberCommand
{
    get
    {
        return new DelegateCommand(delegate ()
        {
            SelectedPopupType = PopupTypes.PhoneNumber;
            IsShowPopup = true;
        });
    }
}

Then I want to get the commandParameter in the UserControl opened by 'ClickPhoneNumberCommand'. But, I dont know how? Is there way without no ViewModel?

2
  • Are you using a ViewModel not? It's hard to tell from your question. Commented Feb 4, 2019 at 6:01
  • I'm using ViewModel.cs as above. Commented Feb 4, 2019 at 6:10

1 Answer 1

1

You code returns a new delegate for each return of the ClickItemCommand property. I don't think this will work with WPF because of how object-references work, I think you should use a field to store a single reference to an immutable Command, like so:

private readonly DelegateCommand clickItemCommand;

public MyViewModel()
{
    this.clickItemCommand = new DelegateCommand( this.OnItemClick );
}

private void OnItemClick(Object parameter)
{
    this.SelectedPopupType = PopupTypes.ItemDetail;
    this.IsShowPopup = true;
}

public DelegateCommand ClickItemCommand
{
    get { retrn this.clickItemCommand; }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.