0

I'm using CaliburnMicro in my WPF application, which uses an ExplorerBrowser control from WindowsAPICodePack (Microsoft-WindowsAPICodePack-Shell and Microsoft-WindowsAPICodePack-Core).

The events like SelectionChanged attached to this control are not firing in the viewmodel.

I've tried it multiple ways with Caliburn's [Event] = [Action()], or making a simpler "WinForms" style event to the backing class of the view - none of these worked.

Caliburn events are working fine for any other controls in the view. So if I place an event on the parent Grid - it works.

The only way I found it does work, is accessing the control itself by name from code-behind, which isn't how I want do things.

I'm also not entirely clear on the syntax for the Caliburn event in this case, because it's accessible through Selector - [Event Selector.SelectionChanged].

I also tried catching it with different arg types and other events with same result.

Here's the View:

<UserControl x:Class="App.WinExplorer.WinExplorerView"
      xmlns:WindowsAPICodePackPresentation="clr-namespace:Microsoft.WindowsAPICodePack.Controls.WindowsPresentationFoundation;assembly=Microsoft.WindowsAPICodePack.Shell"
      xmlns:cal="http://www.caliburnproject.org"
...
    <Grid>
        <WindowsAPICodePackPresentation:ExplorerBrowser 
            x:Name="ExplorerBrowser"
            NavigationTarget="{Binding NavigationTarget}"
            cal:Message.Attach="[Event Selector.SelectionChanged] = [Action SelectionChanged($this, $eventArgs)]"
            />
    </Grid>
</UserControl>

Here's the handler in the viewmodel:

public void SelectionChanged(object s, SelectionChangedEventArgs e)
{
     // never hits this method
}

Tried declaring the event the reular WPF way too:

Selector.SelectionChanged="ExplorerBrowser_SelectionChanged"

What actually works but is a backwards way of doing it - inside the code-behind:

    public partial class WinExplorerView : UserControl
    {
        public WinExplorerView()
        {
            InitializeComponent();
            ExplorerBrowser.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;
        }

        private void SelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            throw new System.NotImplementedException();
        }
    }

Any insight would be appreciated.

Teacan
  • 49
  • 6
  • The `ExplorerBrowser` class doesn't define or raise any `SelectionChanged` changed event so why would this ever work? – mm8 Jul 04 '19 at 11:52
  • According to [this](https://github.com/aybe/Windows-API-Code-Pack-1.1/blob/master/source/WindowsAPICodePack/Shell/ExplorerBrowser/ExplorerBrowser.cs) it does have a SelectionChanged event. In the view however, as I said, it can be accessed through selector only : `Selector.SelectionChanged="ExplorerBrowser_SelectionChanged"` – Teacan Jul 04 '19 at 12:09
  • You have linked to a Windows Forms control. but you are using a WPF control. – mm8 Jul 04 '19 at 12:11
  • You're right, my bad. I checked the WPF class and I don't see any events there **at all**.. The only viable option seems to be `ObservableCollection SelectedItems`. But this is a property of ExplorerBrowser itself and my viewmodel doesn't know about it. I tried adding it to the VM, but then I'm not sure how to create a binding to it in the view - `SelectedItems` of this control isn't directly accessible through XAML. – Teacan Jul 04 '19 at 12:52
  • You may wrap the control, hook up an event handler to `SelectedItems.CollectionChanged` and then raise a custom event yourself. – mm8 Jul 04 '19 at 12:55

0 Answers0