Defining a View for a third party viewmodel

Dec 29, 2011 at 7:15 PM

Hello,

I'm using the Caliburn.Micro.Contrib from Kevin Mees, I wish to redefine the view that's bound to DialogView / DialogView<T> ... as far I've understood I need to tell the ViewLocator to use the view I've defined... the problem is how?

Thanks in advance

Jan 3, 2012 at 10:12 PM

What do you mean by "redefine"?

Jan 4, 2012 at 12:53 PM

he has included a template for his dialogviewmodel, how can i tell the viewlocator to assign my own iw for his viewmodel [defined in an assembly]?

thanks

Jan 4, 2012 at 12:57 PM

You can do one of the following:

  • customize the ViewLocator creating a proper rule
  • Modify the ViewLocator.LocateViewForModelType function to check for the specific view-model, and return your view type if needed or use default implementation if not

For the first option, refer to the docs.

Jan 4, 2012 at 1:02 PM

i've searched but in which point should I tell the viewlocator to locate the view?

Jan 4, 2012 at 1:16 PM

If you haven't done it already, have a look at the docs:

http://caliburnmicro.codeplex.com/wikipage?title=View%2fViewModel%20Naming%20Conventions&referringTitle=Documentation

http://caliburnmicro.codeplex.com/wikipage?title=Using%20the%20NameTransformer&referringTitle=Documentation

Tipically, you should add your custom rule or re-define the locate function before the first view/view-model has to be located. Tipically, such customizations should happen either in the Bootstrapper constructor or (if possible) overriding the Configure method in the Bootstrapper.

Jan 4, 2012 at 2:54 PM
Edited Jan 4, 2012 at 2:57 PM
advapi wrote:

he has included a template for his dialogviewmodel, how can i tell the viewlocator to assign my own iw for his viewmodel [defined in an assembly]?

thanks


You can call methods on the ViewLocator directly. If you're calling it from the ViewModel's code:

//This gets you the type of the View
var viewtype = ViewLocator.LocateTypeForModelType(this.GetType());
//This gets you an instance of the View
var viewinstance = ViewLocator.LocateForModel(this);

 If you only know the type of the ViewModel (e.g. MyViewModel):

//This gets you the type of the View
var viewtype = ViewLocator.LocateTypeForModelType(typeof(MyViewModel));
//This gets you an instance of the View
var viewinstance = ViewLocator.LocateForModelType(typeof(MyViewModel));

The ViewLocator automatically supports a standard type and a standard namespace naming covention. You shouldn't need to add a new type mappings unless you have some strange convention. Can you give us the fully-qualified type names of your ViewModel and View?

Jan 4, 2012 at 3:25 PM

cb55555, he said that he already has a view in-place, so if I understand him correctly, he needs to override somehow the default behaviour of the view locator, injecting a custom view over an existing VM.

Jan 4, 2012 at 5:08 PM

I checked out the source code for CMContrib, and it appears to just use the WindowManager class which uses ViewLocator.

You just need to map the namespace for the dialog's ViewModel with your own namespace for the dialog's View.

You can do this by adding this code to the bootstrapper:

ViewLocator.AddNamespaceMapping("Caliburn.Micro.Contrib.Dialogs", "MyProject.MyNamespace");
Jan 9, 2012 at 5:05 PM

I'm also still having issues getting this to work with the latest 1.3 source (including your last update this weekend).

Maybe I'm just dense after a long couple of days trying to get endless little things in place but I could use more details here or clarification on exactly what to do.  There are two scenarios using the CM.Contrib library - calling the default dialogs or opening a custom one with my own viewModel.

I'm making a direct call to the built in Information Dialog which should end up showing the Caliburn.Micro.Contrib.DialogViewModel/DialogView combo. 

I'm making this call from Epm.Silverlight.MyEpm.MyEpmViewModel:

    var informationDone = new Information("SomeText", Answer.Ok);
    yield return informationDone.AsResult();

