简体   繁体   中英

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.

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.

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);
    }

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