0

I'm trying to get CefSharp to play nicely with Caliburn.Micro, but that wasn't as easy as I'd hoped. It's probably still easy but I'm just not familiar enough with either of them.

I added a browser component to my view:

<cefsharp:ChromiumWebBrowser x:Name="Browser"></cefsharp:ChromiumWebBrowser>

Then I added a property in my view model with the same name:

public ChromiumWebBrowser Browser { get; set; }

I had now hoped that Caliburn.Micro's magic had bound this property to the actual browser in the view so that I could use Browser from my code-behind.

To test this I try to go to a specific webpage when the view is activated:

protected override void OnActivate()
{
    Browser.Dispatcher.Invoke(() =>
    {
        Browser.Address = "http://stackoverflow.com";
        NotifyOfPropertyChange(() => Browser);
    });
    base.OnActivate();
}

Because Browser is owned by a different thread I'm using the Dispatcher to be able to access it properly.

All this code runs just fine without any exceptions but SO is not opened when the browser loads.

I'm guessing this is because I haven't been able to get Caliburn.Micro to properly bind the two ChromiumWebBrowser objects together.

How can I accomplish this?

TheHvidsten
  • 4,028
  • 3
  • 29
  • 62

1 Answers1

0

you have to add custom Convention to bind to that control based on the x:Name. there is no way around that since it's a 3rd party control, otherwise you will have to use properties.. The only controls that have conventions out of the box are those included in the wpf/silver/windows phone framework(s) for .NET. If memory serves me there are some other steps required for that particular control to initialize it as well.

http://caliburnmicro.com/documentation/conventions

examples of custom conventions for Telerik's UI for Windows Phone

ConventionManager.AddElementConvention<RadDataBoundListBox>(DataControlBase.ItemsSourceProperty, "ItemsSource", "SelectionChanged");
ConventionManager.AddElementConvention<RadDockPanel>(RadDockPanel.DockProperty, "Dock", "DockChanged");
ConventionManager.AddElementConvention<RadListPicker>(ItemsControl.ItemsSourceProperty, "ItemsSource", "SelectionChanged");
ConventionManager.AddElementConvention<RadDatePicker>(DateTimePicker.ValueProperty, "Value", "ValueChanged");
ConventionManager.AddElementConvention<RadTimePicker>(DateTimePicker.ValueProperty, "Value", "ValueChanged");
ConventionManager.AddElementConvention<RadToggleSwitch>(RadToggleSwitch.IsCheckedProperty, "IsChecked", "CheckChanged");
ConventionManager.AddElementConvention<RadContextMenuItem>(RadContextMenuItem.CommandProperty, "Command", "Tap");
ConventionManager.AddElementConvention<RadHubTile>(HubTileBase.CommandProperty, "Command", "Tap");

these are very basic but get them working accordingly.

ConventionManager.AddElementConvention<Pivot>(ItemsControl.ItemsSourceProperty, "SelectedItem", "SelectionChanged").ApplyBinding =
            (viewModelType, path, property, element, convention) =>
            {
                if (ConventionManager
                    .GetElementConvention(typeof(ItemsControl))
                    .ApplyBinding(viewModelType, path, property, element, convention))
                {

                    ConventionManager
                        .ConfigureSelectedItem(element, Pivot.SelectedItemProperty, viewModelType, path);
                    ConventionManager
                        .ApplyHeaderTemplate(element, Pivot.HeaderTemplateProperty, null, viewModelType);

                    return true;
                }
                return false;
            };

more advanced convention related to the SelectedItem of a ItemsControl...

As you can see its entirely dependent on the control itself and the available DependencyProperties exposed to use.

mvermef
  • 3,814
  • 1
  • 23
  • 36