Giter Site home page Giter Site logo

caliburn-micro / caliburn.micro Goto Github PK

View Code? Open in Web Editor NEW
2.8K 184.0 773.0 22.23 MB

A small, yet powerful framework, designed for building applications across all XAML platforms. Its strong support for MV* patterns will enable you to build your solution quickly, without the need to sacrifice code quality or testability.

Home Page: http://caliburnmicro.com/

License: MIT License

PowerShell 0.02% C# 99.98%
c-sharp mvvm xamarin xamarin-forms wpf windows-phone windows-8 windows-10 uwp hacktoberfest

caliburn.micro's People

Contributors

0x8deadf00d avatar adamgauthier avatar altso avatar bartoszpierzchlewiczmacrix avatar bjoernfi avatar brunojuchli avatar coola avatar dependabot[bot] avatar e-tobi avatar eisenbergeffect avatar fredrikl avatar gpetrou avatar heskandari avatar jozefizso avatar kaspersk avatar mcdonnelldean avatar mgnsm avatar mjuen avatar mvermef avatar mykezero avatar neilt6 avatar ngbrown avatar nigel-sampson avatar pableess avatar shaunmarx avatar taori avatar tapanila avatar tibel avatar vb2ae avatar willson556 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

caliburn.micro's Issues

Can't add to Windows Phone 8.1 universal project

When i try to add Caliburn.Micro to a windows phone 8.1 universal project i get the following error:

Attempting to resolve dependency 'Caliburn.Micro.Core (= 2.0.0)'.
'Caliburn.Micro.Core 2.0.0' already installed.
'Caliburn.Micro 2.0.0' already installed.
Adding 'Caliburn.Micro.Core 2.0.0' to CM.HelloUniversal.WindowsPhone.
Could not install package 'Caliburn.Micro.Core 2.0.0'. You are trying to install this package into a project that targets 'WindowsPhoneApp,Version=v8.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

[Phone] Tombstoning Doesn't Support Composite View Models

The scenario in question is that in a WP7 app, a view model (a Conductor for example) has an Items collection, which may contain other view models. The user can add new items on the fly, and therefore we don't have specific design-time knowledge of them. However, we want to be able to persist them using CM's tombstoning support.

We should be able to, in the storage handler for the conductor, specify that the Items property (or any other collection) should get persisted. Ideally, the storage mechanism should then look up any available storage handlers for the view model types contained in Items (or other specified collections) in order to persist them.

Currently, the storage mechanism simply attempts to serialize the objects in the collection in their entirety, which typically results in an exception. I've worked around this in my app using a custom implementation of IStorageHandler that does its own binary serialization; but I'd rather use the same mechanism for everything.

Remove Win8.0 support

The CM Win8.0 version depends on two projects that discontinued Win8.0 support.

<dependency id="Windows.UI.Interactivity" version="[1.3.0]" />
<dependency id="Callisto" version="[1.3.1]" />

There will not be any bug fixes, changes or enhancements.

Is there still the need to support Win8.0, as Win8.1 was a free update?

WP71 sample does not work, neither does Caliburn in a WP8 project

The WP71 sample calls an undefined method Initialize in AppBootstrapper.cs, line 13. If I delete the call, the project compiles but hangs on splashscreen.

The AppBootstrapper constructor gets called, but the Configure does not.

If I create a WP8 project and add Caliburn 2.0, the result is the same, the app just hangs.

Add a Set<T> method to Screen and PropertyChangedBase

Would it be sensible to add something similar to the MVMM Light ViewModelBase.Set method(s)?

e.g.

    protected bool Set<T>(string propertyName, ref T field, T newValue)
    {
        if (EqualityComparer<T>.Default.Equals(field, newValue))
            return false;
        field = newValue;
        this.NotifyOfPropertyChange<T>(propertyName);
        return true;
    }

    protected bool Set<T>(
         ref T field, T newValue, [CallerMemberName] string propertyName = null)
    {
        return Set(propertyName, ref field, newValue);
    }

    ... lambda version etc

Usage

    class SomeClass : Screen
    {
        private int _someProp;
        public int SomeProp 
        {
            get{ return _someProp; }
            set{ Set( ref _someProp, value ); }
        }
    }

Or add an extension method

    internal static class NotifyPropertyChangeExtensions
    {
        public static bool Set<T>(
            this INotifyPropertyChangedEx notifier, ref T field, 
            T newValue, [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(field, newValue))
            {
                return false;
            }

            field = newValue;
            notifier.NotifyOfPropertyChange(propertyName);

            return true;
        }
    }

Usage

    class SomeClass : Screen
    {
        private int _someProp;
        public int SomeProp 
        {
            get{ return _someProp; }
            set{ this.Set( ref _someProp, value ); }
        }
    }

