0

I have just started using Catel for a WPF application and I am having a few problems.

1) When a button cannot execute I do not see the button grayed out as per the documentation.

2) Where do I put code to persist values to a database - in the ViewModel or Model. Is there an example anywhere?

3) Is there an example of using a menu in a main page and loading user controls on the click of menu items?

4) When I set the DeferValidationUntilFirstSaveCall = true in the constructor of my ViewModel I get an exception when the dialog window shows up. The exception is as follows

System.NullReferenceException was unhandled by user code
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=Catel.MVVM
  StackTrace:
       at Catel.Windows.Data.Converters.GetFirstValidationErrorConverter.Convert(Object value, Type targetType, Object parameter)
       at Catel.Windows.Data.Converters.ValueConverterBase.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
       at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
       at System.Windows.Data.BindingExpression.Activate(Object item)
       at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
       at System.Windows.Data.BindingExpression.AttachOverride(DependencyObject target, DependencyProperty dp)
       at System.Windows.Data.BindingExpressionBase.OnAttach(DependencyObject d, DependencyProperty dp)
       at System.Windows.StyleHelper.GetInstanceValue(UncommonField`1 dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, Int32 childIndex, DependencyProperty dp, Int32 i, EffectiveValueEntry& entry)
       at System.Windows.StyleHelper.GetChildValueHelper(UncommonField`1 dataField, ItemStructList`1& valueLookupList, DependencyProperty dp, DependencyObject container, FrameworkObject child, Int32 childIndex, Boolean styleLookup, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
       at System.Windows.StyleHelper.GetChildValue(UncommonField`1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
       at System.Windows.StyleHelper.GetValueFromStyleOrTemplate(FrameworkObject fo, DependencyProperty dp, EffectiveValueEntry& entry)
       at System.Windows.StyleHelper.ApplyStyleOrTemplateValue(FrameworkObject fo, DependencyProperty dp)
       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.Controls.TextBox.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.FrameworkElement.OnInitialized(EventArgs e)
       at System.Windows.FrameworkElement.TryFireInitialized()
       at System.Windows.FrameworkElement.EndInit()
       at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
       at MS.Internal.Xaml.Runtime.PartialTrustTolerantRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
       at System.Xaml.XamlObjectWriter.Logic_EndInit(ObjectWriterContext ctx)
       at System.Xaml.XamlObjectWriter.WriteEndObject()
       at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
       at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
       at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at FNZCIressClient.Views.AccountMappingWindow.InitializeComponent() in h:\Documents\iress-utils\FNZCIressClient\FNZCIressClient\Views\AccountMappingWindow.xaml:line 1
       at FNZCIressClient.Views.AccountMappingWindow..ctor(AccountMappingViewModel viewModel) in h:\Documents\iress-utils\FNZCIressClient\FNZCIressClient\Views\AccountMappingWindow.xaml.cs:line 28
  InnerException: 

If I remove the defervalidation line from the code, the pop-up works.

Any help and advice appreciated.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Alan Rutter
  • 321
  • 4
  • 16

1 Answers1

0

1) Take a look at the examples repository, it has a lot of examples.

2) Override the Save() method

3) Use the UIVisualizerService or Prism to dynamically load regions

4) I will look into this. Are you just using the DataWindow or a custom one?

Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32
  • 1) When I run the Catel.WPF.PersonApplication from the Examples none of the buttons are grayed out there either. Am I missing something? 2)In the ViewModel? I don't see any methods in the Model ever being called 3)I used a control template as per the MyMediaStuff demo 4) Just a normal DataWindow – Alan Rutter Aug 07 '13 at 20:29
  • I am also trying to use Catel with BrightstarDB. BrightStarDB generates a partial class for each entity which has its own properties for each field in the interface/class. These clash with the properties that are used for Catel via the modelprop snippets. Do you have any ideas how I can combine BrighstarDB with Catel? – Alan Rutter Aug 08 '13 at 00:09
  • Please try newer demos. The "MyMediaStuff" is really old, all the latest examples are kept up to date in the Examples repository. The PersonApplication does gray out when nothing is selected (the Edit button should be disabled when no person is selected). As long as the BrighstarDB implement INotifyPropertyChanged (and preferrable IEditableObject) it will work just fine. – Geert van Horrik Aug 08 '13 at 06:34
  • I just downloaded the latest Catel.Examples repo. I modified the Debug config to only build the Catel.Examples.WPF.Models and Catel.Examples.WPF.PersonApplication. It built without errors. When run, with nothing at all selected, the Edit and Remove buttons are NOT grayed out. – Alan Rutter Aug 08 '13 at 23:46
  • See https://dl.dropboxusercontent.com/u/8455721/StackOverflow/18092362_disabledbuttons.png, they are disabled. Maybe they are not grayed out, but still disabled. – Geert van Horrik Aug 09 '13 at 07:14
  • Thanks Geert for your patience. Maybe I misread the documentation but I thought the pixel shader was automatic and would gray out the image if disabled. – Alan Rutter Aug 11 '13 at 20:21
  • True, but apparently it doesn't work ATM. Anyway, the commands do work :) – Geert van Horrik Aug 12 '13 at 06:44