With CM1.2 out of the box (no rules added etc.) I get a CM Debug message output:

View not found. Searched: Caliburn.Micro.Contrib.Dialogs.DialogView

If I switch to the latest 1.3 source (with/without your AddNamespaceMapping above) I get an exception thrown from INPC.cs

Method not found: 'Void Caliburn.Micro.IWindowManager.ShowDialog(System.Object, System.Object)'.  It is happening when the CM.Contrib tries to pull the WindowManager out of the IOC:

   CM.Contrib.DialogResult.cs (line 26)

       Micro.Execute.OnUIThread(() => IoC.Get<IWindowManager>().ShowDialog(vm));

I'm not sure if I was getting that error or not before your weekend update and my AddNamespaceMapping was:

ViewLocator.AddNamespaceMapping("Caliburn.Micro.Contrib.Dialogs", "Epm.Silverlight");

So there are two scenario that I need to get to work:

Call the defautl dialog (show a VM/View from Caliburn.Micro.Contrib.Dialogs) and show a local VM/View from my own library but passed into the CM.Contrib.DialogResult<> method calls.

My guess is that this is something quite simple when you know all the intimate details but I'm not even sure where to start.

Thanks

jack

 

 

Jan 9, 2012 at 5:26 PM

Wait a minute. I thought you wanted to use a custom View resolved from the built-in Caliburn.Micro.Contrib.DialogViewModel. If that's not the case, then you shouldn't add the namespace mapping that I suggested earlier.

Can you give me an example of what you want, using this notation?

  • Caliburn.Micro.Contrib.Dialogs.DialogViewModel -> Caliburn.Micro.Contrib.Dialogs.DialogView
  • Epm.Silverlight.MyDialogViewModel -> ???

 

 

Jan 9, 2012 at 7:33 PM

My first attempt was to try and use the pre-existing ViewModel/View combination which is your first scenario below:

My second attempt, which I haven’t got to yet, was to use a custom viewModel.

Upon further review I thought that I would be able to call CM.Contrib.DialogViewModel(myViewModel) or something along those lines. I realize know that I have to create my own IDialogViewModel<TResponse> which is what I believe the original author of this discussion was doing.

Caliburn.Micro.Contrib.DialogsIDialogResult Epm.Silverlight.SomeProject.MyDialogViewModel -> Epm.Silverlight.SomeProject.MyDialogView

Is it possible to handle both scenarios?

Thanks

jack

From: cb55555 [email removed]
Sent: Monday, January 09, 2012 11:27 AM
To: Jack Addington
Subject: Re: Defining a View for a third party viewmodel [caliburnmicro:284507]

From: cb55555

Wait a minute. I thought you wanted to use a custom View resolved from the built-in Caliburn.Micro.Contrib.DialogViewModel. If that's not the case, then you shouldn't add the namespace mapping that I suggested earlier.

Can you give me an example of what you want, using this notation?

  • Caliburn.Micro.Contrib.Dialogs.DialogViewModel -> Caliburn.Micro.Contrib.Dialogs.DialogView
  • Epm.Silverlight.MyDialogViewModel -> ???

Jan 9, 2012 at 7:53 PM
Edited Jan 9, 2012 at 8:01 PM

Yes, you can handle both scenarios. In both cases, the ViewModel and the corresponding View are located in the same namespace, so you shouldn't even have to add any custom namespace mappings.

However, you will need to register that external assembly with AssemblySource.

Jan 9, 2012 at 8:08 PM

Which is unfortunately exactly where I am at now…

The Execute.OnUIThread(() => IoC.Get<IWindowManager>().ShowDialog(vm)); throws an exception (when called from CM.Contrib…)

>>>>>>

If I switch to the latest 1.3 source (with/without your AddNamespaceMapping above) I get an exception thrown from INPC.cs

Method not found: 'Void Caliburn.Micro.IWindowManager.ShowDialog(System.Object, System.Object)'. It is happening when the CM.Contrib tries to pull the WindowManager out of the IOC:

CM.Contrib.DialogResult.cs (line 26)

Micro.Execute.OnUIThread(() => IoC.Get<IWindowManager>().ShowDialog(vm));

>>>>>>

From: cb55555 [email removed]
Sent: Monday, January 09, 2012 1:53 PM
To: Jack Addington
Subject: Re: Defining a View for a third party viewmodel [caliburnmicro:284507]

From: cb55555

Yes, you can handle both scenarios. In both cases, the ViewModel and the corresponding View are located in the same namespace, so you shouldn't even have to add any custom namespace mappings.

Jan 9, 2012 at 8:13 PM

This is even after creating your own IDialogViewModel<T>?

Jan 9, 2012 at 8:45 PM

No I haven’t tried that yet. I’m just trying to get the basic case working.

From: cb55555 [email removed]
Sent: Monday, January 09, 2012 2:14 PM
To: Jack Addington
Subject: Re: Defining a View for a third party viewmodel [caliburnmicro:284507]

From: cb55555

This is even after creating your own IDialogViewModel<T>?

Jan 9, 2012 at 9:38 PM
Edited Jan 9, 2012 at 9:39 PM

I downloaded the CMContrib source, changed all the references to the CM1.2 Nuget package to my local CM projects in the CMContrib sample projects, and they both (SL and WPF sample projects) to run fine for me. Were you able to at least get the sample projects to run with 1.3?

Jan 9, 2012 at 9:44 PM

I swapped out the CM reference to the compiled 1.3SL5 dll, rebuilt just fine, and I get the following error:

The invocation of the constructor on type 'Caliburn.Micro.Contrib.Demo.AppBootstrapper' that matches the specified binding constraints threw an exception. [Line: 8 Position: 50]

From: cb55555 [email removed]
Sent: Monday, January 09, 2012 3:39 PM
To: Jack Addington
Subject: Re: Defining a View for a third party viewmodel [caliburnmicro:284507]

From: cb55555

I downloaded the CMContrib source, changed all the references to the CM1.2 Nuget package to my local CM projects in the CMContrib sample projects, and they both (SL and WPF sample projects) to run fine for me. Were you able to at least get the sample projects to run?

Jan 9, 2012 at 9:55 PM

You never mentioned this was an SL5 project.

Jan 9, 2012 at 9:55 PM

I did convert the CM.Contrib to SL5… not sure if that would make a difference though.

From: cb55555 [email removed]
Sent: Monday, January 09, 2012 3:39 PM
To: Jack Addington
Subject: Re: Defining a View for a third party viewmodel [caliburnmicro:284507]

From: cb55555

I downloaded the CMContrib source, changed all the references to the CM1.2 Nuget package to my local CM projects in the CMContrib sample projects, and they both (SL and WPF sample projects) to run fine for me. Were you able to at least get the sample projects to run?

Jan 9, 2012 at 10:02 PM

Sorry, I must have just assumed since we were having a somewhat related conversation in the other thread(s) where I did mention SL5.

From: cb55555 [email removed]
Sent: Monday, January 09, 2012 3:55 PM
To: Jack Addington
Subject: Re: Defining a View for a third party viewmodel [caliburnmicro:284507]

From: cb55555

You never mentioned this was an SL5 project.

Jan 9, 2012 at 10:34 PM

I converted the demo SL project to SL5 and converted CMContrib.SL to SL5, and the demo works fine (after removing an unknown reference to a NumericUpDown control, that is).

Are you sure that you registered the Caliburn.Micro.Contrib assembly in the AssemblySource?

Jan 10, 2012 at 3:27 PM

I got the demo working properly – I had to replace all the references and the bin/obj folders and restart VS a couple of times.

From my application side it no longer blows up but I do still get an issue trying to resolve the view:

View not found. Searched: Caliburn.Micro.Contrib.Dialogs.DialogView, Caliburn.Micro.Contrib.Dialogs.DialogView.