[Win81] ActionMessage does not work without Message.Attach

When adding an ActionMessage to a trigger using the verbose XAML syntax like this:

<Button x:Name="btnMonth" Content="Month">
  <Interactivity:Interaction.Behaviors>
    <Core:EventTriggerBehavior EventName="Click">
      <cal:ActionMessage MethodName="SetCalendarView">
        <cal:ActionMessage.Parameters>
          <cal:Parameter Value="{Binding Month}" />
        </cal:ActionMessage.Parameters>
       </cal:ActionMessage>
     </Core:EventTriggerBehavior>
  </Interactivity:Interaction.Behaviors>
</Button>

the trigger will throw an exception that the method could not be found. This is due to ActionMessage.AssociatedObject not being set. A workaround is to bind the AssociatedObject manually to the element the trigger is set on:

<cal:ActionMessage MethodName="SetCalendarView" AssociatedObject="{Binding ElementName=btnMonth}">

Verbose action syntax not working

The verbose action syntax is not working, even the shown example in the docs is throwing errors.

<Button Content="Click Me">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <cal:ActionMessage MethodName="SayHello" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
</Button>

Firstly, ActionMessage is not available in the cal: namespace. If you add it anyway, it says 'EventTrigger' would not support direct content.
Crazy thus it worked with older version of caliburn.micro and the docs say that is should be correct.

"Composition over Inheritance" for Screen / Conductor

Hi everyone
(Note: I did not really know how i should contact you about this. Is there a discussion board?)
We've been using Caliburn / Caliburn.Micro for several years now. Thank you for all your efforts and the good work.

We've been having some code-quality sorrows with Screens and Conductors. They are based on Separation of Concern and Coupling. To reach loose coupling we moved (some) of the conducting logic away from view models to separate code.
I've created a sample application showing what we've achieved so far, you can find it here: https://github.com/BrunoJuchli/RibbonizerSample

What we achieved so far:
-Activation & deactivation of children, i.E. settings a child property to a new value will deactivate the old child and activate the new child.
(-An adapter for Caliburn.Micro Screen/Conductor child view models, so that you can replace Screens/Conductors step-by-step)

  • Extensibility in the regard that you can register ILifecycleExtension for view models, the extension is informed upon Activation / Deactivation of a view model.

This is implemented in the so called ILifecycleController.

Based on that we were able to achieve a much better design (loose coupling, separation of concern) for our ribbon implementation, long story short, this is the change it resulted in:
(for future readers: the Views for the corresponding ViewModels all exist, but they have been omitted due to not being relevant for this particular example method call)
Old:
Design new
New:
Design new

Furthermore we are using PropertyChanged.Fody for property change notification.
All of this enabled us to forgo inheritance at ViewModel classes completely.

Note: I came across an interview with Rob Eisenberg, where he said:
(...) "As we explored the MVVM pattern more, along with other UI modeling ideas, we realized the critical importance of "composition over inheritance." (...).

That's why i thought you might be open to improving Screen/Conductors in this direction. I would be happy to contribute.

Respect guard properties / methods for bound properties

Not 100% sure if this would be possible or even a good idea yet, but could we respect guard properties when bound to methods as well?

http://stackoverflow.com/questions/23815239/why-is-the-guard-property-for-a-toggle-button-ignored-when-its-name-matches-a-p/

From a convention point of view I don't think it'll always make sense and make for some weirdly named view model properties.

For instance:

public string Username
{
    get; set;
}

public bool CanUsername
{
    get { return LoginMethod == LoginMethods.Username; }
}

ArgumentNullException in ActionMessage.cs

When removing a resource dictionary that contains a style with a template that contains a Action.TargetWithoutContext statement I get an ArgumentNullException. I haven't tested if it occurs with Action.Target as well. The following code is responsible:

ActionMessage.cs Line 375-378

var source = context.Source;
if (ConventionManager.HasBinding(source, UIElement.IsEnabledProperty)){
    return source.IsEnabled;
}

The problem is source is null, so the call to HasBinding fails. I would imagine a simple null check will solve the issue, but I don't understand the internals of CM well enough to really know.

In Caliburn.Micro v1.5.2 I had a similar issue with context.Source being null (under the same circumstances). v2.0.0.6 solved that issue, but then this one arose. The problem occurs when UpdateContext gets called when base.AssociatedObject is null.

Here is the Callstack:

