This is a migrated thread and some comments may be shown as answers.

InvalidOperationException when using Caliburn.Micro conductors

5 Answers 228 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
StepTNT
Top achievements
Rank 1
StepTNT asked on 02 Dec 2013, 09:35 PM
I'm moving my first steps into Caliburn.Micro and I'm working with a Pivot control.

I created the conductors and the view models for each pivot page, and everything goes fine until i replace my ListBox with the RadDataBoundListBox.

Here's the exception that I got:

First-chance exception 'System.InvalidOperationException' in System.Windows.ni.dll
Can't convert type Caliburn.Micro.BindableCollection`1[System.String] to type System.Windows.Visibility.


and here's the full stack trace :

System.Windows.ni.dll!MS.Internal.Data.DefaultValueConverter.Create(System.Type sourceType, System.Type targetType, bool targetToSource)    Unknown
System.Windows.ni.dll!MS.Internal.Data.DynamicValueConverter.EnsureConverter(System.Type sourceType = {System.RuntimeType}, System.Type targetType = {System.RuntimeType})    Unknown
System.Windows.ni.dll!MS.Internal.Data.DynamicValueConverter.Convert(object value = Count = 4, System.Type targetType = {System.RuntimeType}, object parameter = null, System.Globalization.CultureInfo culture = {System.Globalization.CultureInfo})    Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.ConvertToTarget(object value = Count = 4)    Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.GetValue(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp)    Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.SetValueInternal(System.Windows.DependencyProperty dp = {System.Windows.CoreDependencyProperty}, object value, bool allowReadOnlySet)    Unknown
System.Windows.ni.dll!System.Windows.Data.BindingOperations.SetBinding(System.Windows.DependencyObject target, System.Windows.DependencyProperty dp, System.Windows.Data.BindingBase binding)    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.ConventionManager..cctor.AnonymousMethod__3(System.Type viewModelType = {System.RuntimeType}, string path = "Items", System.Reflection.PropertyInfo property = {System.Reflection.RuntimePropertyInfo}, System.Windows.FrameworkElement element = {Telerik.Windows.Controls.RadDataBoundListBox}, Caliburn.Micro.ElementConvention convention = {Caliburn.Micro.ElementConvention}, System.Windows.DependencyProperty bindableProperty = {System.Windows.CoreDependencyProperty})    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.ConventionManager.SetBindingWithoutBindingOverwrite(System.Type viewModelType = {System.RuntimeType}, string path = "Items", System.Reflection.PropertyInfo property = {System.Reflection.RuntimePropertyInfo}, System.Windows.FrameworkElement element = {Telerik.Windows.Controls.RadDataBoundListBox}, Caliburn.Micro.ElementConvention convention = {Caliburn.Micro.ElementConvention}, System.Windows.DependencyProperty bindableProperty = {System.Windows.CoreDependencyProperty})    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.ElementConvention..ctor.AnonymousMethod__0(System.Type viewModelType = {System.RuntimeType}, string path = "Items", System.Reflection.PropertyInfo property = {System.Reflection.RuntimePropertyInfo}, System.Windows.FrameworkElement element = {Telerik.Windows.Controls.RadDataBoundListBox}, Caliburn.Micro.ElementConvention convention = {Caliburn.Micro.ElementConvention})    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.ViewModelBinder..cctor.AnonymousMethod__6(System.Collections.Generic.IEnumerable<System.Windows.FrameworkElement> namedElements = Count = 3, System.Type viewModelType = {System.RuntimeType})    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.ViewModelBinder..cctor.AnonymousMethod__9(object viewModel = {MyNamespace.ViewModels.SearchByGenreViewModel}, System.Windows.DependencyObject view = {MyNamespace.Views.SearchByGenreView}, object context = null)    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.View.OnModelChanged(System.Windows.DependencyObject targetLocation = {System.Windows.Controls.ContentControl}, System.Windows.DependencyPropertyChangedEventArgs args = {System.Windows.DependencyPropertyChangedEventArgs})    Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.RaisePropertyChangeNotifications(System.Windows.DependencyProperty dp = {System.Windows.CustomAttachedDependencyProperty}, object oldValue, object newValue)    Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.DependencyProperty property, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, System.Windows.DependencyObject.ValueOperation operation)    Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.RefreshExpression(System.Windows.DependencyProperty dp)    Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.SendDataToTarget()    Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.SourceAcquired()    Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(object sender, System.Windows.DataContextChangedEventArgs e)    Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.DataContextChanged(object sender, System.Windows.DataContextChangedEventArgs e)    Unknown
System.Windows.ni.dll!System.Windows.FrameworkElement.OnDataContextChanged(System.Windows.DataContextChangedEventArgs e)    Unknown
System.Windows.ni.dll!System.Windows.FrameworkElement.OnTreeParentUpdated(System.Windows.DependencyObject newParent, bool bIsNewParentAlive)    Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.UpdateTreeParent(MS.Internal.IManagedPeer oldParent = null, MS.Internal.IManagedPeer newParent = {System.Windows.Controls.ContentPresenter}, bool bIsNewParentAlive, bool keepReferenceToParent = true)    Unknown
System.Windows.ni.dll!MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(System.IntPtr oldParentElement, System.IntPtr parentElement, System.IntPtr childElement, byte bIsParentAlive, byte bKeepReferenceToParent, byte bCanCreateParent)    Unknown
[From native to managed]   
[From managed to native]   
System.Windows.ni.dll!MS.Internal.XcpImports.FrameworkElement_MeasureOverride(System.Windows.FrameworkElement element = {Microsoft.Phone.Controls.PivotItem}, System.Windows.Size availableSize)    Unknown
Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.PivotItem.MeasureOverride(System.Windows.Size availableSize)    Unknown
System.Windows.ni.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, double inWidth, double inHeight, [From native to managed]   
[From managed to native]   
System.Windows.ni.dll!MS.Internal.XcpImports.UIElement_UpdateLayout(System.Windows.UIElement element = {Microsoft.Phone.Controls.Pivot}) Unknown
Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.Pivot.OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)    Unknown
System.Windows.ni.dll!System.Windows.Controls.ItemsControl.OnItemCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)    Unknown
System.Windows.ni.dll!System.Windows.Controls.ItemCollection.NotifyCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)    Unknown
System.Windows.ni.dll!System.Windows.Controls.ItemCollection.System.Windows.Controls.ICollectionChangedListener.OnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)    Unknown
System.Windows.ni.dll!System.Windows.Controls.WeakCollectionChangedListener.SourceCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)    Unknown
System.ni.dll!System.Collections.ObjectModel.ObservableCollection<Caliburn.Micro.IScreen>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.BindableCollection<Caliburn.Micro.IScreen>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs})    Unknown
System.ni.dll!System.Collections.ObjectModel.ObservableCollection<System.__Canon>.InsertItem(int index, System.__Canon item)    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.BindableCollection<Caliburn.Micro.IScreen>.InsertItemBase(int index = 3, Caliburn.Micro.IScreen item = {MyNamespace.ViewModels.SearchByGenreViewModel})    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.BindableCollection<Caliburn.Micro.IScreen>.InsertItem.AnonymousMethod__4()    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.Execute.OnUIThread(System.Action action = {System.Action})    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.BindableCollection<Caliburn.Micro.IScreen>.InsertItem(int index = 3, Caliburn.Micro.IScreen item = {MyNamespace.ViewModels.SearchByGenreViewModel})    Unknown
mscorlib.ni.dll!System.Collections.ObjectModel.Collection<Caliburn.Micro.IScreen>.Add(Caliburn.Micro.IScreen item)    Unknown
MyProjectDLL!MyNamespace.ViewModels.SearchViewModel.OnInitialize() Riga 26    C#
Caliburn.Micro.DLL!Caliburn.Micro.Screen.Caliburn.Micro.IActivate.Activate()    Unknown
Caliburn.Micro.DLL!Caliburn.Micro.FrameAdapter.OnNavigated(object sender = {System.Windows.Navigation.NavigationService}, System.Windows.Navigation.NavigationEventArgs e = {System.Windows.Navigation.NavigationEventArgs})    Unknown
Microsoft.Phone.ni.dll!System.Windows.Navigation.NavigationService.RaiseNavigated(object content = {MyNamespace.Views.SearchView}, System.Uri uri = {System.Uri}, System.Windows.Navigation.NavigationMode mode = New, bool isNavigationInitiator = true, Microsoft.Phone.Controls.IPhoneApplicationPage existingContentPage = {MyNamespace.Views.MainPage}, Microsoft.Phone.Controls.IPhoneApplicationPage newContentPage = {MyNamespace.Views.SearchView})    Unknown
Microsoft.Phone.ni.dll!System.Windows.Navigation.NavigationService.CompleteNavigation(System.Windows.DependencyObject content, System.Windows.Navigation.NavigationMode mode = New)    Unknown
Microsoft.Phone.ni.dll!System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(System.IAsyncResult result)    Unknown
Microsoft.Phone.ni.dll!System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(System.AsyncCallback userCallback = {System.AsyncCallback}, System.Windows.Navigation.PageResourceContentLoader.PageResourceContentLoaderAsyncResult result = {System.Windows.Navigation.PageResourceContentLoader.PageResourceContentLoaderAsyncResult})    Unknown
Microsoft.Phone.ni.dll!System.Windows.Navigation.PageResourceContentLoader.BeginLoad.AnonymousMethod__0(object args)    Unknown
[From native to managed]   
mscorlib.ni.dll!System.Delegate.DynamicInvokeImpl(object[] args)    Unknown
System.Windows.ni.dll!System.Windows.Threading.DispatcherOperation.Invoke()    Unknown
System.Windows.ni.dll!System.Windows.Threading.Dispatcher.Dispatch(System.Windows.Threading.DispatcherPriority priority)    Unknown
System.Windows.ni.dll!System.Windows.Threading.Dispatcher.OnInvoke(object context)    Unknown
System.Windows.ni.dll!System.Windows.Hosting.CallbackCookie.Invoke(object[] args)    Unknown
System.Windows.RuntimeHost.ni.dll!System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(System.IntPtr pHandle, int nParamCount, System.Windows.Hosting.NativeMethods.ScriptParam* pParams, System.Windows.Hosting.NativeMethods.ScriptParam* pResult = 0x0055fab4)    Unknown


