private void SetTemplate(DialogBaseViewModel vm) { if (vm == null) { throw new InvalidCastException("DataContext는 DialogBaseViewModel에 의해 상속된 Class여야 합니다!"); } if (vm.ViewType == null) { throw new NullReferenceException("ViewType은 Null일 수 없습니다, ViewType을 정의하세요!"); } ContentPanelElement = GetTemplateChild("ContentPanel") as Panel; if (ContentPanelElement == null) { throw new InvalidCastException("ContentPanel이 확인 되지 않습니다, XAML코드를 확인하세요!"); } ResultButtonsPanelElement = GetTemplateChild("ButtonsPanel") as MessageButtonsPanel; if (ResultButtonsPanelElement == null) { throw new InvalidCastException("ButtonsPanel(MessageButtonsPanel)이 확인 되지 않습니다, XAML코드를 확인하세요!"); } ResultButtonsPanelElement.MessageButtonResultChanged += result => _result = result; SetContent(vm); }
public MessageBoxResult ShowDialog(string title, MessageBoxButton msgButton, DialogBaseViewModel vm, ResizeMode mode = ResizeMode.NoResize) { SetMember(null, title, msgButton, vm, mode); ShowDialog(); return(_result); }
private void SetContent(DialogBaseViewModel vm) { var content = Activator.CreateInstance(vm.ViewType) as FrameworkElement; content.DataContext = vm; ContentPanelElement.Children.Add(content); }
private void SetMember(Window owner, string title, MessageBoxButton msgButton, DialogBaseViewModel vm, ResizeMode mode) { if (owner != null) { this.Owner = owner; this.WindowStartupLocation = WindowStartupLocation.CenterOwner; } else { this.Topmost = true; this.WindowStartupLocation = WindowStartupLocation.CenterScreen; } WindowChrome.SetWindowChrome(this, new WindowChrome { NonClientFrameEdges = NonClientFrameEdges.None, CaptionHeight = 26, UseAeroCaptionButtons = false, ResizeBorderThickness = new Thickness(mode == ResizeMode.NoResize ? 0 : 5) }); this.Title = title; this.ResizeMode = mode; this.DataContext = vm; this.MessageBoxButtonInfo = msgButton; this.ConfirmCommand = vm.ConfirmCommand; this.CancelCommand = vm.CancelCommand; }