I know you said it would not matter but if I put your line in ViewLocator.AddNamespaceMapping("Caliburn.Micro.Contrib.Dialogs", "Epm.Silverlight");

Then I get:

View not found. Searched: Epm.Silverlight.DialogView, Caliburn.Micro.Contrib.Dialogs.DialogView, Caliburn.Micro.Contrib.Dialogs.DialogView.

From: cb55555 [email removed]
Sent: Monday, January 09, 2012 4:35 PM
To: Jack Addington
Subject: Re: Defining a View for a third party viewmodel [caliburnmicro:284507]

From: cb55555

I converted the demo SL project to SL5 and converted CMContrib.SL to SL5, and the demo works fine (after removing an unknown reference to a NumericUpDown control, that is).

Are you sure that you registered the Caliburn.Micro.Contrib assembly in the AssemblySource?

Jan 10, 2012 at 4:00 PM

You would only add that mapping if you wanted to override the default View for the dialog with your own custom while still using the default ViewModel. If you wanted to use your own custom View AND custom ViewModel, you won't need to add any type mapping as long as you use the standard type and namespace naming convention.

Jan 10, 2012 at 4:37 PM

Okay – and how do I debug the basic case which was the first debug output message and no custom mapping added?

View not found. Searched: Caliburn.Micro.Contrib.Dialogs.DialogView, Caliburn.Micro.Contrib.Dialogs.DialogView.

From: cb55555 [email removed]
Sent: Tuesday, January 10, 2012 10:00 AM
To: Jack Addington
Subject: Re: Defining a View for a third party viewmodel [caliburnmicro:284507]

From: cb55555

You would only add that mapping if you wanted to override the default View for the dialog with your own custom while still using the default ViewModel. If you wanted to use your own custom View AND custom ViewModel, you won't need to add any type mapping as long as you use the standard type and namespace naming convention.

Jan 10, 2012 at 5:37 PM

Again, did you register the Caliburn.Micro.Contrib assembly in the AssemblySource?

Jan 12, 2012 at 4:45 PM

I tried doing the stardard override of SelectAssemblies I've seen in the forums and all it told me was that it was already in place. 

Jan 13, 2012 at 12:44 AM
Edited Jan 13, 2012 at 12:46 AM
jaddington wrote:

I tried doing the stardard override of SelectAssemblies I've seen in the forums and all it told me was that it was already in place. 


So you didn't register Caliburn.Micro.Contrib then. Look at the override code for CMContrib.SL.Demo and compare to what you have in your project.

You should have something like this:

protected override IEnumerable<Assembly> SelectAssemblies()
{
    return base.SelectAssemblies().Concat(new Assembly[] { typeof(ResultExtensions).Assembly });
}
Jan 17, 2012 at 6:20 AM

excuse me... is there a reason why I don't have AddNamespaceMapping in ViewLocator on WPF?

Thanks

Jan 17, 2012 at 2:11 PM

Did you download the latest source?

Jan 17, 2012 at 2:13 PM

I think I got some problem getting it via nuGet.... In the official 1.2 it's not present am I right?

Jan 17, 2012 at 3:45 PM
Edited Jan 17, 2012 at 3:45 PM

Yes, you are correct. It's not in the official v1.2 release.

Jan 17, 2012 at 3:49 PM

That did the trick. Thanks

From: cb55555 [email removed]
Sent: Thursday, January 12, 2012 6:45 PM
To: Jack Addington
Subject: Re: Defining a View for a third party viewmodel [caliburnmicro:284507]

From: cb55555

jaddington wrote:

I tried doing the stardard override of SelectAssemblies I've seen in the forums and all it told me was that it was already in place.


So you didn't register Caliburn.Micro.Contrib then. Look at the override code for CMContrib.SL.Demo and compare to what you have in your project.

Jan 17, 2012 at 3:49 PM

So I download the lastest and build it, anything else particular?

Jan 17, 2012 at 4:15 PM