System.ArgumentNullException: Value cannot be null.
Parameter name: target
   at System.Windows.Data.BindingOperations.GetBindingExpressionBase(DependencyObject target, DependencyProperty dp)
   at System.Windows.Data.BindingOperations.GetBindingBase(DependencyObject target, DependencyProperty dp)
   at Caliburn.Micro.ConventionManager.HasBinding(FrameworkElement element, DependencyProperty property)
   at Caliburn.Micro.ActionMessage.<.cctor>b__f(ActionExecutionContext context)
   at Caliburn.Micro.ActionMessage.UpdateAvailabilityCore()
   at Caliburn.Micro.ActionMessage.UpdateContext()
   at Caliburn.Micro.ActionMessage.HandlerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.Freezable.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
   at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
   at System.Windows.Data.BindingExpression.ScheduleTransfer(Boolean isASubPropertyChange)
   at MS.Internal.Data.ClrBindingWorker.NewValueAvailable(Boolean dependencySourcesChanged, Boolean initialValue, Boolean isASubPropertyChange)
   at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
   at MS.Internal.Data.PropertyPathWorker.OnDependencyPropertyChanged(DependencyObject d, DependencyProperty dp, Boolean isASubPropertyChange)
   at MS.Internal.Data.ClrBindingWorker.OnSourceInvalidation(DependencyObject d, DependencyProperty dp, Boolean isASubPropertyChange)
   at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
   at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
   at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Caliburn.Micro.Message.SetHandler(DependencyObject d, Object value)
   at Caliburn.Micro.Action.SetTargetCore(DependencyPropertyChangedEventArgs e, DependencyObject d, Boolean setContext)
   at Caliburn.Micro.Action.OnTargetWithoutContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
   at System.Windows.StyleHelper.ClearTemplateChain(HybridDictionary[] instanceData, FrameworkElement feContainer, FrameworkContentElement fceContainer, List`1 templateChain, FrameworkTemplate oldFrameworkTemplate)
   at System.Windows.StyleHelper.ClearGeneratedSubTree(HybridDictionary[] instanceData, FrameworkElement feContainer, FrameworkContentElement fceContainer, FrameworkTemplate oldFrameworkTemplate)
   at System.Windows.StyleHelper.DoTemplateInvalidations(FrameworkElement feContainer, FrameworkTemplate oldFrameworkTemplate)
   at System.Windows.Controls.ContentPresenter.OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Controls.ContentPresenter.OnContentTemplateChanged(DataTemplate oldContentTemplate, DataTemplate newContentTemplate)
   at System.Windows.Controls.ContentPresenter.OnContentTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
   at System.Windows.StyleHelper.ClearTemplateChain(HybridDictionary[] instanceData, FrameworkElement feContainer, FrameworkContentElement fceContainer, List`1 templateChain, FrameworkTemplate oldFrameworkTemplate)
   at System.Windows.StyleHelper.ClearGeneratedSubTree(HybridDictionary[] instanceData, FrameworkElement feContainer, FrameworkContentElement fceContainer, FrameworkTemplate oldFrameworkTemplate)
   at System.Windows.StyleHelper.DoTemplateInvalidations(FrameworkElement feContainer, FrameworkTemplate oldFrameworkTemplate)
   at System.Windows.Controls.Control.OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.StyleHelper.InvalidateContainerDependents(DependencyObject container, FrugalStructList`1& exclusionContainerDependents, FrugalStructList`1& oldContainerDependents, FrugalStructList`1& newContainerDependents)
   at System.Windows.StyleHelper.DoStyleInvalidations(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle)
   at System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, Style& styleCache)
   at System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.FrameworkElement.UpdateStyleProperty()
   at System.Windows.TreeWalkHelper.InvalidateStyleAndReferences(DependencyObject d, ResourcesChangeInfo info, Boolean containsTypeOfKey)
   at System.Windows.TreeWalkHelper.OnResourcesChanged(DependencyObject d, ResourcesChangeInfo info, Boolean raiseResourceChangedEvent)
   at System.Windows.TreeWalkHelper.OnResourcesChangedCallback(DependencyObject d, ResourcesChangeInfo info, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1._VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(FrameworkElement fe, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.VisitNode(DependencyObject d, Boolean visitedViaVisualTree)
   at System.Windows.DescendentsWalker`1.WalkLogicalChildren(FrameworkElement feParent, FrameworkContentElement fceParent, IEnumerator logicalChildren)
   at System.Windows.DescendentsWalker`1.WalkFrameworkElementLogicalThenVisualChildren(FrameworkElement feParent, Boolean hasLogicalChildren)
   at System.Windows.DescendentsWalker`1.IterateChildren(DependencyObject d)
   at System.Windows.DescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode)
   at System.Windows.TreeWalkHelper.InvalidateOnResourcesChange(FrameworkElement fe, FrameworkContentElement fce, ResourcesChangeInfo info)
   at System.Windows.ResourceDictionary.NotifyOwners(ResourcesChangeInfo info)
   at System.Windows.ResourceDictionary.OnMergedDictionariesChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at System.Windows.ResourceDictionaryCollection.InsertItem(Int32 index, ResourceDictionary item)
   at System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item)
   at RQ.Windows.Styles.Redesign.RedesignMasterStyleSheet.InternalReload(Collection`1 mergedDictionaries, Object key, ResourceDictionary dictionary, ResourceDictionary resourceDictionary) in c:\Git\RQ4\Code\RQ.Windows\Styles\Redesign\RedesignMasterStyleSheet.xaml.cs:line 78

[Phone] NullReferenceException in TaskController

Hi,

I'm getting null ref errors in TaskController.OnTaskComplete method because the "request" field is null. I dug deeper and while I don't have a solid understanding of why it's happening here is what is happening:

  1. Page A does EventAggregator.RequestTask()
  2. The PhotoChooserTask completes, Page A's async void Handle(TaskCompleted completed) fires.
  3. Page A navigates to Page B which does EventAggregator.RequestTask()
  4. Pres Back button twice to get back to Page A.
  5. Page A does EventAggregator.RequestTask()
  6. The PhotoChooserTask completes and the NullReferenceException crash happens in the TaskController.OnTaskComplete.
    The culprit is this, on step 5 the TaskController handles the TaskExecutionRequested and executes this bit of code:
            var @event = taskType.GetEvent("Completed");
            if(@event != null) {
                request = message;
                @event.AddEventHandler(request.Task, CreateOnTaskCompletedDelegate(@event));
            }

As soon as the event handler is attached the Chooser's event fires with TaskResult.Cancel result. TaskController.OnTaskComplete executes and clears out the request field.

So when the Chooser is actually shown and completes and OnTaskComplete is fired again the request field is null.

Issue with DataContracts on classes inheriting from PropertyChangedBase

Upgraded to 2.0 recently and the only problem I have encountered is with the DataContractJsonSerializer.

An exception of type 'System.Runtime.Serialization.InvalidDataContractException'
occurred in System.Runtime.Serialization.dll but was not handled in user code

Additional information: Type 'Shows.Models.Episode' cannot inherit from a type that is 
not marked with DataContractAttribute or SerializableAttribute.  Consider marking the 
base type 'Caliburn.Micro.PropertyChangedBase' with DataContractAttribute or 
SerializableAttribute, or removing them from the derived type.

My 'Episode' class is marked with the [DataContract] attribute and contains a few [DataMembers] and inherits PropertyChangedBase. This class use to work fine with the serializer while inheriting PropertyChangedBase.

[Phone] OnViewReady doesn't work after an app was resumed

Hi!

There is some sort of problem with OnViewReady method in WP apps. It is correctly works after first navigation and after back navigation to a page. But if an app was deactivated by pressing Home button and after that it was resumed then nothing happen. OnViewReady doesn't called in this sutiation. Only after some interactions with the page (for example pressing of a button) method will be called (because LayoutUpdated event occurs only after that).

As far as I know all "heavy" actions must be performed in the OnViewReady. For example updating of a big list of data. Data in the app could became outdated between dormant and resumed states. And current framework behavior ruins update logic in this particular scenario. I think this is an issue.

Use of Task.Factory.StartNew in PublishOnBackgroundThread() method

This is more of a question than anything. We have noticed occasions where our message handlers would be executing on the UI thread even though we always post messages using the PublishOnBackgroundThread method to publish these messages. Upon reading into the issue and looking at the Caliburn.Micro source, I suspect this might be due to the usage of Task.Factory.StartNew in the PublishOnBackgroundThread method. Would Task.Run be more appropriate here to ensure that we are always using TaskScheduler.Default?

http://richnewman.wordpress.com/2012/11/21/why-starting-a-new-task-in-the-task-parallel-library-tpl-doesnt-always-start-a-new-thread/

Add control naming conventions

From StackOverflow question:

Caliburn.Micro allows configuring naming conventions for views and view models, but I couldn't find how to configure matching between controls and methods/properties. I know I can just use Message.Attach attached property, but I'd like to rely on conventions if it's possible.

Caliburn.Micro's conventions say that methods must be named the same as controls. But here lies a problem: they are often named differently. For example, Save and Cancel are good names for methods, but bad names for buttons. SaveButton and CancelButton are good names for buttons, but bad names for methods. Considering XAML is less strictly typed than C#, Hungarian notation can be useful too, but names like btnSave and btnCancel are unacceptable for methods.

It would be nice if Caliburn.Micro supported custom rules for control naming conventions. For example, rules could be used to remove suffixes like Button and List, or remove Hungarian prefixes like btn and lst.

Navigation in windows universal app

when i use caliburn.micro in windows universal app,i meet the problem of navigate.
I config my App class like ths:

namespace HelloBlue {
    public sealed partial class App {
        private WinRTContainer container;

        public App() {
            InitializeComponent();
        }

        protected override void Configure() {
            container = new WinRTContainer();
            container.RegisterWinRTServices();
            container.PerRequest<MainPageViewModel>()
                .PerRequest<SubPageViewModel>();
        }

        protected override object GetInstance(Type service,string key) {
            var instance = container.GetInstance(service,key);
            if(instance != null)
                return instance;

            throw new Exception("Could not locate any instances.");
        }

        protected override void PrepareViewFirst(Frame rootframe) {
            container.RegisterNavigationService(rootframe);
        }

        protected override IEnumerable<object> GetAllInstances(Type service) {
            return container.GetAllInstances(service);
        }

        protected override void BuildUp(object instance) {
            container.BuildUp(instance);
        }

        protected override void OnLaunched(LaunchActivatedEventArgs e) {
            DisplayRootView<MainPage>();
        }

    }
}

and navigate use the FrameAdapter:

        private void ListViewOnSelectionChanged(object sender, SelectionChangedEventArgs selectionChangedEventArgs) {
            IoC.Get<INavigationService>().Navigate<SubPage>(ListView.SelectedItem);
        }

It just work well and the frame navigate to the SubPage as expected.
but when I press back key on the device,the frame doesn't navigate back to MainPage,but it back to the app list, it seems like the app is exited.
Is there something wrong with my code?

[Win81] Exception on Toggle in/out of view

In Win8.1, if you have a ItemsControl derived type that removes and re-adds some portion of its children and you're using the c:View.Model binding on a data template to convert child view models into their views, you hit an issue.

The issue is this. The OnModelChanged event gets fired every time that the child appears or disappears, which in and of itself would not be bad. However, the following pattern is then employed ...

  1. Use the ViewLocator to get the view.
  2. Set the ContentProperty on the target to the view.

The problem lies in that the ViewLocator attempts to use a cached view by default and that view is still part of the visual tree. Therefore, the setting the content property fails because the view is already the child of another element in the tree.

This has been tested with several Syncfusion controls that employ this visual hiding/reshowing.

The workaround is to add this override, which trades out the exception (and failure to display the view-model with instead a memory increase as the view keeps being created.

public override object GetView(object context = null) {
    return null;
}

COMException caused by naming conflict (WinRT)

In my viewmodel I've got the following property:

// INPC by fody
public List<string> Services { get; set; }

which is bound to the following view:

<Grid x:Name="Services">
    <ItemsControl ItemsSource="{Binding Services}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="&#10003;" />
                    <TextBlock Text="{Binding}" />
                </StackPanel>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>

Note: I've named the Grid solely for documentational purposes.

Upon setting the Services property in my viewmodel, I receive the following exception:

An exception of type 'System.Runtime.InteropServices.COMException' occurred in Caliburn.Micro.DLL but was not handled in user code

Additional information: Error HRESULT E_FAIL has been returned from a call to a COM component.

With this stacktrace:

at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
at Caliburn.Micro.PropertyChangedBase.OnPropertyChanged(PropertyChangedEventArgs e)
at Caliburn.Micro.PropertyChangedBase.<>c__DisplayClass4.<NotifyOfPropertyChange>b__2()
at Caliburn.Micro.XamlPlatformProvider.OnUIThread(Action action)
at Caliburn.Micro.Execute.OnUIThread(Action action)
at Caliburn.Micro.PropertyChangedBase.NotifyOfPropertyChange(String propertyName)
at MyNamespace.Class.set_Services(List`1 value)

