Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all 1760 articles
Browse latest View live

New Post: Single instance wpf app

$
0
0
I use this method that I developed myself.
I use it in many applications, since it integrates seamlessly with the WPF environment, and allows for inter-process communication (notification of next instances startup). If next instances have to close (single instance application), you just need to handle the Started event, checking if the the instance is not the first one, and shutdown the next application.

With this approach, you just need to use an Application-derived object (just changing the App.xaml and App.cs), without the need of defining the Main method explicitly.
Depending on your needs, you can decide to integrate the next-instance check inside the Bootstrapper startup, or before... it just depends on this question: do I need to configure a bootstrapper when the next application has to close? Personally, I prefer to let the bootstrapper be configured, so that I can log next instances and eventually handle/report unexpected exceptions in the same way as the main application. But it is just a personal choice.

I am considering creating a NuGet package for the project, and integrate a Caliburn.Micro based sample.

New Post: Single instance wpf app

$
0
0
Thanks for the info! What I really miss is an example of how the bootstrapper and the single instance detection code should be used together. I mean, should I handle single instance detection and then run the bootstrapper or should I use the bootstrapper to handle single instance detection?

New Post: Single instance wpf app

$
0
0
As I was saying before: it depends on you. If you want/need to use stuff provided by the bootstrapper, the IoC or CM in general, the logic should be in the Bootstrapper (using the code I was speaking above, in the OnStartup override of the bootstrapper). Otherwise, you can override the App.OnStartup method, and procede to the Shutdown if the application is not the first one.

I prefer to handle it in the bootstrapper, since in my opinion there could be actions to be taken requiring bootrstrapper-provided objects (e.g. logging, message boxes). This approach comes to a cost: full initialization of the bootstrapper is performed. The cost, in my opinion, is negligible in respect to the benefits.

Created Unassigned: Partial unsubscription (and subscription) [347]

$
0
0
Sometimes a subscriber may no longer be interested in receiving messages of a certain type, however in its present form, if you unsubcribe from the event aggregator, you do so for all message types.

So the suggestion is to extend the aggregator with a

void Unsubscribe<TMessage>(object subscriber);

to allow only unsubscribing from that specific type of message.

Similarly a

void Subscribe<TMessage>(object subscriber);

could be added.

Looking at the current implementation of EventAggregator this should be a fairly trivial addition to make :)

New Post: vb.net hello world. - frustrated, head banging

$
0
0
does anyone have a simple wp8 hello world sample for vb.net - I've coded in vb for 15 years and cant get on with c#

I cant get anything to work in my experiments, mainly errors with the name/tag bootstrapper does not exist, or initializecomponent is not declared....

I've converted the most basic sample from http://wp.qmatteoq.com/first-steps-with-caliburn-micro-in-windows-phone-8-the-first-project/

but the app wont even build!


sorry for being thick but Im at a loss... which is very frustrating as I have apps I would like to see if I could migrate to use the framework.




App.XAML
<Application
x:Class="glp2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:caliburnMicro="clr-namespace:CaliburnMicro">

<!--Application Resources-->
<Application.Resources>
    <caliburnMicro:Bootstrapper x:Key="bootstrapper" />
</Application.Resources>

<Application.ApplicationLifetimeObjects>
    <!--Required object that handles lifetime events for the application-->
</Application.ApplicationLifetimeObjects>
</Application>


app.vb
Imports System.Diagnostics
Imports System.Resources
Imports System.Windows.Markup

Partial Public Class App
Inherits Application

''' <summary>
''' Provides easy access to the root frame of the Phone Application.
''' </summary>
''' <returns>The root frame of the Phone Application.</returns>
Public Shared Property RootFrame As PhoneApplicationFrame

