Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    advapiIT
    @advapiIT
    Excuse me Geert, a really stupid question but I can't remember how it's done. if I need to fill on the MainView a ContentPresenter and bind it to a viewmodel, how do I render the view? I mean on the MainViewModel I have the viewmodel I need to show. on the MainView.Xaml I've added the ContentPresenter and it binds to a Content property. what I'm missing is the type of the property...has it to be an IView? and resolved via IViewLocator or its something that does the magic?
    advapiIT
    @advapiIT
    The magic was
    <catel:ViewModelToViewConverter x:Key="ViewModelToViewConverter"></catel:ViewModelToViewConverter>
    <catel:ViewModelToViewConverter x:Key="ViewModelToViewConverter"></catel:ViewModelToViewConverter>
    almost 4 years I write here, and still have got problem pasting code...LOL
    Geert van Horrik
    @GeertvanHorrik
    :)
    venom_aa
    @venomAA
    @advapiIT i do that with my systems..let me help you
    /// <summary>
    /// Dependencia para crear propiedad ContentControlBag. Nos permite mantener aislado el ContentControl de la vista modelo.
    /// </summary>
    public static readonly DependencyProperty ContentControlBagPropiedad = DependencyProperty.Register("ContentControlBag", typeof(ContentControlBag),
    typeof(MainWindow), new PropertyMetadata(null, (sender, e) => ((MainWindow)sender).UpdateContentControl()));
        private void UpdateContentControl()
        {
            if (ContentControlBag != null)
            {
                contenedorVistas.Content = null;
                GC.Collect(); // necesario para que se limpie el contenedor de vistas
                contenedorVistas.Content = ContentControlBag.View;
                contenedorVistas.DataContext = ContentControlBag.ViewModel;
            }
        }
    
        public ContentControlBag ContentControlBag
        {
            get { return (ContentControlBag)GetValue(ContentControlBagPropiedad); }
            set { SetValue(ContentControlBagPropiedad, value); }
        }
    this binds the view model and view to the content property..its a dependency property on the view
    and this is all i need on the viewmodel
    ContentControlBag = new ContentControlBag(Activator.CreateInstance(_view), _viewmodel);
    _viewmodel is an instance created by the typeFactory
    and _view is the type of the view
    venom_aa
    @venomAA
    ups..contenedorVistas is the ContentPresenter :P
    venom_aa
    @venomAA
    @advapiIT looks like the GC.Collect isnt doing its job of forcing the unloading of the vm correctly all the time
    so i have to manually close the last vm shown on the ContentPresenter in the MainViewModel. Hope the code gives you a hint to make your own :)
    venom_aa
    @venomAA
    @advapiIT forget about what i said about the bug.. the above code works perfectly fine and the automatic close on the unload its working perfectly
    advapiIT
    @advapiIT
    Excuse me , does Orchestra implement a close service that asks before closing or have I to implmeent on my own?
    Geert van Horrik
    @GeertvanHorrik
    hwe do have one, but not sure whether it's in orchestra or our private libs
    I'm afraid it's internal
    advapiIT
    @advapiIT
    ok..
    no problem,thanks
    I think I have to modify the ShellService in order to intercept it
    Geert van Horrik
    @GeertvanHorrik
    just search for the vm of the main window
    then subscirbe to the close event, I think you can intercept it
    advapiIT
    @advapiIT
    I've some reminiscence of such a discussion with you almost 2 years ago
    I try, thanks
    advapiIT
    @advapiIT
    just to know, since I've checek but MainView is just an usercontrol, is a simple way I can treieve the shellview view from IApplicationStartupService, so I can attach a behavior
    Geert van Horrik
    @GeertvanHorrik
    MainView is, but it's parent is a window ;-)
    that's because the window depends on the shell implementation (mahapps / fluent.ribbon / whatever)
    advapiIT
    @advapiIT
    uhm
    true
    thx for the hint
    Geert van Horrik
    @GeertvanHorrik
    I thikn Orchestra even has a GetParentWindow extension method
    advapiIT
    @advapiIT
    super!
    Geert van Horrik
    @GeertvanHorrik
    you are lucky
    CloseApplicationWatcherBase
    just implement a watcher deriving from that one
    and register it in the servicelocator with RegisterAndInstantiate<MyWatcher>()
    you should ask your company to sponsor us ;-)
    advapiIT
    @advapiIT
    yup I'll do
    Geert van Horrik
    @GeertvanHorrik
    on open collective you'll even get an invoice
    advapiIT
    @advapiIT
    let me finish it and I'll contribute
    I promise
    Geert van Horrik
    @GeertvanHorrik
    that's the point, it should not be you, it should be your company / manager / whatever
    anyway, this watcher is very nice
    you can handle it there
    so in our internal libs, we have created a watcher that intercepts that closing, and exposes that via a service, so we can prevent closing from basically everywhere
    advapiIT
    @advapiIT
    TypeNotRegisteredException: The specified type 'Orchestra.CloseApplicationWatcherBase, Orchestra.Core, Version=5.2.6.0, Culture=neutral, PublicKeyToken=null' is not registered or could not be constructed. Please register type before using it. The type 'Orchestra.CloseApplicationWatcherBase, Orchestra.Core, Version=5.2.6.0, Culture=neutral, PublicKeyToken=null' is not registered
    Geert van Horrik
    @GeertvanHorrik
    public abstract class CloseApplicationWatcherBase
    but.....