If I change the grids name to something other than "Services", the exception does not occur.

I'm using Caliburn.Micro version 2.0.0-beta

Trace possibilities

There should be trace message included which can be activated in the application configuration. At the moment it is hard to debug for example why a Message.Attach failed. It just does silently nothing instead of tracing something like "Attach failed, Event {0} was not found on the element"

Using Conductor with Hub in Windows Phone 8.1 XAML

Windows Phone 8.1 XAML contains a Hub control that should be used instead of Pivot or Panorama.

Hub is not bindable, so I guess I would have to create a new control inheriting from Hub with a bindable ItemsSource and SelectedItem properties. This should not be so difficult to make it work with an ItemTemplate that is a part of the control.

But I want the ItemTemplate to be the View associated to the ViewModel. So if I have a (ot a collection of) IScreen, is there a way to get the associated View for them? Ideally in a way that the View could be easily transformed to a DataTemplate.

private static void ItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var hub = d as ItemsHub;
            if (hub != null)
            {
                var items = e.NewValue as BindableCollection<IScreen>;
                if (items != null)
                {
                    hub.Sections.Clear();
                    foreach (var item in items)
                    {                        
                        var section = new HubSection {DataContext = item, Header = item, HeaderTemplate = hub.SectionHeaderTemplate};                       
                        DataTemplate template = hub.ItemTemplate; //somehow get the View for the IScreen and convert it to DataTemmplate
                        section.ContentTemplate = template;
                        hub.Sections.Add(section);
                    }
                }
            }
        }

