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

New Post: Changing DataContext, does not change target

$
0
0
Trivial solution: The bootstrapper wasn't correctly setup causing CM to work in "DesignMode" and not properly binding to the target. I think older CM versions didn't assume DesginMode by default.

New Post: Viewmodel not found

$
0
0
I have an AppView and in this view I have an CustomerListView and offcource the viewmodels with the same name.

My AppView looks like:
<Window x:Class="Klanten_beheer.Views.AppView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:Klanten_beheer.Views"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">

<Grid Height="Auto" Width="Auto" Background="AliceBlue">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <local:CustomerListView Grid.Column="0"/>
    <local:CustomerView Grid.Column="2"/>
    <local:ContactView Grid.Column="4"/>

    <GridSplitter Grid.Column="1" Width="3" ResizeDirection="Auto" 
        HorizontalAlignment="Stretch" Background="Navy"
        VerticalAlignment="Stretch"/>

    <GridSplitter Grid.Column="3" Width="3" ResizeDirection="Auto" 
        HorizontalAlignment="Stretch"
        Background="Navy"
        VerticalAlignment="Stretch"/>
</Grid>
</Window>


and my customer list view like (only relevant peace that is):

<UserControl x:Class="Klanten_beheer.Views.CustomerListView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:caliburn="http://www.caliburnproject.org"
         xmlns:local="clr-namespace:Klanten_beheer.ViewModels"
         xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit">

<Border BorderBrush="Navy" BorderThickness="1">
    <Grid>

        <DockPanel  LastChildFill="True" Height="Auto" Width="Auto" Grid.Row="0">
            <Button x:Name="ToLastRecord" Content="&lt;&lt;" Background="LightSkyBlue" caliburn:Message.Attach="[Event Click] = [Action ToLastRecord()]"/>
When push the button a crash is the result telling me it can't find the ToLastRecord.

When I copy past the ToLastRecord to my AppViewModel it will execute this function instead.

I did check all the naming if it's correct and these seem ok.
AppViewModel
AppView

CustomerListViewModel
CustomerListView

Commented Issue: IsolatedStorageException in Save() EndStoring AppSettingsStorageMechanism [225]

$
0
0
There is some issue with Save method in IsolatedStorageSettings.ApplicationSettings.Save();

Stack trace:
5 System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor 908
6 System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor 84
7 System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor 120
8 System.IO.IsolatedStorage.IsolatedStorageFile.OpenFile 84
9 System.IO.IsolatedStorage.IsolatedStorageSettings.Save 152
10 Caliburn.Micro.AppSettingsStorageMechanism.EndStoring 196
11 Caliburn.Micro.StorageCoordinator._Save_b__11 188
12 Caliburn.Micro.ExtensionMethods.Apply 272
13 Caliburn.Micro.StorageCoordinator.Save 1192
14 Caliburn.Micro.StorageCoordinator.OnDeactivated 180
Comments: Hi, Shouldn't StorageCoordinator be fail proof? I am experiencing the very same issue (in production, not knowing anything more than exception data from the Windows Store). I would expect that if anything goes wrong while persisting, it won't affect the application overall state. Thoughts?

New Post: Please Add CanDeactivate function to Screen

$
0
0
I've dealt with the tab control issue before. It is solvable, but it requires some hacking. I've written up a WPF attached behavior that can handle this. It was originally written with Prism in mind, but it is really framework agnostic.

You can see the full source code at my Github

Focus on:
staticvoid view_CurrentChanging(object sender, CurrentChangingEventArgs e)
{
    var items = (ItemCollection)sender;

    if (e.IsCancelable && items.CurrentItem != null)
    {
        var currentView = items.CurrentItem as FrameworkElement;
        if (currentView == null) return;
        var selector = FindVisualParent<Selector>(currentView);
        if (selector == null) return;

        var vetoingSource = currentView as IConfirmDeactivate ?? currentView.DataContext as IConfirmDeactivate;
        
        if (vetoingSource != null&& !vetoingSource.ConfirmDeactivation())
        {
            e.Cancel = true;
        }

        selector.Dispatcher.BeginInvoke(new Action(items.Refresh));
    }
}
It checks the view and view model of the current tab for an implementation of IConfirmDeactivation. If found it calls ConfirmDeactivation(). Based on the result you can cancel or continue the tab change

New Post: No DisplatRootViewFor method for Windows Phone 8

$
0
0
Hello!

Thank you for your nice framework!

How can I load different Views on startup? There is no DisplatRootViewFor method in Windows Phone version.

