Ibrahiem Rafiq
Ibrahiem Rafiq

Reputation: 73

PopUp Window WPF Form Custom Control Content

I have a form done in WPF which has a custom control already on it called RateView. This custom control has 4 textboxes (which are all working as they should be). It also contains a button.

I have a second custom control called Extended Margin Info, which also has a XAML Form which will just show output data only.

How can I by clicking the button on the custom control called Rateview bring up the XAML canvas onto my Main window of the extendedmargin info XAML, in the same position everytime? Rateview control exists 5 times on the main window therfore there will be 5 buttons that when clicked, will need to output the popup of ExtendedMargin Info to the main screen in the same position each time with the content of extendedmargin info.

Upvotes: 0

Views: 2716

Answers (2)

opewix
opewix

Reputation: 5083

I guess you want show one popup and change it's content placing in it different controls.

At 1st create your custom control:

balloon = new LogEntryInfoBalloon();
        balloon.SetMainWindow(this);
        balloon.DataContext = vm.NotificationViewModel;

Then create Popup control (System.Windows.Controls.Primitives):

localPop = new Popup();
        localPop.AllowsTransparency = true;
        localPop.Placement = PlacementMode.AbsolutePoint;
        localPop.StaysOpen = true;
        localPop.PlacementTarget = this;
        localPop.Child = balloon;

Placement target points to MainWindow.

Define timer that will close(hide) balloon:

localPopTimer = new Timer(new TimerCallback(CloseLocalPopup));

Close func:

private void CloseLocalPopup(object args)
    {
        var act = new Action(() =>
        {
            localPop.IsOpen = false;
        });
        Dispatcher.BeginInvoke(act, null);
    }

Show balloon code looks like this:

private void ShowNotifyBaloon(NotifyBaloonViewModel vm)
    {
        var act = new Action(() =>
        {
            localPop.IsOpen = true;
            localPopTimer.Change(4000, Timeout.Infinite);
        });
        Dispatcher.BeginInvoke(act, null);
    }

Upvotes: 0

franssu
franssu

Reputation: 2430

Your button, when clicked, should call a Command which updates a Property of some ViewModel that exposes the ViewModel of the current ExtendedMarginInfo you want to display. Then you can bind this property to the Content Property of a ContentControl in the target view. You can select the View you want the Control to display by using the ContentControl.ContentTemplateSelector property.

Upvotes: 2

Related Questions