[Phone] Deactivating a ViewModel always sends false for close param

When a view model is truly closed, I would expect the close parameter of the Screen's Deactivate function to be true.
This it not the case when navigating away from a Windows Phone 8 page.
I believe that this parameter should be true at least for navigating backwards.
It seems like this was already fixed in a previous version:
http://caliburnmicro.codeplex.com/workitem/193
But somehow the fix did not make it through to current version.

Binding with Caliburn.Micro Failing

I have a MessageBoxView and an associated MessageBoxViewModel class, as shown below

public class MessageBoxViewModel : DialogViewModel<MessageDialogResult> { ... }

where

public abstract class DialogViewModel<TResult> : PropertyChangedBase { ... }

In my MessageBoxView XAML I am attempting to bind to some properties within the MessageBoxViewModel class. However, using Snoop I can see that the binding is failing. the stack trace/binding error is showing:

System.Windows.Data Error: 40 : BindingExpression path error: 'AffirmativeButtonText' property not found on 'object' ''ShellViewModel' (HashCode=19096940)'. BindingExpression:Path=AffirmativeButtonText; DataItem='ShellViewModel' (HashCode=19096940); target element is 'Button' (Name='AffirmativeButton'); target property is 'Content' (type 'Object')

This view is for a dialog box, so I do not want this to inherit from IScreen. How can I get Caliburn.Micro to bind to properties in the associated view model?