Now I use INavigationService and its Navigate method in override function OnStartup of PhoneBootstrapperBase class. But after this seems application launch is a bit slower . Am I on a right way? :)

New Post: Bootstrapper.OnStartup never called, following the Basic Configuration example in WPF

$
0
0
I already asked this question on StackOverflow.

I am trying to create a simple WPF application. However, I am keeping the views, models and bootstrapper in separate class library and calling it from a separate WPF application.

My library has just one view for main window, one MainWindow xaml class and a Bootstrapper derived class. Currently I have overloaded OnStartup

Here is my OnStartup code

protected override object GetInstance(Type serviceType, string key)
{
return base.GetInstance(serviceType, key);
}
Here is my WPF App.Xaml is calling it

<Application.Resources>
<ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
            <my:AppBootStrapper x:Key="bootstrapper" />
        </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Problem is, I noticed that Bootstrapper object is created but OnStartup is never called. Why ?

Do I have to do anything extra ?

New Post: Bootstrapper.OnStartup never called, following the Basic Configuration example in WPF

$
0
0
Found the issue, I was not calling Initialize() inside the ctor

New Post: Closing only one Window

$
0
0
I have one ViewModel and 2 Views for that ViewModel - "View" and "Detail".
First View is for displaying grid for all items and second is for displaying details of selected item where user can change or add new item.
I display first view with ShowDialog. After that I call ShowDialog for second View and everything works great.

But, if I try to close View when on "Detail" (with TryClose on ViewModel) I get error "Cannot set Visibility to Visible or call Show, ShowDialog, Close, or WindowInteropHelper.EnsureHandle while a Window is closing."

If I first get "Detail" view with GetView("Detail") and call Close on it, "View" is also closed.
I've tried to subscribe to View's closing event and set e.Cancel=true. In that case, "View" stays open, but it's removed from Views dictionary and TryClose or GetView do nothing.

Is there any way to change this behavior.
If i call Close on explicit View it shouldn't close all views associated with that ViewModel.

Created Unassigned: Null reference exception [364]

$
0
0
Hi,

We are seeing NullReferenceException in the production machine as soon as user logs off. It is happening intermittently at customer site and we are not able to reproduce in our environment. It is really frustrating. Anyone has seen this issue? What could be causing this?

Here is the exception:

Object reference not set to an instance of an object.

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Caliburn.Micro.ActionMessage.<.cctor>b__d(ActionExecutionContext context)
at Caliburn.Micro.ActionMessage.Invoke(Object eventArgs)
at System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
at System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs)
at System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
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.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
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.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(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 a

New Post: OnActive doesn't fire on VM if you navigate in OnInitialize method

$
0
0
Hello!
I have 3 VM: StartVM, ListItemsVM, ItemDetailsVM
Let\s say, I ran app from secondary tile and I need to open ItemDetailsVM with some Id. But I also need to open ListItemsVM for create navigation back entries stack.
So, in StartVM I do navigation:
 base.navigationService.UriFor<ListItemsVM>()
.WithParam(vm=>vm.ItemQueryParameter, 1)
.Navigate();
base.navigationService.RemoveBackEntry(); //drop StartVM from stack
Then, in ListItemsVM in OnInitialize method I navigated to ItemDetailsVM.
And there, if I do navigationService.GoBack in code or user tap Back button, I will return to the ListItemsVM and OnActive event won't fire because it had activated after my navigation to new VM.

I know that I could navigate to the ItemsDetailsVM and then open the ListItemsVM. It's not good for me now, but I'll do that if I won't have any other way,
I just interested can it be fixed in framework? Because it looks like a bug.
Thanks.

New Post: OnActive doesn't fire on VM if you navigate in OnInitialize method

$
0
0
Actually, how to delete navigation parameter in INavigationService? I've tried to replace Source in BackStack item but it still has one when I navigated back.

New Post: Caliburn action message swallows exceptions when working with async methods

$
0
0
The unhandled exception handler seems to fire if you change the action method to return void rather than Task

eg:
public async void BeginProcess()
{
    throw new Exception("Test");
}
I was always under the impression that async void was in most cases bad(TM) code, but it appears to be whats required in this case. Not sure why Caliburn doesn't handle both situations similarly.

New Post: Non-generic Bootstrapper obsolete?

$
0
0
This no longer seems to be current. Start is now called Initialize and the generic Bootstrapper<T> is gone.

New Post: Which samples can be used with WPF?

$
0
0
Hi,
Is there any instructions available how to port the samples so the work on WPF.
Even if the code are WPF compatible it seems some work are for sure needed to get the code running as a WPF example.

-Johan

New Post: IDataErrorInfo Not calling Item on property change.

$
0
0
I have to start by saying that this framework is awesome! I love using it. Great job!

I'm having an issue with IDataErrorInfo Item not being called when using Name convention binding on a context view.

I have a Button.Detail view like this:
<ContentControl cal:View.Model="{Binding ActiveItem}"
                        cal:View.Context="Detail" />
And my Detail view has these controls
<TextBox x:Name="Button_Path"
                     Width="218"
                     Margin="0,0,4,0"
                     VerticalAlignment="Center" />

  <TextBox Grid.Column="1"
                 Grid.Row="1"
                 Margin="3"
                 Text="{Binding Button.Name, Mode=TwoWay, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
                 VerticalAlignment="Center"
                 Width="70"
                 HorizontalAlignment="Left" />
Changing either one will cause PropertyChanged to fire but "Item" is only called for "Button.Name" but not for Button.Path.

This is my "Item" property in the VM
    Default Public ReadOnly Property Item(columnName As String) As String Implements IDataErrorInfo.Item
        Get
            Dim __ValidationResults = SelfValidate()
            If __ValidationResults Is Nothing Then
                Return String.Empty
            End If
            Dim __ColumnResults = __ValidationResults.Errors.FirstOrDefault(Function(x) String.Compare(x.PropertyName, columnName, True) = 0)
            Return If(__ColumnResults IsNot Nothing, __ColumnResults.ErrorMessage, String.Empty)
        End Get

    End Property
I have used the name convention binding many times with validation and have never had an issue. This is the first time I've tried it with a "Context" view. I'm sure it's something I'm doing wrong. Any ideas?

New Post: Methods for providing view model dependencies

$
0
0
The only way I have found to do what you're wanting to do is:

1) Include resolution of the container in the view's constructor and store the container internally
2) Resolve the view using Prism Region
3) In your view's Loaded event handler, use the container to resolve the view model and set that as your data context.

