Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3950176
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:34:51+00:00 2026-05-20T01:34:51+00:00

trying to use a login window with caliburn + mef I get these two

  • 0

trying to use a login window with caliburn + mef

I get these two warnings as well

Warning    1    CA2000 : Microsoft.Reliability : In method 'AppBootstrapper.CreateContainer()', call System.IDisposable.Dispose on object 'container' before all references to it are out of scope.    C:\adl\DotNetProjects\CaliburnTest\CaliburnTest\AppBootstrapper.cs    25    CaliburnTest
Warning    2    CA2000 : Microsoft.Reliability : In method 'AppBootstrapper.CreateContainer()', call System.IDisposable.Dispose on object 'new AggregateCatalog(Enumerable.Select<Assembly, AssemblyCatalog>(this.SelectAssemblies(), AppBootstrapper.CS$<>9__CachedAnonymousMethodDelegate1))' before all references to it are out of scope.    C:\adl\DotNetProjects\CaliburnTest\CaliburnTest\AppBootstrapper.cs    25    CaliburnTest

Thanks in advance I know that caliburn is going to save me lots of time would love to get this to work!

In this project my IShell is an empty interface.

public class AppBootstrapper : Bootstrapper<IShell>
{
    protected override IServiceLocator CreateContainer()
    {
        var container = new CompositionContainer(
            new AggregateCatalog(SelectAssemblies().Select(x => new AssemblyCatalog(x)))
            );

        var batch = new CompositionBatch();
        //batch.AddExportedValue<IWindowManager>(new WindowManager());
        return new MEFAdapter(container);
    }
}



[Export(typeof(IShell))]
public class MainViewModel : Conductor<IScreen>, IShell
{
    readonly IWindowManager windowManager;
    [ImportingConstructor]
    public MainViewModel(IWindowManager windowManager)
    {
        this.windowManager = windowManager;
        var result = windowManager.ShowDialog(new LoginWindowViewModel());
        if (result != true)
        {
            Application.Current.Shutdown();
        }
    }
}

[Export(typeof(LoginWindowViewModel))]
public class LoginWindowViewModel :Screen
{
    public LoginWindowViewModel()
    {
    }
    public  ObservableCollection<User> Users
    {
        get
        {
            if (_users == null)
            {
                _users = new ObservableCollection<User>(){new User("ADMIN","ADMIN","ADMIN")};
            }
            return _users;
        }
    }

    public bool AuthenticateUser(string username, string pass)
    {
        Common.Authenticated.CurrentUser = Users.Where<User>(y => y.Login.Trim() == username.Trim()).FirstOrDefault(y => y.Pass.Trim() == pass.Trim());
        if (Common.Authenticated.CurrentUser != null)
            return true;
        return false;
    }
    public bool Authenticated 
    {
        get
        {
            if (Username == null || Username == String.Empty || Password == null || Password == String.Empty)
                return false;
            return AuthenticateUser(Username, Password); 
        }
    }
    public bool CheckAuthNeeded() {return true;}
    private ObservableCollection<User> _users;

    public void Login()
    {    RequestClose(this, new SuccessEventArgs(true));      }
    public string Username {get;set;}
    public string Password {get;set;}

    public event CloseDialogEventHandler RequestClose;
      public delegate void CloseDialogEventHandler(object sender, SuccessEventArgs e);
}

LoginWindowView:

<Grid Height="Auto" Width="Auto">
    <Grid.RowDefinitions>
        <RowDefinition Height="2*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="93*" />
        <ColumnDefinition Width="185*" />
    </Grid.ColumnDefinitions>
    <StackPanel Grid.Column="0" Margin="10,10,0,0">
        <Label Content="Username:"  FontWeight="Bold" VerticalContentAlignment="Center" Margin="0,4,0,0" Padding="5,5,0,5" />
        <Label Content="Password:"  FontWeight="Bold" VerticalContentAlignment="Center" VerticalAlignment="Stretch" Margin="0,4,0,0" Padding="5,5,0,5" />
    </StackPanel>
    <StackPanel Grid.Column="1" Margin="0,10,10,0">
        <dxe:ComboBoxEdit x:Name="User" ItemsSource="{Binding Users}" 
                         Padding="0" Margin="5" DisplayMember="Login" ValueMember="Login" Validate="User_Validate" ValidateOnTextInput="True"
                          AutoComplete="True" ImmediatePopup="True"   IncrementalFiltering="True" ShowEditorButtons="False" />
        <dxe:PasswordBoxEdit x:Name="Pass" Margin="5" Validate="Pass_Validate" ValidateOnTextInput="False"  InvalidValueBehavior="AllowLeaveEditor" />
    </StackPanel> 
    <Button Content="Login" Grid.Row="1" Height="23" HorizontalAlignment="Center" 
            x:Name="Login" VerticalAlignment="Top" Width="75" IsDefault="True" Grid.ColumnSpan="2" />