Thanks for your time.

2.0.0 - DisplayRootViewFor, Message.Attach with Conductor throws ArgumentNullException

I have a ShellViewModel that is of type Conductor.Collection.OneActive. Its view contains a ContentControl to display the ActiveItem (<ContentControl Name="Workspace" cm:View.Model="{Binding ActiveItem}").

The ShellViewModel calls ActivateItem on another view that contains 2 buttons with Message.Attach handlers. When my CaliburnBootstrapper calls DisplayRootViewFor, the ActivateItem call to the other view causes an ArgumentNullException because of the Message.Attach in the second view's XAML. If I change the syntax to use <Interactions.Triggers>, all works fine. (Full exception below)

Examples:

Exception thrown:

<Button FontSize="15"   x:Name="New" Content="New" cal:Message.Attach="[Event MouseEnter] = [Action DoSomething()]; 
[Event MouseLeave] = [Action DoDifferentThing()]" />

No exception:


<Button FontSize="15"   x:Name="New" Content="New"
<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseEnter">
        <cm:ActionMessage MethodName="DoSomething" />
    </i:EventTrigger>
</i:Interaction.Triggers>
</Button>

Exception details:

System.ArgumentNullException was unhandled
  HResult=-2147467261
  Message=Value cannot be null.
Parameter name: target
  Source=PresentationFramework
  ParamName=target
  StackTrace:
       at System.Windows.Data.BindingOperations.GetBindingExpressionBase(DependencyObject target, DependencyProperty dp)
       at System.Windows.Data.BindingOperations.GetBindingBase(DependencyObject target, DependencyProperty dp)
       at Caliburn.Micro.ConventionManager.HasBinding(FrameworkElement element, DependencyProperty property)
       at Caliburn.Micro.ActionMessage.<.cctor>b__f(ActionExecutionContext context)
       at Caliburn.Micro.ActionMessage.UpdateAvailabilityCore()
       at Caliburn.Micro.ActionMessage.UpdateContext()
       at Caliburn.Micro.ActionMessage.ElementLoaded(Object sender, RoutedEventArgs e)
       at Caliburn.Micro.View.<>c__DisplayClass1.<ExecuteOnLoad>b__0(Object s, RoutedEventArgs e)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
       at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
       at MS.Internal.LoadedOrUnloadedOperation.DoWork()
       at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
       at System.Windows.Interop.HwndTarget.OnResize()
       at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
  InnerException: 

Remove SL5 from PCL core

This will solve an issue that comes up when adding WP81 support.
SL5 can still be supported, but not with PCL.

View.Model in Windows 8.1 app bars resets Frame.Content to null

When you put ContentControl with configured Bind.Model and View.Model properties in TopAppBar/BottomAppBar on Windows 8.1 the page content gets blank once menu is opened (via right click).

<Page.TopAppBar>
    <AppBar>
        <ContentControl micro:Bind.Model="TopMenu"
                        micro:View.Model="{Binding}" />
    </AppBar>
</Page.TopAppBar>

I did some debugging and It turned out that Content property of the root Frame is being reset to null.

If you put ContentControl in other place on the page, everything works just fine - it's being replaced with proper view bound to a view model. Therefore, I assume that the issue is related to app bars.

If I remove View.Model, the page doesn't get blank when I open menu, but obviously menu view is not being picked up.