The drawback to this method are as follows:
1) You have to store the container reference internally and use it (not too bad)
2) You have to define an interface specific to the view model so it can be resolved
3) You don't get the benefit of design-time data context awareness when defining bindings to the data context, since the loaded event won't be called.

i.e.:
public interface IShellViewModel
{
    // No requirements
}

public partial class Shell : Window
{
    private IUnityContainer _container { get; set; }

    public Shell(IUnityContainer container)
    {
        _container = container;
        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        this.DataContext = _container.Resolve<IShellViewModel>();
    }
}

New Post: Methods for providing view model dependencies

$
0
0
The only way I have found to do what you're wanting to do is:

1) Include resolution of the container in the view's constructor and store the container internally
2) Resolve the view using Prism Region
3) In your view's Loaded event handler, use the container to resolve the view model and set that as your data context.

The drawback to this method are as follows:
1) You have to store the container reference internally and use it (not too bad)
2) You have to define an interface specific to the view model so it can be resolved
3) You don't get the benefit of design-time data context awareness when defining bindings to the data context, since the loaded event won't be called.

i.e.:
public interface IShellViewModel
{
    // No requirements
}

public partial class Shell : Window
{
    private IUnityContainer _container { get; set; }

    public Shell(IUnityContainer container)
    {
        _container = container;
        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        this.DataContext = _container.Resolve<IShellViewModel>();
    }
}

New Post: Nested View Activation

$
0
0
I have a similar situation, but the _nested property, instead of being set in the constructor, is exposed as a public property that can be changed, something like this:
public NestedViewModel Nested
{
            get
            {
                return this._nested;
            }
            set
            {
                if (this._nested!= value)
                {
                    if (this._nested!= null)
                    {
                        // How can undo this?
                        //this._nested.ConductWith(this);
                    }
                    this._nested= value;
                    if (this._nested!= null)
                    {
                        this._nested.ConductWith(this);
                    }
                    this.NotifyOfPropertyChange(() => this.Nested);
                }
            }
}
My point is that I need to undo the ConductWith(this) action from the old value of the _nested object when it gets replaced.
How ca i do that?

Thanks!

New Post: Error trying to convert Caliburn.Micro.HelloScreens sample to WPF

$
0
0
Hi,
Has this been solved? I have the same problem.
Please post the solution if you solved it.

New Post: Viewmodel not found

$
0
0
Hi,
I have simillar issue on Windows Phone 8 App. I found that TypeNameCache doesn't have any of ViewModels after injecting thats why It can't find the view model.
Viewing all 1760 articles
Browse latest View live


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