Mini Kabibi Habibi
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using DevExpress.Utils;
using DevExpress.Xpf.Core;
using System.Collections.Generic;
namespace ControlsDemo {
public partial class Dialog : ControlsDemoModule {
List<DXWindow> openedInstances = new List<DXWindow>();
public Dialog() {
InitializeComponent();
InitializeAnimationTypeCombobox();
InitializeDialogButtonCombobox();
InitializeDefaultDialogResultCombobox();
}
protected override void RaiseBeforeModuleDisappear() {
base.RaiseBeforeModuleDisappear();
foreach(DXWindow dxw in openedInstances) dxw.Hide();
openedInstances.Clear();
}
void InitializeAnimationTypeCombobox() {
Array typeArray = EnumExtensions.GetValues(typeof(WindowAnimationType));
foreach(WindowAnimationType db in typeArray)
AnimationType.Items.Add(db.ToString());
AnimationType.SelectedIndex = 0;
}
void InitializeDialogButtonCombobox() {
Array buttonArray = EnumExtensions.GetValues(typeof(DialogButtons));
foreach(DialogButtons db in buttonArray)
DialogButton.Items.Add(db.ToString());
DialogButton.SelectedIndex = 1;
}
void InitializeDefaultDialogResultCombobox() {
Array resultArray = EnumExtensions.GetValues(typeof(DialogResult));
foreach(DialogResult result in resultArray)
DefaultDialogResult.Items.Add(result.ToString());
DefaultDialogResult.SelectedIndex = 0;
}
private void ShowDialog_Click(object sender, RoutedEventArgs e) {
DXDialog dialog = ((DataTemplate)Resources["dt"]).LoadContent() as DXDialog;
openedInstances.Add(dialog);
dialog.Buttons = (DialogButtons)DialogButton.SelectedIndex;
dialog.Title = Title.Text;
dialog.DefaultDialogResult = (DialogResult)DefaultDialogResult.SelectedIndex;
dialog.KeepPosition = KeepPosition.IsChecked.Value;
dialog.Opened += Dialog_Opened;
dialog.Closing += Dialog_Closing;
dialog.Closed += Dialog_Closed;
dialog.Icon = GetIcon();
dialog.AnimationType = (WindowAnimationType)AnimationType.SelectedIndex;
dialog.ShowAnimation = CreateAnimation(true);
dialog.HideAnimation = CreateAnimation(false);
dialog.FlowDirection = this.DemoModuleControl.Content.FlowDirection;
if(IsModal.IsChecked.Value)
dialog.ShowDialog();
else
dialog.Show();
}
void Dialog_Closing(object sender, CancelEventArgs e) {
DXDialog d = (DXDialog)sender;
Log.Text += "DXDialog(" + Convert.ToString(d.Title) + ") Closing event raised with result = " + d.DialogResult.ToString() + "\n";
e.Cancel = CancelClosingEvent.IsChecked.Value;
}
void Dialog_Closed(object sender, EventArgs e) {
DXDialog d = (DXDialog)sender;
Log.Text += "DXDialog(" + Convert.ToString(d.Title) + ") Closed event raised with result = " + d.DialogResult.ToString() + "\n";
}
void Dialog_Opened(object sender, EventArgs e) {
DXDialog d = (DXDialog)sender;
Log.Text += "DXDialog(" + Convert.ToString(d.Title) + ") Opened event raised\n";
}
void Window_Closing(object sender, CancelEventArgs e) {
DXWindow d = (DXWindow)sender;
Log.Text += "DXWindow(" + Convert.ToString(d.Title) + ") Closing event raised\n";
e.Cancel = CancelClosingEvent.IsChecked.Value;
}
void Window_Closed(object sender, EventArgs e) {
DXWindow d = (DXWindow)sender;
Log.Text += "DXWindow(" + Convert.ToString(d.Title) + ") Closed event raised\n";
}
void Window_Opened(object sender, EventArgs e) {
DXWindow d = (DXWindow)sender;
Log.Text += "DXWindow(" + Convert.ToString(d.Title) + ") Opened event raised\n";
}
private void ShowWindow_Click(object sender, RoutedEventArgs e) {
DXWindow window = ((DataTemplate)Resources["wt"]).LoadContent() as DXWindow;
openedInstances.Add(window);
window.Title = Title.Text;
window.KeepPosition = KeepPosition.IsChecked.Value;
window.Opened += Window_Opened;
window.Closing += Window_Closing;
window.Closed += Window_Closed;
window.Icon = GetIcon();
window.AnimationType = (WindowAnimationType)AnimationType.SelectedIndex;
window.ShowAnimation = CreateAnimation(true);
window.HideAnimation = CreateAnimation(false);
window.FlowDirection = this.DemoModuleControl.Content.FlowDirection;
if(IsModal.IsChecked.Value)
window.ShowDialog();
else
window.Show();
}
private void ClearMessages_Click(object sender, RoutedEventArgs e) {
Log.Text = "";
}
Image GetIcon() { return new Image() { Source = new BitmapImage(new Uri("../Images/AgControls.png", UriKind.Relative)) }; }
Storyboard CreateAnimation(bool isShow) {
DoubleAnimation daAngle = new DoubleAnimation();
DoubleAnimation daOpacity = new DoubleAnimation();
Storyboard sb = 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) {
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;
}
return sb;
}
void CancelClosingEvent_Loaded(object sender, RoutedEventArgs e) {
CheckBox cb = (CheckBox)sender;
bool isVisible = IsChecked(IsModal) && IsChecked(CancelClosingEvent);
cb.Visibility = isVisible ? Visibility.Visible : Visibility.Collapsed;
if(!isVisible)
return;
Binding isCheckedBinding = new Binding("IsChecked");
isCheckedBinding.Source = this.CancelClosingEvent;
isCheckedBinding.Mode = BindingMode.TwoWay;
cb.SetBinding(CheckBox.IsCheckedProperty, isCheckedBinding);
}
bool IsChecked(CheckBox cb) { return cb.IsChecked.Value; }
}
}