Here is modified WinRT81 sample: http://ge.tt/792Poak1/v/0. Please go to Binding Conventions and open menu to reproduce the issue.

Navigating back in Windows Phone 8.1 XAML

Suppose my page hierarchy is

AViewModel->BViewModel

In every ViewModel (registered as PerRequest) I load the data from server in the OnActivate method and set a flag (private bool class variable) that the data is loaded.

In Windows Phone 8 and Windows Phone 8.1 Silverlight, when the user navigates back from BViewModel, the AViewModel, then in OnActivate the ViewModel knows that the data is already loaded (the flag is true) and does nothing.

This does not work in Windows Phone 8.1 because each time the user navigates back, the ViewModel is created again (I can see the constructor call).

When I set NavigationCacheMode=NavigationCacheMode.Required; in all the views, then the flag survives the back navigation. The problem with this solution is that when I navigate back from BViewModel back to AViewModel, the flag lives so the data is not loaded again but (that is ok) but when I then navigate to BViewModel (with different parameter), then nothing happens because BViewModel was not destroyed and it is reused, with the flag saying that data does not need to be loaded.

Is there a way to make it behave exactly like in Windows Phone 8 (or 8.1 Silverlight)?

Xamarin

Did you plan a support of Xamarin, like did MVVM Cross ?

Thx

Cannot find view for... (unable to locate views without code-behind)

Caliburn.Micro seems to fail locating views if there is no corresponding code-behind class available. This mainly happens on views deriving from Window and UserControl.

Steps to reproduce

Scenario 1

  • Create class ShellViewModel.cs
  • Create page ShellView
  • Delete code-behind ShellView.xaml.cs

Result
Caliburn.Micro successfully loads ShellView.xaml

Scenario 2

  • Create window ShellView
  • Delete code-behind ShellView.xaml.cs

Result
Caliburn.Micro fails to load ShellView.xaml, resulting in a error message.

Issue

This bug seems to be related to the view locator. It is not critical, but code-behind files should be preferably avoided in MVVM.

[WinRT] How to change NavigationService base frame?

I have a view BasePage, which is opened on start, and it contains Frame. I want to register NavigationService using not rootFrame, but my Frame from BasePage.

In WP it was possible to get container from code-behind:

Bootstrapper bootstrapper = Application.Current.Resources["bootstrapper"] as Bootstrapper;

and after that call RegisterNavigationService(CustomFrame);

But I didn't found a way to do it in Win8 app. Any ideas?

Windows Store and WPF action messages behaving differently with 3th party controls

I found interesting scenario when working with 3th party control both in WPF and Windows Store 8.1 applications.

When using WPF controls everything is working as they should be and I can do all following cases:

  • cal:Message.Attach="[Event MapViewTapped] = [Action OnMapViewTapped($eventArgs)]"
  • cal:Message.Attach="Action OnMapViewTapped($eventArgs)" with custom convention defined
  • cal:Message.Attach="OnMapViewTapped($location)" with custom convention and special value defined

When working with Windows Store 8.1, none of the upper cases gets invoked. Funny part for me is that all normal controls like Button or StackPanel are working just fine but with those custom controls, events are not hooked. I can see click happening but when it comes to raising an event, handler is null.

Is there something special that should be considered when working with Windows Store controls that might give me this issue?

I can provide sample projects but to get controls for testing you need to join Beta-program. It is very fast process and free but still some extra steps to do.

RegisterFlyoutCommand not working when Settings Charm is opened

var settingsService = new SettingsService();
settingsService.RegisterFlyoutCommand<AboutViewModel>("About");

causes an exception when the settings charm is loaded

System.InvalidCastException occurred
Message: A first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll
Additional information: Object in an IPropertyValue is of type 'Int32', which cannot be converted to a 'Guid'.

The error appears to be in the SettingsService class:

protected virtual void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args) {
  var settingsCommands = commands.Select((c, i) => new SettingsCommand(i, c.Label, h => OnCommandSelected(c)));

  settingsCommands.Apply(args.Request.ApplicationCommands.Add);
}

where i is an integer, but SettingsCommand tries to convert this object to a Guid.

An ugly work-around is this line

var settingsCommands = _commands.Select((c, i) => new SettingsCommand(new Guid(i,0,0,0,0,0,0,0,0,0,0), c.Label, h => c.OnSelected()));

[WPA81] Design time binding not working with controls inside DataTemplate

I have a Windows.UI.Xaml.Controls.Page with the following attributes:

xmlns:d="http://schemas.microsoft.com/expression/blend/2008 
xmlns:designData="using:Screens.DesignData"
xmlns:cm="using:Caliburn.Micro"
d:DataContext="{d:DesignInstance Type=designData:ViewModel, IsDesignTimeCreatable=True}"
cm:Bind.AtDesignTime="True"

