Setting the Owner property on a modal dialog in WPF/MVVM using a Func

I’m looking to solve the problem of setting the Owner property on modal dialogs in WPF, while using IoC and MVVM patterns I’ve seen (and written) all sorts of hacks.

Here’s a naive example of a window with a viewmodel containing an ICommand which prompts the user. It works by having the view set vm.Owner = this, and then the viewmodel using Owner later in a MessageBox when the command is called.

public partial class MyWindow : Window {     private readonly MyWindowViewModel vm;      public MyWindow(MyWindowViewModel vm)     {         InitializeComponent();         DataContext = vm;         vm.Owner = this;     } }  public class MyWindowViewModel {     private readonly RelayCommand<object> fooCommand;      public ICommand FooCommand => fooCommand;     public Window Owner { get; set; }      public MyWindowViewModel()     {         fooCommand = new RelayCommand<object>(OnFooCommand);     }      private void OnFooCommand(object obj)     {         if (MessageBox.Show(Owner, "Are you sure?", MessageBoxButton.OKCancel) == MessageBoxResult.OK)         {             // ...         }     } } 

This works, but the ViewModel is doing View-related things like opening message boxes, and knowing who owns it.

Here’s an example that abstracts the dialog into a Func, which is set in the constructor of the Window.

public partial class MyWindow : Window {     private readonly MyWindowViewModel vm;      public MyWindow(MyWindowViewModel vm)     {         InitializeComponent();         DataContext = vm;         vm.OkCancelBox = OkCancelBox;     }      private MessageBoxResult OkCancelBox(string text)     {         return MessageBox.Show(this, text, "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question);     } }  public class MyWindowViewModel {     private readonly RelayCommand<object> fooCommand;      public ICommand FooCommand => fooCommand;     public Func<string, MessageBoxResult> OkCancelBox { get; set; } = s => throw new NotImplementedException();      public MyWindowViewModel()     {         fooCommand = new RelayCommand<object>(OnFooCommand);     }      private void OnFooCommand(object obj)     {         if (OkCancelBox("Are you sure?") == MessageBoxResult.OK)         {             // ...         }     } } 

This feels better, now my ViewModel calls OkCancelBox and gets back a MessageBoxResult, without knowing anything about the View. If you “forget” to set OkCancelBox, you’ll get a NotImplementedException. In a test, I can trivially set the Func to simulate the user clicking “OK”:

vm.OkCancelBox = s => MessageBoxResult.OK; 

Still, I’m not sure I like it.

There are other solutions like passing in (or service-locating) an IMessageBoxService, but I don’t fully understand how you can specify the owner of a dialog without the ViewModel knowing who owns it.

Any thoughts on my implementation using Func<string, MessageBoxResult>?

Weird system dialog keeps showing up on OSX

For some time already I get a system dialog showing up in my computer (OSX El Capitan, 10.11.6), saying:

accountsd wants to use your confidential information stored in “Skype for Desktop MSA” in your keychain. Do you want to allow access to this item?

It also offers three buttons:

  • Always Allow
  • Deny
  • Allow

But no matter which one I click, the dialog keeps poping-up again and again, sometimes immediately, sometimes after a few seconds.

I’ve tried uninstalling Skype and removing any references to Skype and accountsd in my Keychain, without success. The annoying dialog always comes back. Any idea how to get rid of it?

Thanks

Como exportar um gráfico como imagem e abri-lo em um dialog. Utilizando Primefaces

Tenho um gráfico que fiz usando Primefaces, e um script que exporta o gráfico como imagem e coloca em um outputPanel, porém quando abro o dialog que contem esse panel, vejo que não há nada lá.

<ui:define name="head">     <link         href="$  {facesContext.externalContext.requestContextPath}/RESOURCES/css/tipo.css"         rel="stylesheet" type="text/css" />          <script>             $  (document).ready(function (){                  var windowWidth = window.innerWidth;                 var windowHeight = window.innerHeight;                  document.getElementById('typeForm:width').value = windowWidth;                 document.getElementById('typeForm:height').value = windowHeight;              });              function exportChart() {                 //export image                 $  ('#output').empty().append(PF('chart').exportAsImage());                  //show the dialog                 PF('dlg').show();             }          </script> </ui:define>  <ui:define name="cont_principal">      <div id="conteudo_principal">          <h:form class="typeDay" id="typeForm">             <p:messages class="ui-messages-mensagem" showDetail="true"                 autoUpdate="true" closable="true" />             <br></br>              <center>                 <h2 class="ui-title-titulo">                     <h:outputText value="Veículos - Tipo por Dia"></h:outputText>                 </h2>             </center>              <h:panelGrid columns="1" class="ui-panel-escolha">                  <br />                 <p:outputLabel value="Escolha" class="ui-label-escolha" />                 <br />                  <h:panelGrid columns="6">                     <h:panelGrid columns="2">                         <p:outputLabel value="Equipamento: " class="ui-label-equipamento" />                         <p:selectOneMenu id="boxEqp" class="ui-selectOneMenu-equipamento"                             value="#{typeVehicles.selectedEquipamento}" size="50">                             <f:selectItem itemLabel="Equipamento" itemValue="" />                             <f:converter converterId="equipConverter" />                             <f:selectItems value="#{typeVehicles.nomeEquip}" />                         </p:selectOneMenu>                     </h:panelGrid>                      <h:panelGrid columns="2" class="ui-panel-data">                         <p:outputLabel value="Data Ínicio: " class="ui-label-data" />                         <p:calendar class="ui-calendar-data"                             value="#{typeVehicles.selectedDtInicio}" locale="pt_BR"                             pattern="dd/MM/yyyy" mask="99/99/9999" id="dataInicio"                             showOn="button" />                          <p:outputLabel value="Data Fim: " class="ui-label-data" />                         <p:calendar class="ui-calendar-data"                             value="#{typeVehicles.selectedDtFim}" locale="pt_BR"                             pattern="dd/MM/yyyy" mask="99/99/9999" id="dataFim"                             showOn="button" />                     </h:panelGrid>                  </h:panelGrid>                  <h:panelGrid columns="2">                     <p:outputLabel value="Nº. de Eixos: " class="ui-label-eixos" />                     <p:selectCheckboxMenu id="chkbxMenu"                         class="ui-selectCheckBoxMenu-eixos"                         value="#{typeVehicles.selectedAxels}" label="Nº de Eixos"                         filter="false" filterMatchMode="startsWith"                         panelStyle="width:250px">                         <f:converter converterId="eixosConverter" />                         <f:selectItems value="#{typeVehicles.numAxles}" />                     </p:selectCheckboxMenu>                 </h:panelGrid>                  <br />             </h:panelGrid>             <h:inputHidden id="width" value="#{typeVehicles.windowWidth}" />             <h:inputHidden id="height" value="#{typeVehicles.windowHeight}" />              <p:commandButton value="Buscar"                 class="ui-button-custom ui-button-busca"                 action="#{typeVehicles.getTipoByDay}" process="@form"                 update="@form" />              <p:commandButton value="Reset"                 class="ui-button-custom ui-button-reset"                 action="#{typeVehicles.resetForm}" process="@this"                 update="boxEqp, dataInicio, dataFim, chkbxMenu, tipoAll">                 <p:resetInput                     target="boxEqp, dataInicio, dataFim, chkbxMenu, tipoAll" />             </p:commandButton>             <br />              <!-- tabela - Begin -->             <p:dataTable id="tipoAll" binding="#{table}"                 value="#{typeVehicles.totalEixos}" resizableColumns="true"                 var="type" class="ui-datatable-all" rows="32" paginator="true">                  <!--  Grupo Columns Header -->                 <p:columnGroup type="header">                     <p:row>                         <p:column rowspan="2" headerText="Data" />                         <p:column colspan="2" headerText="Veículos Leves" />                         <p:column colspan="8" headerText="Veículos Pesados" />                         <p:column rowspan="2" headerText="Total" />                     </p:row>                      <p:row>                         <p:column headerText="Motocicletas" />                         <p:column headerText="Automóveis" />                         <p:column headerText="2 Eixos" />                         <p:column headerText="3 Eixos" />                         <p:column headerText="4 Eixos" />                         <p:column headerText="5 Eixos" />                         <p:column headerText="6 Eixos" />                         <p:column headerText="7 Eixos" />                         <p:column headerText="8 Eixos" />                         <p:column headerText="9 Eixos" />                     </p:row>                 </p:columnGroup>                  <!-- Grupo Columns Header -->                  <!-- Valores -->                  <p:column id="coluna1">                     <h:outputText value="#{type.data}" />                 </p:column>                  <p:column id="coluna3">                     <h:outputText value="#{type.motocicletas}" />                 </p:column>                  <p:column id="coluna4">                     <h:outputText value="#{type.automoveis}" />                 </p:column>                  <p:column id="coluna5">                     <h:outputText value="#{type.eixos2}" />                 </p:column>                  <p:column id="coluna6">                     <h:outputText value="#{type.eixos3}" />                 </p:column>                  <p:column id="coluna7">                     <h:outputText value="#{type.eixos4}" />                 </p:column>                  <p:column id="coluna8">                     <h:outputText value="#{type.eixos5}" />                 </p:column>                  <p:column id="coluna9">                     <h:outputText value="#{type.eixos6}" />                 </p:column>                  <p:column id="coluna10">                     <h:outputText value="#{type.eixos7}" />                 </p:column>                  <p:column id="coluna11">                     <h:outputText value="#{type.eixos8}" />                 </p:column>                                       <p:column id="coluna12">                     <h:outputText value="#{type.eixos9}" />                 </p:column>                                       <p:column id="coluna13">                     <h:outputText value="#{type.total}" />                 </p:column>                          </p:dataTable>             <!-- Table - End -->             <br />             <br />             <p:commandLink ajax="false" immediate="true"                 action="#{typeVehicles.createExcelDiario}" widgetVar="startLink"  style="margin: 2%;">                 <h:graphicImage                     url="/RESOURCES/icons/microsoft/microsoft_excel_logo.png"                     styleClass="ui-image-icon-excel" />             </p:commandLink>              <c:choose>                 <c:when test="#{typeVehicles.selectedDtInicio == null}">                  </c:when>                 <c:otherwise>                     <p:commandLink onclick="PF('dlg2').show();" style="margin: 2%;">                         <h:graphicImage                             url="/RESOURCES/icons/grafico/grafico.png"                             styleClass="ui-image-icon-excel" />                     </p:commandLink>                     <p:dialog header="Gráfico - Eixos por dia" widgetVar="dlg2"  data-backdrop="static" modal="true" height="1000" width="100%">                         <h:panelGrid id="selectedEmpPanel" columns="1" style="width: 100%;">                              <p:chart type="line" model="#{typeVehicles.lineModel2}" style="height:420px; width: 98%; margin-top: 0.2%;"                                 widgetVar="chart" />                          </h:panelGrid>                          <p:commandLink id="chartDlg" onclick="exportChart()" style="margin: 2%;" oncomplete="dlg2.hide()" >                             <h:graphicImage                                 url="/RESOURCES/icons/grafico/salvar.png"                                 styleClass="ui-image-icon-excel" style=" margin-top: 5%;" />                         </p:commandLink>                        </p:dialog>                      <p:dialog widgetVar="dlg" showEffect="fade" modal="true" header="Chart as an Image" resizable="false">                         <p:outputPanel id="output" layout="block"/>                     </p:dialog>                  </c:otherwise>             </c:choose>          </h:form>      </div> </ui:define> 

How to display a form in modal dialog on page load?

This is on Drupal 8.6, PHP 7.2, Theme is based on Bootstrap.

The scenario is, I want to display a dialog box with a subscription form in the home page. The dialog box will be loaded automatically when page load, not by click any link. I see there are lot of examples there in the net, but all related to by clicking a link, modal will display. But I want to load it without any click.

I partially successful by using BootstrapDialog, but ajax is not working on form submit button. What I did, I attach a js file in the front page, with the code below. It shows the Modal Dialog box, and I tuned a page–newsletter–subscribe.html.twig, its working But submit button not working not ajax is working.

    BootstrapDialog.show({     title: 'Subscribe To Newsletter',     message: jQuery('<div></div>').load('/newsletter/subscribe'),     closable: false,     draggable: true,     closeByBackdrop: false,     closeByKeyboard: false,     buttons: [{         label: 'Close',         action: function(dialogRef){             dialogRef.close();         }     }] }); 

I saw there is an example in code node.preview.js file like this:

          var $  previewDialog = $  ('<div>' + Drupal.theme('nodePreviewModal') + '</div>').appendTo('body');       Drupal.dialog($  previewDialog, {         title: Drupal.t('Leave preview?'),         buttons: [{           text: Drupal.t('Cancel'),           click: function click() {             $  (this).dialog('close');           }         }, {           text: Drupal.t('Leave preview'),           click: function click() {             window.top.location.href = event.target.href;           }         }]       }).showModal(); 

But I never able to make it working in my custom module.

If some one can help on this, will be really great!

Undo typing dialog appears often recently, in Safari

Recently it started happening on my iPad that a small dialog asking “Undo typing?” appears on a web page in Safari.

The two options offered are Cancel and Undo. No matter which I tap, both make the dialog disappear and nothing else seems to happen.

Why does this dialog appear? What is its purpose?

I run the latest iOS 12.1.1

Ubuntu 18.04 – How do I turn off the “App is not responding” dialog box?

When I try to play Europa Universalis 4 on my machine, the keyboard will be unresponsive until I tab out of the game and discover that the dialog box has taken over my keyboard but is rendered under the game. I can hit Wait, but then when I tab back into the game the frame rate drops to something like 10fps and the performance is very poor.

My question is this: How do I disable this dialog? I don’t want to ever see it again.

enter image description here

“\vcredist_x64.exe” dialog when installing .exe with Wine

I have followed these instructions for installing Wine.

Now I’m trying to install a Windows program with Wine. As soon as I run the install command from my ~/Downloads directory

wine HoldemManager2Setup_8544.exe 

this dialog pops up.

enter image description here

Any idea how to successfully install the .exe?

I’m trying to install the free trial version of Holdem Manager 2.

Office UI Dialog not showing correctly on SPFX Web part

On the SharePoint Workspace the UI dialog works fine. The dialog comes out when you click on Forward Case.

enter image description here

When I have gulp packaged the solution and adding the app (locally on gulp) then I get this when I click on Forward Case.

enter image description here

So the dialog needs to pop out much further and onto the main screen and not just within the web part.

Is this anything that can be done ?