It depends on what you want to do. Did you want to add a custom dialog (i.e. your own ViewModel/View pair) or just override the existing View while using the built-in ViewModel?

Jan 17, 2012 at 4:27 PM

Hello cb55555,

I've updated to 1.3 but I got an error on valeriu caraulean's Telerik conventions... it says :

 

public static class TelerikConventions

   {

       public static void Install()

       {

           ConventionManager.AddElementConvention<RadTabControl>(RadTabControl.ItemsSourceProperty,

           "ItemsSource",

           "SelectionChanged")

           .ApplyBinding = (viewModelType, path, property, element, convention) =>

           {

               if (!ConventionManager.SetBinding(viewModelType, path, property, element, convention)) //here Error     Delegate 'Action' does not take 5 arguments 

                   return false;

 

               var tabControl = (RadTabControl)element;

               if (tabControl.ContentTemplate == null

               && tabControl.ContentTemplateSelector == null

               && property.PropertyType.IsGenericType)

               {

                   var itemType = property.PropertyType.GetGenericArguments().First();

                   if (!itemType.IsValueType && !typeof(string).IsAssignableFrom(itemType))

                       tabControl.ContentTemplate = ConventionManager.DefaultItemTemplate;

               }

               ConventionManager.ConfigureSelectedItem(element,

               RadTabControl.SelectedItemProperty,

               viewModelType,

               path);

 

               if (string.IsNullOrEmpty(tabControl.DisplayMemberPath))

                   ConventionManager.ApplyHeaderTemplate(tabControl, //here Error    19    No overload for method 'ApplyHeaderTemplate' takes 3 arguments

                   RadTabControl.ItemTemplateProperty,

                   viewModelType);

               return true;

           };

 

           ConventionManager.AddElementConvention<RadMenuItem>(RadMenuItem.ItemsSourceProperty, "DataContext", "Click");

           ConventionManager.AddElementConvention<RadBusyIndicator>(RadBusyIndicator.IsBusyProperty, "IsBusy", "Loaded");

           ConventionManager.AddElementConvention<RadMaskedTextBox>(RadMaskedTextBox.MaskedTextProperty, "MaskedText",

           "ValueChanged");

           ConventionManager.AddElementConvention<RadMaskedTextInput>(RadMaskedTextInput.ValueProperty, "Value", "ValueChanged");

 

           // Works also for RadTimePicker, RadDatePicker

           ConventionManager.AddElementConvention<RadDateTimePicker>(RadDateTimePicker.SelectedValueProperty, "SelectedValue",

           "SelectionChanged");

 

           ConventionManager.AddElementConvention<RadGridView>(DataControl.ItemsSourceProperty, "SelectedItem", "SelectionChanged")

           .ApplyBinding = (viewModelType, path, property, element, convention) =>

           {

               if (!ConventionManager.SetBinding(viewModelType, path, property, element, convention)) return false; //here Error     Delegate 'Action' does not take 5 arguments

               if (ConventionManager.HasBinding(element, DataControl.SelectedItemProperty)) return true;

               var index = path.LastIndexOf('.');

               index = index == -1 ? 0 : index + 1;

               var baseName = path.Substring(index);

               foreach (var selectionPath in

               from potentialName in ConventionManager.DerivePotentialSelectionNames(baseName)

               where viewModelType.GetProperty(potentialName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) != null

               select path.Replace(baseName, potentialName))

               {

                   var binding = new Binding(selectionPath) { Mode = BindingMode.TwoWay };

                   BindingOperations.SetBinding(element, DataControl.SelectedItemProperty, binding);

               }

               return true;

           };

       }

   }
what should I pass for them?
Thanks
Jan 17, 2012 at 4:54 PM

Try passing nulls to the new arguments that were added since v1.2.

Jan 17, 2012 at 5:09 PM
Edited Jan 17, 2012 at 5:10 PM

BTW, the original code for ConventionManager.SetBinding() method derived the 5th argument internally as:

convention.GetBindableProperty(element);

You just need to call that method before passing it to ConventionManager.SetBinding().

Also, ConventionManager.SetBinding() is now an Action<T> instead of Func<T>, so it does not return a value.

Coordinator
Jan 17, 2012 at 5:13 PM

Sorry about those breaking changes! We had some bugs in conventions and we literally had to make the API changes to fix them. After the release of v1.3 we are going to move to a more semantic versioning strategy, so you should be able to tell more readily from the version number whether there are breaking changes or not. Thanks for hanging in there.

Jan 17, 2012 at 5:37 PM

hello, cb55555 you mean 6th element? @EisembergEffect if you say so to me, that's cool! thanks!

Jan 17, 2012 at 5:57 PM

Sorry, I meant 6th argument.

Jan 18, 2012 at 7:27 AM

Hello,

it seems to work... for the other error I passed null, is it ok?

 

if (string.IsNullOrEmpty(tabControl.DisplayMemberPath))

    ConventionManager.ApplyHeaderTemplate(tabControl,

    RadTabControl.ItemTemplateProperty,

    null, //<-new param

    viewModelType);

 

for what concern the

 

ViewLocator.AddNamespaceMapping("Caliburn.Micro.Contrib.Dialogs", "myProject.Modules.Core.View")

it won't show me the display message...

 

my view is defined as

 

<Window  x:Class="myProject.Modules.Core.Views.DialogView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Contrib="clr-namespace:Caliburn.Micro.Contrib;assembly=Caliburn.Micro.Contrib"
        xmlns:Converter="clr-namespace:Caliburn.Micro.Contrib.Converter;assembly=Caliburn.Micro.Contrib"
        xmlns:Micro="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
        xmlns:Dialogs="clr-namespace:Caliburn.Micro.Contrib.Dialogs;assembly=Caliburn.Micro.Contrib"
        Title="{Binding Dialog.Subject}"
        Width="450"
        MaxWidth="450"
        MaxHeight="500"
        Contrib:DialogCloser.DialogResult="{Binding IsClosed}"
        ResizeMode="NoResize"
        SizeToContent="WidthAndHeight"
        WindowStartupLocation="CenterOwner"
        WindowStyle="ToolWindow">
    <Window.Resources>
        <Converter:DialogTypeToSystemIconConverter x:Key="IconConverter" />
        <Converter:EnumLocalizer x:Key="EnumLocalizer" />
        <DataTemplate DataType="{x:Type Dialogs:Answer}">
            <ContentControl Content="{Binding ., Converter={StaticResource EnumLocalizer}}" />
        </DataTemplate>
    </Window.Resources>
    <Window.Icon>
        <Binding Path="Dialog.DialogType">
            <Binding.Converter>
                <Converter:DialogTypeToSystemIconConverter />
            </Binding.Converter>
        </Binding>
    </Window.Icon>
    <DockPanel Focusable="False" LastChildFill="True">
        <ItemsControl x:Name="Responses"
                      Margin="5"
                      HorizontalAlignment="Center"
                      DockPanel.Dock="Bottom">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Height="25"
                            MinWidth="75"
                            Margin="5 0"
                            Content="{Binding Response}"
                            Focusable="True"
                            IsCancel="{Binding IsCancel}"
                            IsDefault="{Binding IsDefault}"
                            Micro:Message.Attach="Respond($dataContext)" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

        <Image Width="20"
               Margin="10"
               VerticalAlignment="Center"
               DockPanel.Dock="Left"
               Focusable="False"
               Source="{Binding Dialog.DialogType,
Converter={StaticResource IconConverter}}" />

        <Border Width="1" Margin="0 5" Background="Gray" DockPanel.Dock="Left"/>

        <TextBlock Margin="10"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Focusable="False"
                   Text="{Binding Dialog.Message}"
                   TextWrapping="Wrap" />
    </DockPanel>
</Window>

and the cs is

 

