简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM