' Follow steps 1a or 1b and then 2 to use this custom control in a XAML file. ' ' Step 1a) Using this custom control in a XAML file that exists in the current project. ' Add this XmlNamespace attribute to the root element of the markup file where it is ' to be used: ' ' xmlns:MyNamespace="clr-namespace:EgtWPFLib5" ' ' ' Step 1b) Using this custom control in a XAML file that exists in a different project. ' Add this XmlNamespace attribute to the root element of the markup file where it is ' to be used: ' ' xmlns:MyNamespace="clr-namespace:EgtWPFLib5;assembly=EgtWPFLib5" ' ' You will also need to add a project reference from the project where the XAML file lives ' to this project and Rebuild to avoid compilation errors: ' ' Right click on the target project in the Solution Explorer and ' "Add Reference"->"Projects"->[Browse to and select this project] ' ' ' Step 2) ' Go ahead and use your control in the XAML file. Note that Intellisense in the ' XML editor does not currently work on custom controls and its child elements. ' ' ' Imports System.Windows.Controls.Primitives Imports EgtUILib Public Class EgtMsgBox Inherits System.Windows.Window Public Const MSG_EGTMSGBOX = 20040 Private m_Grid As Grid Private m_Title As TextBlock Private m_Icon As Image Private m_Text As TextBlock Private m_ProgressBar As ProgressBar Private m_Button1 As Button Private m_Button2 As Button Private m_Button3 As Button Shared Sub New() 'This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class. 'This style is defined in themes\generic.xaml DefaultStyleKeyProperty.OverrideMetadata(GetType(EgtMsgBox), New FrameworkPropertyMetadata(GetType(EgtMsgBox))) End Sub Public Overrides Sub OnApplyTemplate() MyBase.OnApplyTemplate() ' Retrieve the Button from the current template m_Grid = TryCast(MyBase.GetTemplateChild("PART_MoveRectangle"), Grid) m_Title = TryCast(MyBase.GetTemplateChild("PART_MoveRectangle"), TextBlock) m_Icon = TryCast(MyBase.GetTemplateChild("PART_MoveRectangle"), Image) m_Text = TryCast(MyBase.GetTemplateChild("PART_MoveRectangle"), TextBlock) m_ProgressBar = TryCast(MyBase.GetTemplateChild("PART_MoveRectangle"), ProgressBar) m_Button1 = TryCast(MyBase.GetTemplateChild("PART_MoveRectangle"), Button) m_Button2 = TryCast(MyBase.GetTemplateChild("PART_MoveRectangle"), Button) m_Button3 = TryCast(MyBase.GetTemplateChild("PART_MoveRectangle"), Button) End Sub ''Parametri ricevuti 'Private m_sTitle As String = String.Empty 'Private m_sText As String = String.Empty Private m_Buttons As Buttons = Buttons.NULL Private m_IconVal As Icons = Icons.NULL Private m_bProgressBar As Boolean = False Private m_Width As Double = 0 Private m_WidthType As WidthType = WidthType.NULL Private m_iExtraColumns As Integer = 0 Private m_iExtraHalfRows As Integer = 0 'Parametri ausiliari Private m_nRow As Double = 0 Private m_nColumn As Double = 0 'Parametro di ritorno Public Shadows DialogResult As Integer = 0 ' Riferimento alla finestra che contiene la MsgBox Private m_Owner As Window ' Proprietà che permette di cambiare il Text a finestra già aperta, utile per aggiornare il testo durante i caricamenti Public Property Text Get Return m_Text.Text End Get Set(value) m_Text.Text = value End Set End Property ' Proprietà che permette di cambiare il Value della LoadingPrBr all'esterno della libreria Public Property ProgressBarValue Get Return m_ProgressBar.Value End Get Set(value) m_ProgressBar.Value = value End Set End Property 'Enum Enum Buttons YES_NO_CANCEL OK_CANCEL ONE_TWO OK NULL End Enum Enum Icons DANGER ESCLAMATION IMAGE NULL End Enum Enum WidthType GRID PIXEL NULL End Enum 'Costruttori Sub New(Owner As Window, sTitle As String, sText As String, Buttons As Buttons, Icon As Icons, Optional ExtraColumns As Integer = 0, Optional ExtraHalfRows As Integer = 0) 'Inizializzazione dei membri della classe con i valori ricevuti m_Owner = Owner m_Title.Text = sTitle m_Text.Text = sText m_Buttons = Buttons m_IconVal = Icon m_WidthType = WidthType.NULL m_iExtraColumns = ExtraColumns m_iExtraHalfRows = ExtraHalfRows 'Apro direttamente la finestra If m_Buttons <> EgtMsgBox.Buttons.NULL Then Me.ShowDialog() Else Me.Show() End If End Sub Sub New(Owner As Window, Width As Double, WidthType As WidthType, sTitle As String, sText As String, Buttons As Buttons, Icon As Icons, Optional ExtraColumns As Integer = 0, Optional ExtraHalfRows As Integer = 0) 'Inizializzazione dei membri della classe con i valori ricevuti m_Owner = Owner m_Title.Text = sTitle m_Text.Text = sText m_Buttons = Buttons m_IconVal = Icon m_Width = Width m_WidthType = WidthType m_iExtraColumns = ExtraColumns m_iExtraHalfRows = ExtraHalfRows 'Apro direttamente la finestra If m_Buttons <> EgtMsgBox.Buttons.NULL Then Me.ShowDialog() Else Me.Show() End If End Sub Sub New(Owner As Window, sTitle As String, sText As String, bProgressBar As Boolean, Icon As Icons, Optional ExtraColumns As Integer = 0, Optional ExtraHalfRows As Integer = 0) 'Inizializzazione dei membri della classe con i valori ricevuti m_Owner = Owner m_Title.Text = sTitle m_Text.Text = sText m_bProgressBar = bProgressBar m_IconVal = Icon m_WidthType = WidthType.NULL m_iExtraColumns = ExtraColumns m_iExtraHalfRows = ExtraHalfRows 'Apro direttamente la finestra Me.Show() End Sub Private Sub EgtMsgBox_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized 'Calcolo il numero di righe necessarie If m_Title.Text <> String.Empty Then m_nRow += 0.5 If m_Text.Text <> String.Empty Then m_nRow += 1 End If If m_bProgressBar Then m_nRow += 1 End If If m_Buttons <> EgtMsgBox.Buttons.NULL Then m_nRow += 1.5 End If Else If m_Text.Text <> String.Empty Then m_nRow += 1 End If If m_bProgressBar Then m_nRow += 1 End If If m_Buttons <> EgtMsgBox.Buttons.NULL Then m_nRow += 1.5 End If End If m_nRow += m_iExtraHalfRows / 2 'Calcolo il numero di colonne necessarie Select Case m_Buttons Case Buttons.YES_NO_CANCEL, Buttons.OK m_nColumn = 5 Case Buttons.OK_CANCEL, Buttons.ONE_TWO m_nColumn = 4.5 Case Buttons.NULL m_nColumn = 3.5 End Select m_nColumn += m_iExtraColumns 'Creo la griglia For Index As Integer = 1 To m_nRow * 2 m_Grid.RowDefinitions.Add(New RowDefinition) Next For Index As Integer = 1 To m_nColumn * 2 m_Grid.ColumnDefinitions.Add(New ColumnDefinition) Next 'Attivo/disattivo gli elementi e li posiziono If m_Title.Text <> String.Empty Then m_Title.SetValue(Grid.RowProperty, 0) m_Title.SetValue(Grid.ColumnProperty, 1) m_Title.SetValue(Grid.ColumnSpanProperty, m_Grid.ColumnDefinitions.Count - 2) Else m_Title.Visibility = Windows.Visibility.Hidden End If If m_IconVal = Icons.NULL Then m_Icon.Visibility = Windows.Visibility.Hidden End If If m_Text.Text <> String.Empty Then If m_Title.Text <> String.Empty Then m_Text.SetValue(Grid.RowProperty, 1) m_Icon.SetValue(Grid.RowProperty, 1) Else m_Text.SetValue(Grid.RowProperty, 0) m_Text.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center) m_Icon.SetValue(Grid.RowProperty, 0) m_Icon.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center) End If If m_IconVal <> Icons.NULL Then m_Text.SetValue(Grid.ColumnProperty, 3) m_Text.SetValue(Grid.ColumnSpanProperty, m_Grid.ColumnDefinitions.Count - 4) m_Icon.SetValue(Grid.ColumnProperty, 1) m_Icon.SetValue(Grid.ColumnSpanProperty, 2) m_Icon.SetValue(Grid.RowSpanProperty, 2) Else m_Text.SetValue(Grid.ColumnProperty, 1) m_Text.SetValue(Grid.ColumnSpanProperty, m_Grid.ColumnDefinitions.Count - 2) m_Text.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center) End If m_Text.SetValue(Grid.RowSpanProperty, 2 + m_iExtraHalfRows) Else m_Text.Visibility = Windows.Visibility.Hidden m_Icon.Visibility = Windows.Visibility.Hidden End If If m_bProgressBar Then If m_Title.Text <> String.Empty Then If m_Text.Text <> String.Empty Then m_ProgressBar.SetValue(Grid.RowProperty, 3 + m_iExtraHalfRows) Else m_ProgressBar.SetValue(Grid.RowProperty, 1) End If Else If m_Text.Text <> String.Empty Then m_ProgressBar.SetValue(Grid.RowProperty, 2 + m_iExtraHalfRows) Else m_ProgressBar.SetValue(Grid.RowProperty, 0) End If End If m_ProgressBar.SetValue(Grid.ColumnProperty, 1) m_ProgressBar.SetValue(Grid.ColumnSpanProperty, m_Grid.ColumnDefinitions.Count - 2) Else m_ProgressBar.Visibility = Windows.Visibility.Hidden End If If m_Buttons <> Buttons.NULL Then If m_Title.Text <> String.Empty Then If m_Text.Text <> String.Empty Then If m_bProgressBar Then m_Button1.SetValue(Grid.RowProperty, 5 + m_iExtraHalfRows) m_Button2.SetValue(Grid.RowProperty, 5 + m_iExtraHalfRows) m_Button3.SetValue(Grid.RowProperty, 5 + m_iExtraHalfRows) Else m_Button1.SetValue(Grid.RowProperty, 3 + m_iExtraHalfRows) m_Button2.SetValue(Grid.RowProperty, 3 + m_iExtraHalfRows) m_Button3.SetValue(Grid.RowProperty, 3 + m_iExtraHalfRows) End If Else If m_bProgressBar Then m_Button1.SetValue(Grid.RowProperty, 3) m_Button2.SetValue(Grid.RowProperty, 3) m_Button3.SetValue(Grid.RowProperty, 3) Else m_Button1.SetValue(Grid.RowProperty, 1) m_Button2.SetValue(Grid.RowProperty, 1) m_Button3.SetValue(Grid.RowProperty, 1) End If End If Else If m_Text.Text <> String.Empty Then If m_bProgressBar Then m_Button1.SetValue(Grid.RowProperty, 4 + m_iExtraHalfRows) m_Button2.SetValue(Grid.RowProperty, 4 + m_iExtraHalfRows) m_Button3.SetValue(Grid.RowProperty, 4 + m_iExtraHalfRows) Else m_Button1.SetValue(Grid.RowProperty, 2 + m_iExtraHalfRows) m_Button2.SetValue(Grid.RowProperty, 2 + m_iExtraHalfRows) m_Button3.SetValue(Grid.RowProperty, 2 + m_iExtraHalfRows) End If Else If m_bProgressBar Then m_Button1.SetValue(Grid.RowProperty, 2) m_Button2.SetValue(Grid.RowProperty, 2) m_Button3.SetValue(Grid.RowProperty, 2) Else m_Button1.SetValue(Grid.RowProperty, 0) m_Button2.SetValue(Grid.RowProperty, 0) m_Button3.SetValue(Grid.RowProperty, 0) End If End If End If m_Button1.SetValue(Grid.RowSpanProperty, 2) m_Button2.SetValue(Grid.RowSpanProperty, 2) m_Button3.SetValue(Grid.RowSpanProperty, 2) End If Select Case m_Buttons Case Buttons.YES_NO_CANCEL m_Button1.SetValue(Grid.ColumnProperty, 1 + m_iExtraColumns) m_Button1.SetValue(Grid.ColumnSpanProperty, 2) m_Button1.Content = EgtMsg(MSG_EGTMSGBOX + 3) m_Button2.SetValue(Grid.ColumnProperty, 4 + m_iExtraColumns) m_Button2.SetValue(Grid.ColumnSpanProperty, 2) m_Button2.Content = EgtMsg(MSG_EGTMSGBOX + 4) m_Button3.SetValue(Grid.ColumnProperty, 7 + m_iExtraColumns) m_Button3.SetValue(Grid.ColumnSpanProperty, 2) m_Button3.Content = EgtMsg(MSG_EGTMSGBOX + 2) Case Buttons.OK_CANCEL m_Button1.SetValue(Grid.ColumnProperty, 2 + m_iExtraColumns) m_Button1.SetValue(Grid.ColumnSpanProperty, 2) m_Button1.Content = EgtMsg(MSG_EGTMSGBOX + 1) m_Button2.Visibility = Windows.Visibility.Hidden m_Button3.SetValue(Grid.ColumnProperty, 5 + m_iExtraColumns) m_Button3.SetValue(Grid.ColumnSpanProperty, 2) m_Button3.Content = EgtMsg(MSG_EGTMSGBOX + 2) Case Buttons.ONE_TWO m_Button1.SetValue(Grid.ColumnProperty, 2 + m_iExtraColumns) m_Button1.SetValue(Grid.ColumnSpanProperty, 2) m_Button1.Content = "1" m_Button2.Visibility = Windows.Visibility.Hidden m_Button3.SetValue(Grid.ColumnProperty, 5 + m_iExtraColumns) m_Button3.SetValue(Grid.ColumnSpanProperty, 2) m_Button3.Content = "2" Case Buttons.OK m_Button1.SetValue(Grid.ColumnProperty, 4 + m_iExtraColumns) m_Button1.SetValue(Grid.ColumnSpanProperty, 2) m_Button1.Content = EgtMsg(MSG_EGTMSGBOX + 1) m_Button2.Visibility = Windows.Visibility.Hidden m_Button3.Visibility = Windows.Visibility.Hidden Case Buttons.NULL m_Button1.Visibility = Windows.Visibility.Hidden m_Button2.Visibility = Windows.Visibility.Hidden m_Button3.Visibility = Windows.Visibility.Hidden End Select 'Assegno agli elementi i valori ricevuti Dim sImagePath As String = String.Empty 'Select Case m_IconVal ' Case Icons.DANGER ' sImagePath = InitializeEgtWPFLib.MsgBoxDangerPath ' Case Icons.ESCLAMATION ' sImagePath = InitializeEgtWPFLib.MsgBoxExclamationPath ' Case Icons.IMAGE ' sImagePath = InitializeEgtWPFLib.MsgBoxImagePath 'End Select 'If m_IconVal <> Icons.NULL Then ' Try ' IconImg.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri(sImagePath, UriKind.Absolute)) ' Catch ex As Exception ' EgtOutLog("Errore nel caricamento dell'icona dell'EgtMsgBox") ' End Try 'End If 'Calcolo dimensioni e posizione della finestra Select Case m_WidthType 'Case WidthType.NULL ' Me.Height = m_Owner.Height / InitializeEgtWPFLib.BaseGridHeight * m_nRow ' Me.Width = m_Owner.Width / InitializeEgtWPFLib.BaseGridWidth * m_nColumn 'Case WidthType.GRID ' Me.Height = m_Owner.Height / InitializeEgtWPFLib.BaseGridHeight * m_nColumn * m_Width / m_nRow ' Me.Width = m_Owner.Width / InitializeEgtWPFLib.BaseGridWidth * m_Width Case WidthType.PIXEL ' Fisso il minimo a 250 pixel perchè più piccola diventa inutilizzabile If m_Width < 250 Then m_Width = 250 End If Me.Height = m_Width / m_nColumn * m_nRow Me.Width = m_Width End Select Me.Top = m_Owner.Top + (m_Owner.Height / 2) - (Me.Height / 2) Me.Left = m_Owner.Left + (m_Owner.Width / 2) - (Me.Width / 2) 'Assegno la finestra come figlia della MainWindow Me.Owner = m_Owner End Sub Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) DialogResult = 1 End Sub Private Sub Button2_Click(sender As Object, e As RoutedEventArgs) DialogResult = 2 End Sub Private Sub Button3_Click(sender As Object, e As RoutedEventArgs) DialogResult = 0 End Sub End Class