</Grid>

LoginWindowView CodeBehind:

public partial class LoginWindowView
{
    public LoginWindowView()
    {
        InitializeComponent();
    }
    private void User_Validate(object sender, ValidationEventArgs e)
    {

        if (e.Value == null)
        {
            e.IsValid = false;
            return;
        }
        var _vm = GetDataContext();
        var u = _vm.Users.FirstOrDefault<User>(x => x.Login.Trim() == ((string)e.Value).Trim().ToUpper());

        if (u == null)
        {
            e.SetError("Invalid Login Name", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
            _vm.Username = string.Empty;
            e.IsValid = false;
        }
        else
            _vm.Username = User.Text;
    }
    public LoginWindowViewModel GetDataContext()
    {
        return (LoginWindowViewModel)DataContext;
    }
    private void Pass_Validate(object sender, ValidationEventArgs e)
    {
        if (e.Value == null)
        {
            e.IsValid = false;
            return;
        }
        var _vm = GetDataContext();
        _vm.Password = ((string)e.Value).ToUpper();
        if (_vm.Authenticated == false)
        {
            e.SetError("Wrong Password.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical);
            e.IsValid = false;
        }
    }
    private void Window_Closed(object sender, EventArgs ee)
    {
        GetDataContext().RequestClose -= (s, e) =>
        {
            this.DialogResult = e.Success;
        };
    }
    private void Window_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        if (e.OldValue != null)
        {
            ((LoginWindowViewModel)e.OldValue).RequestClose -= (s, ee) =>
            {
                this.DialogResult = ee.Success;
            };
        }
        ((LoginWindowViewModel)e.NewValue).RequestClose += (s, ee) =>
        {
            this.DialogResult = ee.Success;
        };
    }
}

public class User
{
    public string FullName { get; private set; }
    public string Login { get; private set; }
    public string Pass { get; private set; }

    public User(string fullName, string login, string pass) { FullName = fullName; Login = login; Pass = pass; }
    public static User CreateUser(string fullName, string login,string pass)
    {
        return new User(fullName, login,pass);
    }
}




    public static class Authenticated
    {
        public static string AuthString { get; set; }
        public static User CurrentUser { get; set; }
        public static string UserId
        {
            get
            {
                if (CurrentUser != null)
                    return CurrentUser.Login;
                return string.Empty;
            }
        }
    }

MainView:

<Window x:Class="CaliburnTest.Views.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainView" Height="300" Width="300">
    <Grid>
        <Label>Test</Label>
    </Grid>
</Window>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:34:51+00:00Added an answer on May 20, 2026 at 1:34 am

    Actually Rob Eisenberg of caliburn was very helpful and he helped me out with this issue.

    The problem was that when I switched to caliburn the LoginView was the first window to be opened and it was closed before the MainView window was opened.

    windows treats the first window opened as the mainwindow. and when the mainwindow is closed windows checks if other windows are open if not it closes the application.

    He provided a possible solution of making the loginviewmodel the shell and closing it after opening the mainviewmodel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to use ImageInfo and Jython to get information from a image on
I get this error when trying to connect to SQL Server. Error is: Login
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use a guid as a resource id in a rest url but
While trying to use LINQ to SQL I encountered several problems. I have table
I' trying to use a Linq query to find and set the selected value
I'm trying to use svnmerge.py to merge some files. Under the hood it uses
I've been trying to use SQLite with the PDO wrapper in PHP with mixed
I'm trying to use SQLBindParameter to prepare my driver for input via SQLPutData .
I'm trying to use jQuery to format code blocks, specifically to add a <pre>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.