I am working in silverlight5 and i had to display a error messagebox(made by me using childwindow).I using MVVM approach and problem is situation is like this that i have to to pop up that error message in Model class when something go wrong.
I do this by doing ( cfw.Show()) in model class:
public static void ShowSmallMessageWithResult(string message) { ConfirmationWindow cfw = new ConfirmationWindow(); cfw.SetMessage(message); cfw.Show(); }
The problem is do not pop any error messagebox (i mean this chiildwindow). I dont know why ?
Note: Please note that ConfirmationWindow.xaml is in Model folder.
Why it is not working? How to make it work ?
And ConfirmationWindow.xaml is :
<silvercontrols:ChildWindow x:Class="Model.MessageFolder.ConfirmationWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:silvercontrols="clr-namespace:Silverlight.Windows.Controls;assembly=Silverlight.Windows.Controls" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" Title="Message" Width="Auto" Height="Auto" MouseRightButtonDown="ChildWindow_MouseRightButtonDown"><silvercontrols:ChildWindow.Style><StaticResource ResourceKey="MessageBoxStyle"/></silvercontrols:ChildWindow.Style><Grid x:Name="LayoutRoot" MinWidth="360"><StackPanel Orientation="Vertical"><TextBlock x:Name="MessageBox" Margin="10 15 0 0" Height="Auto" FontSize="12" Text="Text" Foreground="White" TextWrapping="Wrap" HorizontalAlignment="Left" /><StackPanel x:Name="ContentBox" Margin="10 15 0 0" Height="Auto" Orientation="Horizontal"></StackPanel><StackPanel Margin="0 0 0 10" Orientation="Horizontal" HorizontalAlignment="Center" Height="45"><Button x:Name="YesBtn" Content="Yes" Width="82" HorizontalAlignment="Left" VerticalAlignment="Bottom" Style="{StaticResource ButtonStyle_Blue}"/><Button x:Name="NoBtn" Content="No" Margin="60 0 0 0" Width="82" HorizontalAlignment="Right" VerticalAlignment="Bottom" Style="{StaticResource ButtonStyle_Blue}"/></StackPanel></StackPanel></Grid></silvercontrols:ChildWindow>
and ConfirmationWindow.xaml.cs is :
using System.Windows; namespace Model.MessageFolder { public partial class ConfirmationWindow : Silverlight.Windows.Controls.ChildWindow { private bool showBtnClose; public ConfirmationWindow(bool showBtnClose = false) { InitializeComponent(); HasCloseButton = showBtnClose; this.showBtnClose = showBtnClose; NoBtn.Click += Close; } #region METHODS public void SetMessage(string message) { MessageBox.Text = message; } public void AddContent(UIElement elt) { ContentBox.Children.Add(elt); } #endregion #region EVENT_HANDLER public void Close(object sender, RoutedEventArgs e) { this.Close(); } #endregion private void ChildWindow_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { e.Handled = true; } } }
The problem is do not pop any error messagebox (i mean this chiildwindow). I dont know why ?
Note: Please note that ConfirmationWindow.xaml is in Model folder. I know its not a good idea but there are no more option left because its a big already existing project and i have no more options left then popuping error message childwindow in model
Why it is not working? How to make it work ?