This Xaml does not properly bind the Items property of the DesignInstance to the ListView.ItemsSource:

<HubSection>
    <DataTemplate>
        <StackPanel cm:Bind.Model="{Binding}">
            <ListView x:Name="Items"/>
        </StackPanel>
    </DataTemplate>
</HubSection>

However, if I change my syntax to this the binding works:

<ListView ItemsSource="{Binding Items}"

Bring Bootstrapper and CaliburnApplication inline

Not 100% sure when they diverged but right now the main kick off method is different between the two ways to configure CM,

In Bootstrapper it's Start and in CaliburnApplication it's Initialize.

For consistency it would be nice to be aligned across the two.

Currently leaning towards Initalize

Infer owner of window - needs change to work with multiple active windows

In our app we run 2 windows which are active on different screens at the same time so both are active at all times.

We need to be able to have the owning window for any new windows created inferred correctly.

Attempted workaround:
If I pass in the correct owning window as the context then caliburn fails to find the view for the new window so that seems rather pointless.

Current hack:
I am currently setting a property on the view model that is going to be shown as the new window to declare the correct owner and then override OnViewAttached to set the correct owner at that time.

protected override void OnViewAttached(object view, object context)
        {
            var dependencyObject = view as DependencyObject;
            if (dependencyObject != null && CorrectOwner != null)
            {
                var thisWindow = Window.GetWindow(dependencyObject);
                if (thisWindow != null)
                {
                    thisWindow.Owner = CorrectOwner;
                }
            }

            base.OnViewAttached(view, context);
        }

Could the owner instead be determined by who is set as the top most parent in the hierarchy or some other smarter method rather than first active?

Is there any other approach that could be used to solve this situation?

Raising OnDeactivate() on explicit Items.Remove

If I execute, for example, Items.RemoveAt(0) in Conductor<>.Collection.OneActive, Screen.OnDeactivate(true) should be called. Assuming Items is ObservableCollection, I think it can be easily implemented.

Reason: collection can be changed by ItemsSource and in this scenario Screen.OnDeactivate(bool close) won't be called. I personally have a closeable TabControl and I want to have custom logic in ViewModel when closing a tab.

Using ViewModel from PCL

Trying to create a WP8 and Win8 app that would share some business logic and viewmodels in a PCL.

Lets suppose I have a PhoneApp1 with Views/MainView.xaml and a PCL ClassLibrary1 with ViewModels\MainViewModel.cs. When I start the app I get

[Caliburn.Micro.ViewModelLocator] WARN: View Model not found. Searched: PhoneApp1.ViewModels.MainViewModel, PhoneApp1.ViewModels.Main, PhoneApp1.Views, PhoneApp1.Views, PhoneApp1.Views.MainViewModel, PhoneApp1.Views.Main.

So I added

ViewModelLocator.AddNamespaceMapping("PhoneApp1.Views", "ClassLibrary1.ViewModels");

to the bootstrapper according to the document from https://caliburnmicro.codeplex.com/workitem/186 but it did not help.

Now I get

[Caliburn.Micro.ViewModelLocator] WARN: View Model not found. Searched: ClassLibrary1.ViewModels.MainViewModel, ClassLibrary1.ViewModels.Main, PhoneApp1.ViewModels.MainViewModel, PhoneApp1.ViewModels.Main, PhoneApp1.Views, PhoneApp1.Views, PhoneApp1.Views.MainViewModel, PhoneApp1.Views.Main.

but there is a viewmodel ClassLibrary1.ViewModels.MainViewModel.

Project to reporudce the issue: https://dl.dropboxusercontent.com/u/73642/cmpcl.zip

Upgrade to beta2 fails

I get these compile errors in my WPF 4.5 application:

Error   15  The type 'System.ComponentModel.INotifyPropertyChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. C:\Users\Remco\Documents\Visual Studio 2013\Projects\HearthCap\HearthCap\Shell\WindowCommands\WindowCommandViewModel.cs 5   27  HearthCap
Error   16  The type 'System.Collections.Specialized.INotifyCollectionChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.  C:\Users\Remco\Documents\Visual Studio 2013\Projects\HearthCap\HearthCap\Features\Core\BindableServerCollection.cs  9   18  HearthCap
Error   17  The type 'System.Collections.ObjectModel.ObservableCollection`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.    C:\Users\Remco\Documents\Visual Studio 2013\Projects\HearthCap\HearthCap\Features\Core\BindableServerCollection.cs  9   18  HearthCap

what happened?

edit: just downgraded to beta(1) and the project compiles fine again.

I checked the latest caliburn commits, but don't really see any potential issues. Anyone can shed some light on this?

edit2: I initially tried the nuget package, but the same happens when I build and reference Caliburn.Micro.Platform / Caliburn.Micro.Core myself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.