namespace myProject.Modules.Core.Views
{
    public partial class DialogView : Window
    {
        public DialogView()
        {
            InitializeComponent();

            Activated += (sender, args) =>
            {
                DependencyObject child = Responses;
                while (child != null)
                {
                    child = VisualTreeHelper.GetChild(child, 0);
                    if (child is Button)
                    {
                        (child as Button).Focus();
                        break;
                    }
                }
            };
        }
    }
}

 

but when I try to show the dialog, nothing happens...what am I missing?

Thanks

Jan 18, 2012 at 2:32 PM

Your View's type is:  myProject.Modules.Core.Views.DialogView

Your namespace mapping is:  ViewLocator.AddNamespaceMapping("Caliburn.Micro.Contrib.Dialogs", "myProject.Modules.Core.View")

Do you see the problem there?

Jan 18, 2012 at 4:26 PM

Hello cb55555,

even with this :

   ViewLocator.AddNamespaceMapping("Caliburn.Micro.Contrib.Dialogs", "myProject.Modules.Core.Views");

it doesn't work... no screen ...

 

is the SelectAssemblies() correct?

 

   protected override IEnumerable<Assembly> SelectAssemblies()
        {
            return base.SelectAssemblies();
          //  return base.SelectAssemblies().Concat(new Assembly[] { typeof(Caliburn.Micro.Contrib.ResultExtensions).Assembly });
        }

Thanks

 

Jan 18, 2012 at 5:26 PM
Edited Jan 18, 2012 at 5:50 PM

 Your code is fine only if there are no other Views from the Contrib assembly that you'll be invoking. Otherwise, the code that you commented out was correct.

Have you stepped through the code to see what ViewLocator.TransformName() is returning?

Nov 7, 2013 at 1:54 AM
Edited Nov 7, 2013 at 1:54 AM
When i run CM.Contrib (ver 1.0.1) on CM v 1.5.2, I faced the same issue:
The Execute.OnUIThread(() => IoC.Get<IWindowManager>().ShowDialog(vm)); throws an exception (when called from CM.Contrib…)
Error Message: A first chance exception of type 'System.MissingMethodException' occurred in Caliburn.Micro.dll

The exception happens in SequentialResult.cs - after next.Execute(context) - Line 59
if(moveNextSucceeded) {
                try {
                    var next = enumerator.Current;
                    IoC.BuildUp(next);
                    next.Completed += ChildCompleted;
                    next.Execute(context);
                }
                catch(Exception ex) {
                    OnComplete(ex, false);
                    return;
                }
            }
Stack Trace:

Message: "Method not found: '!!0 Caliburn.Micro.IoC.Get()'."

StackTrace " at Caliburn.Micro.Contrib.Results.DialogResult1.<>c__DisplayClass5.<Execute>b__3()\r\n at Caliburn.Micro.Execute.OnUIThread(Action action) in c:\\Users\\Rob\\Documents\\CodePlex\\caliburnmicro\\src\\Caliburn.Micro.Silverlight\\INPC.cs:line 156\r\n at Caliburn.Micro.Contrib.Results.DialogResult1.Execute(ActionExecutionContext context) in D:\dev\dotNET\projects\CMContrib\src\CMContrib.SL\Results\DialogResult.cs:line 44\r\n at Caliburn.Micro.SequentialResult.ChildCompleted(Object sender, ResultCompletionEventArgs args) in c:\Users\Rob\Documents\CodePlex\caliburnmicro\src\Caliburn.Micro.Silverlight\SequentialResult.cs:line 59"

I have included this line the bootstrapper:
        protected override IEnumerable<Assembly> SelectAssemblies()
        {
            return base.SelectAssemblies().Concat(new Assembly[] { typeof(ResultExtensions).Assembly });
        }
I hope there is a quick fix for this.
Nov 7, 2013 at 4:59 AM
CM.Contrib is not compatible with the current Caliburn.Micro version.
Please post CM.Contrib issues to https://github.com/kmees/CMContrib/