Now let's get to the code.

This is the OnInitialize method of the conductor:
protected override void OnInitialize()
{
    base.OnInitialize();                       
    Items.Add(_byGenre);
    ActivateItem(_byGenre);
}
where _byGenre is an instance of:
public class SearchByGenreViewModel : Screen
{
    private ObservableCollection<string> _items;
 
    public ObservableCollection<string> Items
    {
        get { return _items; }
        set
        {
            _items = value;
            NotifyOfPropertyChange(() => Items);
        }
     }
 
    public SearchByGenreViewModel()
    {
        Items = new BindableCollection<string>
        {
            "action",
            "adventure",
            "animation",
            "comedy"
        };
        DisplayName = "by genre";           
    }
}
Finally, here's the XAML (SearchByGenreView.xaml):
(this one is the one that works fine)
<ListBox x:Name="Items">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding}" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
(this is the one who gives the exception)
<telerikPrimitives:RadDataBoundListBox x:Name="Items" Margin="12,3,12,0" Visibility="Visible">
    <telerikPrimitives:RadDataBoundListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding}" />
            </StackPanel>
        </DataTemplate>
    </telerikPrimitives:RadDataBoundListBox.ItemTemplate>
</telerikPrimitives:RadDataBoundListBox>
as you can see, all that I've changed is the ListBox, which I replaced with the RadDataBoundListBox.

