wpfDialogBox

(Hide table-of-contents)

Overview

wpfDialogBox is a Dyalog namespace containing methods to show dialog boxes in a WPF application. Check the comments of each method for more information.

Typical Usage

To Query for a Folder

      path←DialogFolder

DialogFolder.png

To Query for a File Name to Open

      path←DialogOpenFile

DialogOpenFile.png

To Query for a File Name to Save

      path←DialogSaveFile

DialogSaveFile.png

To Show an Error Message

      response←ShowError 'This is an Error Message' 'My Program Name - Error' 'YesNoCancel'

ShowError.png

To Show an Information Message

      response←ShowInfo 'This is an Information Message' 'My Program Name - Info' 'YesNoCancel'

ShowInfo.png

To Show a Warning Message

      response←ShowWarning 'This is a Warning Message' 'My Program Name - Warning' 'YesNoCancel'

ShowWarning.png

Custom WPF Dialog Box

For a custom WPF dialog box you can consult the function CustomMessageBox ( Show the code)

 CustomMessageBox;bitmap;icon;⎕USING
⍝ Prepare a Custom WPF Message Box

 ⎕USING,←⊂'System.Windows.Markup,WPF/PresentationFramework.dll'
⍝ Edit the wMsgBoxCustom_xaml file to suit your needs.
 MsgBox_obj←XamlReader.Parse(⊂wMsgBoxCustom_xaml)

⍝ Set the Custom Error Text
 (MsgBox_obj.FindName⊂'tbError').Text←'custom error text'

⍝ Set the Error Icon of the message box
 ⎕USING←'System.Drawing,System.Drawing.dll' 'System.Windows,WPF/PresentationCore.dll' 'System.Windows,WPF/WindowsBase.dll'

⍝ Possible choices are: Application Asterisk Error Exclamation Hand Information Question Shield Warning WinLogo
 icon←SystemIcons.Error

⍝ Change the Icon to a WPF bitmap
 bitmap←Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle)(Int32Rect.Empty)(Media.Imaging.BitmapSizeOptions.FromEmptyOptions)
 (MsgBox_obj.FindName⊂'imgIcon').Source←bitmap

⍝ Show the Custom Message Box
 MsgBox_obj.ShowDialog


      wMsgBoxCustom_xaml
<Window
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   MaxWidth="800"
   ResizeMode="NoResize"
   SizeToContent="WidthAndHeight"
   Title="Execution Error"
   UseLayoutRounding="True"
   WindowStartupLocation="CenterOwner">
   <StackPanel>
      <Grid Margin="0,-1,0,0" Background="White">
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
         </Grid.ColumnDefinitions>
         <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
         </Grid.RowDefinitions>
         <Image
            x:Name="imgIcon"
            Grid.ColumnSpan="1"
            Grid.Row="0"
            HorizontalAlignment="Left"
            Margin="10,10,16,10"
            VerticalAlignment="Top"/>
         <ScrollViewer
            Name="Scroller"
            MaxHeight="600"
            MinWidth="200"
            Grid.Column="1"
            Grid.ColumnSpan="1"
            Grid.RowSpan="1"
            Margin="8,18,12,8"
            HorizontalScrollBarVisibility="Auto"
            VerticalScrollBarVisibility="Auto">
            <TextBlock
               x:Name="tbError"
               Width="{Binding ElementName=Scroller}"
               FontFamily="APL385 Unicode"
               FontSize="14"
               Text="TextBlock"/>
         </ScrollViewer>
         <Border
            Grid.ColumnSpan="2"
            Grid.Row="1"
            Margin="0,10,0,0"
            VerticalAlignment="Top"
            Background="#FFECECEC"
            BorderBrush="#FFC9C9C9"
            BorderThickness="0,1,0,0"
            Padding="8,0,0,0">
            <StackPanel>
               <Button
                  x:Name="bnOK"
                  Height="24"
                  Width="86"
                  HorizontalAlignment="Right"
                  Margin="0,8,12,8"
                  VerticalAlignment="Center"
                  Content="OK"
                  IsCancel="True"
                  IsDefault="True"/>
            </StackPanel>
         </Border>
      </Grid>
   </StackPanel>
</Window>

How to install wpfDialogBox in your workspace

  1. Download wpfDialogBox.v1.0.txt

  2. Do a Select all (Ctrl+A) and a copy (Ctrl+C).
  3. In your workspace execute )ed ⍟ wpfDialogBox

  4. Paste (Ctrl+V) the text into the Dyalog editor
  5. Press Escape and ')save' your workspace

Optionally to de-script the namespace you can do: #.wpfDialogBox←{('n' ⎕NS ⍵)⊢n←⎕NS ''}#.wpfDialogBox

Version Information

Original author:

Pierre Gilbert

Responsible:

PierreGilbert

Email:

<apgil AT SPAMFREE videotron DOT ca>


CategoryDyalog - CategoryDyalogDotNet - CategoryDyalogWpfUtilities - CategoryDotNet

wpfDialogBox (last edited 2015-07-29 05:41:00 by KaiJaeger)