Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Geert van Horrik
    @GeertvanHorrik
    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.....
    advapiIT
    @advapiIT
    Ah I've to derive from it
    Geert van Horrik
    @GeertvanHorrik
        public class ApplicationClosingService : CloseApplicationWatcherBase, IApplicationClosingService
        {
            public bool IsClosing { get; private set; }
    
            public event AsyncEventHandler<EventArgs> ApplicationClosingAsync;
            public event EventHandler<EventArgs> ApplicationClosingCanceled;
    
            protected override async Task<bool> ClosingAsync()
            {
                IsClosing = true;
    
                await ApplicationClosingAsync.SafeInvokeAsync(this, EventArgs.Empty);
    
                return await base.ClosingAsync();
            }
    
            protected override void ClosingCanceled()
            {
                IsClosing = false;
    
                ApplicationClosingCanceled?.Invoke(this, EventArgs.Empty);
    
                base.ClosingCanceled();
            }
        }
    this is our internal implementation, then you can simply subscribe to IApplicationClosingService::ApplicationClosing and cancel it from there
    advapiIT
    @advapiIT
    excuse me again, but when I subscribe to ApplicationClosing, how can I cancel? the EventArgs
    has no cancel prop
    Geert van Horrik
    @GeertvanHorrik
    hmmm, good question
    you can fix your own, if the eventargs of ApplicationClosingAsync has an e.Cancel
    you could cancel
    since it has a reutnr value
    advapiIT
    @advapiIT
    you're right
    advapiIT
    @advapiIT

    ok, this seems to work
    in mainviewmodel
    ```private async Task ApplicationClosingService_ApplicationClosingAsync(object sender, CancelEventArgs e)
    {
    var response = await messageService.ShowAsync("Sei sicuro di voler chiudere l'applicazione?",
    "Chiusura applicazione", MessageButton.YesNo, MessageImage.Question);
    if (response == MessageResult.No)
    {
    e.Cancel = true;
    }
    }

    in the closeService

    protected override async Task<bool> ClosingAsync()
    {
    IsClosing = true;

            var eventArgs = new CancelEventArgs();
            await ApplicationClosingAsync.SafeInvokeAsync(this, eventArgs);
    
            if (!eventArgs.Cancel)
                return await base.ClosingAsync();
            return false;
        }

    ```

    I want my mom.
    never been able to past code.
      protected override async Task<bool> ClosingAsync()
            {
                IsClosing = true;
    
                var eventArgs = new CancelEventArgs();
                await ApplicationClosingAsync.SafeInvokeAsync(this, eventArgs);
    
                if (!eventArgs.Cancel)
                    return await base.ClosingAsync();
                return false;
            }
    venom_aa
    @venomAA

    I want my mom.

    XD

    i want a beer and a good bbq ..working for this client has been exhausting
    advapiIT
    @advapiIT
    idem for me
    it's 2 AM here
    venom_aa
    @venomAA
    tssss.. thats bad
    but i feel you
    i have working on weekends for about 3 months
    @advapiIT did the code i posted helped you>
    ?