What am I doing wrong?

5 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 06 Dec 2013, 08:21 AM
Hi,

There should not be any problem with this approach. Maybe there is something else in your project that cause the problem with the Telerik listbox. We tried your scenario but could not reproduce it. Is it possible for you to isolate a small project where we can investigate what is the reason for the exception.

Thanks!

Regards,
Valentin.Stoychev
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
StepTNT
Top achievements
Rank 1
answered on 11 Dec 2013, 03:31 PM
I'm sorry for the delay.

Here's an stripped down version of my project. This should be enough to reproduce the issue.

https://www.dropbox.com/s/q5dikr5rh8n5dja/Repro%20WML.rar
0
Victor
Telerik team
answered on 16 Dec 2013, 12:38 PM
Hi Stefano,

Thanks for the project. I am afraid that no exception is being thrown on my side. Please have a look at the screenshots. After I press the search button, the new page is empty and nothing happens. If I bind the list box to the Items property of the data context, the list box binds successfully without exceptions.

Am I missing something?

Regards,
Victor
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
StepTNT
Top achievements
Rank 1
answered on 16 Dec 2013, 06:29 PM
Actually, I think that the exception thrown but your IDE is not set to catch it.

If I set mine to continue when the exception occurs, this message is printed on the output:

System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value 'Caliburn.Micro.BindableCollection`1[System.String]' (type 'Caliburn.Micro.BindableCollection`1[System.String]'); BindingExpression: Path='Items' DataItem='WatchMeLater2.ViewModels.SearchByGenreViewModel' (HashCode=9289124); target element is 'Telerik.Windows.Controls.RadDataBoundListBox' (Name='Items'); target property is 'Visibility' (type 'System.Windows.Visibility').. System.InvalidOperationException: Can't convert type Caliburn.Micro.BindableCollection`1[System.String] to type System.Windows.Visibility.
   at MS.Internal.Data.DefaultValueConverter.Create(Type sourceType, Type targetType, Boolean targetToSource)
   at MS.Internal.Data.DynamicValueConverter.EnsureConverter(Type sourceType, Type targetType)
   at MS.Internal.Data.DynamicValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
   at System.Windows.Data.BindingExpression.ConvertToTarget(Object value).

and this causes my list to show as empty, because binding looks fine as the logger also prints
[2013-12-16T19:25:22.9161710+01:00] Binding Convention Applied: Element Items.

I'm starting to think that this is somehow related to xaml and caliburn micro's naming convention because it's weird that it tries to convert a List<string> to a List<Visibility> :\

Can you please upload the files that you changed so that I can try them too?
0
Accepted
Victor
Telerik team
answered on 18 Dec 2013, 03:18 PM
Hi Stefano,

Since RadDataboundListBox inherits from Control and not ItemsControl or Selector, Caliburn Micro does not have any meaningful default conventions set up. You just have to add an element convention in the bootstrapper like this:
ConventionManager.AddElementConvention<RadDataBoundListBox>(
    RadDataBoundListBox.ItemsSourceProperty, "Items", "Loaded");
Please write again if you need further assistance.

Regards,
Victor
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
DataBoundListBox
Asked by
StepTNT
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
StepTNT
Top achievements
Rank 1
Victor
Telerik team
Share this question
or