''' <summary>
''' Constructor for the Application object.
''' </summary>
Public Sub New()
    ' Standard XAML initialization
    InitializeComponent()

    ' Phone-specific initialization
    '   InitializePhoneApplication()

    ' Language display initialization
    '    InitializeLanguage()

    ' Show graphics profiling information while debugging.
    If Debugger.IsAttached Then
        ' Display the current frame rate counters.
        Application.Current.Host.Settings.EnableFrameRateCounter = True

        ' Show the areas of the app that are being redrawn in each frame.
        'Application.Current.Host.Settings.EnableRedrawRegions = True

        ' Enable non-production analysis visualization mode,
        ' which shows areas of a page that are handed off to GPU with a colored overlay.
        'Application.Current.Host.Settings.EnableCacheVisualization = True


        ' Prevent the screen from turning off while under the debugger by disabling
        ' the application's idle detection.
        ' Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
        ' and consume battery power when the user is not using the phone.
        PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled
    End If
End Sub
End Class

bootstrapper.vb


Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports Caliburn.Micro
Imports CaliburnMicro.ViewModels

Namespace CaliburnMicro
Public Class Bootstrapper
    Inherits PhoneBootstrapper
    Private container As PhoneContainer

    Protected Overrides Sub Configure()
        If Execute.InDesignMode Then Return

        container = New PhoneContainer()

        container.RegisterPhoneServices(RootFrame)
        container.PerRequest(Of MainPageViewModel)()
        AddCustomConventions()
    End Sub

    Private Shared Sub AddCustomConventions()
        'ellided  
    End Sub

    Protected Overrides Function GetInstance(service As Type, key As String) As Object
        Return container.GetInstance(service, key)
    End Function

    Protected Overrides Function GetAllInstances(service As Type) As IEnumerable(Of Object)
        Return container.GetAllInstances(service)
    End Function

    Protected Overrides Sub BuildUp(instance As Object)
        container.BuildUp(instance)
    End Sub
End Class
End Namespace

New Post: Screens, Conductors and Composition

$
0
0
Cheers for CM - It's really great. I am building an application based on the Billy Hollis model used in the CM Training example. My application is quite advanced and has 10 screens rather than the 3 basic screens in the example. My latest issue is how to work with one screen from within the view model of another screen. For a simply stated example, suppose that while working the original CM sample - - - in the "Orders" screens view model of the example, you needed to call the "Customers" Master screen. (Easy, you just click the Customers Icon) - - - but no - - I need to call the customer master in code from the orders view model. Seems like it should be so easy but, so far it has me stumped. Can anyone help to show me how.
Thanks a lot!

New Post: vb.net hello world. - frustrated, head banging

$
0
0
I also work in VB and have converted and built several of the various CM examples in a VB version. (Un-fortunately none of the Windows 8 or phone apps yet). The screens example modeled on the Billy Hollis presentation is nothing short of marvelous and yes it works great in VB. I would be happy to share these examples with anyone who would send me their eMail address. Most of the C# to VB converters have trouble with the lambda expressions as used in CM and struggle with more advanced C# to VB conversion, so it can be a hassle to get started in CM with VB. The good news is that all you need to do is make your way through the conversion once and from then on its clear sailing (and well worth the trouble).

New Post: Single instance wpf app

$
0
0
I guess you are right, putting the logic into the bootstrapper makes more sense and the cost is negligible indeed.

I tried using your code but unfortunately I couldn't get it to work with Caliburn.Micro. I inherited from InstanceAwareApplication, created my unique fixed app GUID and subscribed to the necessary but nothing happened. And by nothing happened I mean that more than one instance of the application could be opened without problems.

Do I have to do anything different because I'm using the Caliburn bootstrapper? I'm using the latest release from nuget, the one with a sample bootstrapper.


On a side note, how hard would it be to accept command line args and pass them to the already running instance? I'm currently doing this manually but it would be nice to implement this together with the single instance behaviour.

New Post: Marshalling INotifyPropertyChanged.PropertyChanged event on UI thread & TaskCanceledException

$
0
0
First off all, why do you marshall INotifyPropertyChanged.PropertyChanged event to UI thread? There is no needed to do it, at least for WPF (it is automatically marshalled to the UI dispatcher).

The second thing, now, for marshalling this event to UI thread in .Net 4.5 you use Dispatcher.InvokeAsync method and waiting returned task, but if application is shutdowning now this task could throw TaskCanceledException, so maybe it's ok catch this type of exception and swallow it, because now it can be cause of application crash during shutdowning, what do you think?

Thanks for you work!

New Post: Marshalling INotifyPropertyChanged.PropertyChanged event on UI thread & TaskCanceledException

$
0
0
The issue with the exception on shutdown has already be fixed in latest CM 2.0.0-alpha

New Post: Marshalling INotifyPropertyChanged.PropertyChanged event on UI thread & TaskCanceledException

$
0
0
Thanks!
Do you consider option do not marshall INotifyPropertyChanged.PropertyChanged event on UI thread?

New Post: Marshalling INotifyPropertyChanged.PropertyChanged event on UI thread & TaskCanceledException

$
0
0
Check this issue.
There is a way to disable this behavior (I am afraid, even if not globally).

New Post: Marshalling INotifyPropertyChanged.PropertyChanged event on UI thread & TaskCanceledException

New Post: Single instance wpf app

$
0
0
The code already deals with passing arguments (check the StartupNextInstance event). You can hook the event in the bootstrapper and process the arguments of the other application instance.

Regarding the shutdown, you need to check if the started up instance is the first one (App.Current.IsFirstInstance), then call Shutdown directly if the property returns false. The code does not assume that other instances have to be shutdown (that's why it is called InstanceAwareApplication and not SingleInstanceApplication ;) ).

New Post: Single instance wpf app

$
0
0
Check the latest source code from the project I posted above. I added a CM sample.

Source code checked in, #91f16c0826c3e0a710ead5a087c93ad62e42e5b5

$
0
0
restrict Callisto version for Win8.0

Released: Caliburn.Micro v2.0.0-alpha (Nov 13, 2013)

$
0
0

Caliburn.Micro v2.0.0-alpha is a major release with breaking changes. This version has undergone significant re-design, splitting it into two portions: a Portable Class Library core and platform-specific adapters.


Packages Available on Nuget

  • Caliburn.Micro.Core - The Portable Class Library (PCL) portion of Caliburn.Micro.
  • Caliburn.Micro – The platform-specific adapters for Caliburn.Micro.
  • Caliburn.Micro.Start - Includes a starting bootstrapper, view model and view.

Changes

  • portable library net45+sl5+win8+wp8 (issue 259), SL4, WP71 and NET40 will not be supported
  • Support Windows 8.1 (issue 336) and use new Behavior SDK (issue 338)
  • Fix CultureInfo in CoerceValue
  • Remove Bootstrapper<TRootModel> and PhoneBootstrapper, use BootstrapperBase and PhoneBootstrapperBase
  • Remove package builder (will not work because portable/platform split)
  • Remove EventAggregator PublicationThreadMarshaller and Publish() without marshaller
  • Add EventAggregatorExtensions (PublishOnCurrentThread, PublishOnBackgroundThread, PublishOnUIThread, BeginPublishOnUIThread and PublishOnUIThreadAsync)
  • Fix OnViewReady should be called on child views too (issue 292)
  • Screen only have one TryClose(bool? dialogResult = null)
  • Coroutine uses CoroutineExecutionContext instead of ActionExecutionContext (as it is not portable)
  • SettingsService.RegisterCommand renamed to RegisterFlyoutCommand
  • CallistoSettingsWindowManager removed, replaced with SettingsWindowManager
  • Dependency on Callisto removed
  • Dependency on Windows.UI.Interactivity removed, replaced with 8.1 Behaviours SDK.
  • NotifyOfPropertyChange() does not support [CallerMemberName] at the moment
  • Fix Memory leak in ActivateWith() and DeactivateWith()
  • View/ViewModel-Locator performance improvement (issue 342)

Updated Release: Caliburn.Micro v2.0.0-alpha (Nov 13, 2013)

$
0
0

Caliburn.Micro v2.0.0-alpha is a major release with breaking changes. This version has undergone significant re-design, splitting it into two portions: a Portable Class Library core and platform-specific adapters.


Packages Available on Nuget

  • Caliburn.Micro.Core - The Portable Class Library (PCL) portion of Caliburn.Micro.
  • Caliburn.Micro – The platform-specific adapters for Caliburn.Micro.
  • Caliburn.Micro.Start - Includes a starting bootstrapper, view model and view.

Changes

  • portable library net45+sl5+win8+wp8 (issue 259), SL4, WP71 and NET40 will not be supported
  • Support Windows 8.1 (issue 336) and use new Behavior SDK (issue 338)
  • Fix CultureInfo in CoerceValue
  • Remove Bootstrapper<TRootModel> and PhoneBootstrapper, use BootstrapperBase and PhoneBootstrapperBase
  • Remove package builder (will not work because portable/platform split)
  • Remove EventAggregator PublicationThreadMarshaller and Publish() without marshaller
  • Add EventAggregatorExtensions (PublishOnCurrentThread, PublishOnBackgroundThread, PublishOnUIThread, BeginPublishOnUIThread and PublishOnUIThreadAsync)
  • Fix OnViewReady should be called on child views too (issue 292)
  • Screen only have one TryClose(bool? dialogResult = null)
  • Coroutine uses CoroutineExecutionContext instead of ActionExecutionContext (as it is not portable)
  • SettingsService.RegisterCommand renamed to RegisterFlyoutCommand
  • CallistoSettingsWindowManager removed, replaced with SettingsWindowManager
  • Dependency on Callisto removed
  • Dependency on Windows.UI.Interactivity removed, replaced with 8.1 Behaviours SDK.
  • NotifyOfPropertyChange() does not support [CallerMemberName] at the moment
  • Fix Memory leak in ActivateWith() and DeactivateWith()
  • View/ViewModel-Locator performance improvement (issue 342)

Edited Issue: [Phone] NullReferenceException in TaskController [337]

$
0
0
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<PhotoChooserTask>()
2. The PhotoChooserTask completes, Page A's async void Handle(TaskCompleted<PhotoResult> completed) fires.
3. Page A navigates to Page B which does EventAggregator.RequestTask<ShareMediaTask>()
4. Pres Back button twice to get back to Page A.
5. Page A does EventAggregator.RequestTask<PhotoChooserTask>()
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.

Edited Issue: [Win8] StartDesignTime() is not executed in designer [344]

$
0
0
`StartDesignTime()` logic is not executed in designer.

see https://caliburnmicro.codeplex.com/discussions/463911 for details
Viewing all 1760 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>