JonasN89
JonasN89

Reputation: 1476

Popup upon click on button

I'm trying to implement an popup when I click an button. I wish to bind the button to an RelayCommand in my ViewModel, and from this RelayCommand I wish to add my PopUp. The Popup is made in an View(xaml). I'm using the MVVM model for a windows phone. The View(xaml) for my Popup is:

<Popup>
    <Border Background="Blue">
        <TextBlock Text="Hej med dig" FontSize="25"/>
    </Border>
</Popup>

The View(xaml) for my Button is

 <Button BorderBrush="Transparent" BorderThickness="0" Command="{Binding ClickCommand}" CommandParameter="{Binding}">
        <Button.Template>
            <ControlTemplate>
                <Path x:Name="CountryUser" Stretch="Fill" StrokeThickness="{StaticResource StrokeUserControl}" StrokeLineJoin="Round" Fill="{StaticResource CountryBackground}" Stroke="{Binding CountryView.CountryColor}" Data="{Binding CountryView.MapData}"/>
            </ControlTemplate>
        </Button.Template>
    </Button>

The ViewModel(C#) which is binded to my Button, and from where I wish to add the RelayCommand which activates the Popup upon click on my button is:

public ICommand ClickCommand { get; set; }

   public CountryViewModel()
   {
       ClickCommand = new RelayCommand(Click);
   }

   public void Click()
   {
       PopUpUC TextPopUp = new PopUpUC();  

   }

My problem is when I click the button my Popup doesn't show, any help would be nice.

Upvotes: 1

Views: 1376

Answers (1)

JTIM
JTIM

Reputation: 2771

In the xaml you should bind something to the IsOpen property so:

<Popup IsOpen="{Binding PopUpUCIsOpen}">
<Border Background="Blue">
    <TextBlock Text="Hej med dig" FontSize="25"/>
</Border>

And then change the variable in the click.

Upvotes: 2

Related Questions