Our team has gone through the sample codes for property status [PropertyStatus project] provided @ http://www.lhotka.net/cslanet/download.aspx and it is working as expected but the Property Status in MVVM sample [MVVMexperiment project] is failing
In one of our applications, we are using MVVM model, ViewModels are inherited from ViewModel Base Class and corresponding business objects are tied to the Model.
Whenever we are using PropertyStatus for the rule validation, we are getting the appropriate BrokenRulesCollection. But we were not successful in populating the validation messages in the UI as shown in the non MVVM sample application [PropertyStatus Project].
private void source_PropertyChanged(object sender, PropertyChangedEventArgs e)
Instead of the above method, our code is navigating to the method in ExtendedBindingList.cs
protected virtual void Child_PropertyChanged(object sender, PropertyChangedEventArgs e)
Please help us in inplementing PropertyStatus in our MVVM application. Let us know if more information is required to understand the issue better. Thanks
Tried with the latest version samples and the MVVM Experiment sample is not working. It is giving a Null reference exception in the line Line: var targetMethod = target.GetType().GetMethod(methodName); Method: private void CallMethod(object sender, EventArgs e) and the File is: InvokeMethod.cs.
Debgging shows the error is triggering from the line
csla:InvokeMethod.TriggerEvent="Loaded" in Window1.xaml
StackTrace for the error is also provided below. Please help
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Csla"
StackTrace:
at Csla.Wpf.InvokeMethod.CallMethod(Object sender, EventArgs e) in C:\User Created Folder\Cambridge Soft\Inventory\CAG\3.8\cslacs\Csla\Wpf\InvokeMethod.cs:line 230
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(Int32 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, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(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, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at MVVMexperiment.App.Main() in C:\User Created Folder\Cambridge Soft\Inventory\CSLA 3.8 Samples downloaded from Lhotka's site\CslaNet\cs\MVVMexperimentWpf\MVVMexperiment\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
This is the WPF sample right?
You are correct, there should not be a call to InvokeMethod in
the Window1 form declaration in the XAML. The XAML should read:
<Window x:Class="MVVMexperiment.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:this="clr-namespace:MVVMexperiment"
xmlns:csla="clr-namespace:Csla.Wpf;assembly=Csla"
Title="Window1" Height="480"
Width="640">
What is strange is that this doesn’t fail on my machine, but
does on yours. In any case, just remove that invalid line from the XAML and it
should be fine.
Dear Rocky,
We have downloaded the CSLA framework 3.8 as well as the new samples, specifically the MVVMExperimentWpf sample. Also we made sure that the following line was removed from Windows1.xaml
csla:InvokeMethod.TriggerEvent="Loaded"
When we enter an ID greater than 10 to break the corresponding business rule and click Process Item, it looks like validation is not being performed. Debugging shows that the BrokenRulesCollection is always empty. CheckRules methods in ValidationRules.cs are never been called.
Really appreciate it if you could take a look at it and let us know if we are missing something.
Thanks.
sg11:Rocky When running this sample, the only way I could get rid of the follwing error in the designer for ListPage.xaml "Object reference not set to an instance of an object", was by changing csla:PropertyStatus Margin="5" Property="{Binding Path=Model.Id}" to csla:PropertyStatus Margin="5" Property="{Binding Path=Id}" in effect changing Model.Id to Id. And either way, running the sample did not trigger a validation error. I was wondering if you might have a different set of goods on your machine. Thanks.
I just compared the code I'm using to the code in the release and it is the same. Here's the release code from my repository:
The controls are in a StackPanel, which has a DataContext pointing to the viewmodel object. Therefore the binding expressions on the individual controls must be Model.Id and Model.Name.
Please make sure you are using the release version of 3.8, not an earlier release. This project (in particular) was changing almost daily during the development process because (as you can guess from the name) this was my experimentation project for these features.
I certainly hope you don’t try to use MVVMexperiment as an
example of any good way to build an application!!
The title of the sample includes the word experiment.
This sample is nothing more than a way to experiment with some of the basic
ideas around MVVM and the use of InvokeMethod, Execute and ViewModel<T>.
It is absolutely not a complete app, and it certainly doesn’t
illustrate how you should really build an app!
The most you should try to get out of MVVMexperiment is the
basic usage of the new MVVM capabilities in 3.8.
Personally I never have regions of my forms enabled or visible
if there’s no underlying datacontext. Why would you do that in a real app?
Due to obvious reasons, I don’t want to change the code in PropertyStatus.cs. It would be helpful if you can provide some suggestions to overcome the issue? Or is it advisible to use the condition 'if ((binding != null) && (binding.DataItem != null))' in the SetSource method. Thanks.
Copyright (c) Marimer LLC