Mini Kabibi Habibi
Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media.Animation
Imports System.Windows.Media.Imaging
Imports DevExpress.Utils
Imports DevExpress.Xpf.Core
Imports System.Collections.Generic
Namespace ControlsDemo
Partial Public Class Dialog
Inherits ControlsDemoModule
Private openedInstances As New List(Of DXWindow)()
Public Sub New()
InitializeComponent()
InitializeAnimationTypeCombobox()
InitializeDialogButtonCombobox()
InitializeDefaultDialogResultCombobox()
End Sub
Protected Overrides Sub RaiseBeforeModuleDisappear()
MyBase.RaiseBeforeModuleDisappear()
For Each dxw As DXWindow In openedInstances
dxw.Hide()
Next dxw
openedInstances.Clear()
End Sub
Private Sub InitializeAnimationTypeCombobox()
Dim typeArray As Array = EnumExtensions.GetValues(GetType(WindowAnimationType))
For Each db As WindowAnimationType In typeArray
AnimationType.Items.Add(db.ToString())
Next db
AnimationType.SelectedIndex = 0
End Sub
Private Sub InitializeDialogButtonCombobox()
Dim buttonArray As Array = EnumExtensions.GetValues(GetType(DialogButtons))
For Each db As DialogButtons In buttonArray
DialogButton.Items.Add(db.ToString())
Next db
DialogButton.SelectedIndex = 1
End Sub
Private Sub InitializeDefaultDialogResultCombobox()
Dim resultArray As Array = EnumExtensions.GetValues(GetType(DialogResult))
For Each result As DialogResult In resultArray
DefaultDialogResult.Items.Add(result.ToString())
Next result
DefaultDialogResult.SelectedIndex = 0
End Sub
Private Sub ShowDialog_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim dialog As DXDialog = TryCast((CType(Resources("dt"), DataTemplate)).LoadContent(), DXDialog)
openedInstances.Add(dialog)
dialog.Buttons = CType(DialogButton.SelectedIndex, DialogButtons)
dialog.Title = Title.Text
dialog.DefaultDialogResult = CType(DefaultDialogResult.SelectedIndex, DialogResult)
dialog.KeepPosition = KeepPosition.IsChecked.Value
AddHandler dialog.Opened, AddressOf Dialog_Opened
AddHandler dialog.Closing, AddressOf Dialog_Closing
AddHandler dialog.Closed, AddressOf Dialog_Closed
dialog.Icon = GetIcon()
dialog.AnimationType = CType(AnimationType.SelectedIndex, WindowAnimationType)
dialog.ShowAnimation = CreateAnimation(True)
dialog.HideAnimation = CreateAnimation(False)
dialog.FlowDirection = Me.DemoModuleControl.Content.FlowDirection
If IsModal.IsChecked.Value Then
dialog.ShowDialog()
Else
dialog.Show()
End If
End Sub
Private Sub Dialog_Closing(ByVal sender As Object, ByVal e As CancelEventArgs)
Dim d As DXDialog = CType(sender, DXDialog)
Log.Text &= "DXDialog(" & Convert.ToString(d.Title) & ") Closing event raised with result = " & d.DialogResult.ToString() & Constants.vbLf
e.Cancel = CancelClosingEvent.IsChecked.Value
End Sub
Private Sub Dialog_Closed(ByVal sender As Object, ByVal e As EventArgs)
Dim d As DXDialog = CType(sender, DXDialog)
Log.Text &= "DXDialog(" & Convert.ToString(d.Title) & ") Closed event raised with result = " & d.DialogResult.ToString() & Constants.vbLf
End Sub
Private Sub Dialog_Opened(ByVal sender As Object, ByVal e As EventArgs)
Dim d As DXDialog = CType(sender, DXDialog)
Log.Text &= "DXDialog(" & Convert.ToString(d.Title) & ") Opened event raised" & Constants.vbLf
End Sub
Private Sub Window_Closing(ByVal sender As Object, ByVal e As CancelEventArgs)
Dim d As DXWindow = CType(sender, DXWindow)
Log.Text &= "DXWindow(" & Convert.ToString(d.Title) & ") Closing event raised" & Constants.vbLf
e.Cancel = CancelClosingEvent.IsChecked.Value
End Sub
Private Sub Window_Closed(ByVal sender As Object, ByVal e As EventArgs)
Dim d As DXWindow = CType(sender, DXWindow)
Log.Text &= "DXWindow(" & Convert.ToString(d.Title) & ") Closed event raised" & Constants.vbLf
End Sub
Private Sub Window_Opened(ByVal sender As Object, ByVal e As EventArgs)
Dim d As DXWindow = CType(sender, DXWindow)
Log.Text &= "DXWindow(" & Convert.ToString(d.Title) & ") Opened event raised" & Constants.vbLf
End Sub
Private Sub ShowWindow_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim window As DXWindow = TryCast((CType(Resources("wt"), DataTemplate)).LoadContent(), DXWindow)
openedInstances.Add(window)
window.Title = Title.Text
window.KeepPosition = KeepPosition.IsChecked.Value
AddHandler window.Opened, AddressOf Window_Opened
AddHandler window.Closing, AddressOf Window_Closing
AddHandler window.Closed, AddressOf Window_Closed
window.Icon = GetIcon()
window.AnimationType = CType(AnimationType.SelectedIndex, WindowAnimationType)
window.ShowAnimation = CreateAnimation(True)
window.HideAnimation = CreateAnimation(False)
window.FlowDirection = Me.DemoModuleControl.Content.FlowDirection
If IsModal.IsChecked.Value Then
window.ShowDialog()
Else
window.Show()
End If
End Sub
Private Sub ClearMessages_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Log.Text = ""
End Sub
Private Function GetIcon() As Image
Return New Image() With {.Source = New BitmapImage(New Uri("../Images/AgControls.png", UriKind.Relative))}
End Function
Private Function CreateAnimation(ByVal isShow As Boolean) As Storyboard
Dim daAngle As New DoubleAnimation()
Dim daOpacity As New DoubleAnimation()
Dim sb As New Storyboard()
sb.Children.Add(daAngle)
sb.Children.Add(daOpacity)
Storyboard.SetTargetProperty(daAngle, New PropertyPath("Grid.RenderTransform.Children[1].Angle"))
Storyboard.SetTargetProperty(daOpacity, New PropertyPath("Opacity"))
daAngle.Duration = New Duration(TimeSpan.FromSeconds(1))
If isShow Then
daAngle.From = 0
daAngle.To = 360
daOpacity.From = 0
daOpacity.To = 1
Else
daAngle.From = 360
daAngle.To = 0
daOpacity.From = 1
daOpacity.To = 0
End If
Return sb
End Function
Private Sub CancelClosingEvent_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim cb As CheckBox = CType(sender, CheckBox)
Dim isVisible As Boolean = IsChecked(IsModal) AndAlso IsChecked(CancelClosingEvent)
cb.Visibility = If(isVisible, Visibility.Visible, Visibility.Collapsed)
If (Not isVisible) Then
Return
End If
Dim isCheckedBinding As New Binding("IsChecked")
isCheckedBinding.Source = Me.CancelClosingEvent
isCheckedBinding.Mode = BindingMode.TwoWay
cb.SetBinding(CheckBox.IsCheckedProperty, isCheckedBinding)
End Sub
Private Function IsChecked(ByVal cb As CheckBox) As Boolean
Return cb.IsChecked.Value
End Function
End Class
End Namespace