how to use PropertyStatus in CSLA3.8

how to use PropertyStatus in CSLA3.8

Old forum URL: forums.lhotka.net/forums/t/7844.aspx


HenryYu posted on Wednesday, October 21, 2009

Hi folks,

 

Nice to see you,our team are using your CSLA, and I am using Csla3.8 for Wpf binding, I have a problem when I used PropertyStatus in defining my CreateContainer view like this(it is metioned in http://www.lhotka.net/cslabugs/edit_bug.aspx?id=492):

<csla:PropertyStatus Property="{Bindin Path=Model.LocationId,Mode=TwoWay}"  TargetControl="{Binding ElementName=LocationIdTextBox}" />

 

But when I  executed this statement to get my defined view: createContainerWin.Content = _container.Resolve<IContainerEditViewModel>().View;

It throw an exception(Resolution of the dependency failed, type = "CambridgeSoft.COE.Inventory.Modules.ContainerModule.Interfaces.IContainerEditViewModel", name = "". Exception message is: The current build operation (build key Build Key[CambridgeSoft.COE.Inventory.Modules.ContainerModule.ContainerActions.ContainerEditViewModel, null]) failed: Object reference not set to an instance of an object. (Strategy type BuildPlanStrategy, index 3)which seemed like the progress creating view,Also I found the true reason is about this using way :PropertyStatus Property="{Bindin Path=Model.LocationId,Mode=TwoWay}".(Since I uncommented this statement,the codes run)

 

So which way can I use if I want to implement the validation of Property using PropertyStatus?

Fintanv replied on Thursday, October 22, 2009

Just to get this out of the way, but I notice that twice in your post you use "Bindin" instead of "Binding" with reference to the PropertyStatus declaration.  Is this a mistake in your code or just in this posting?

RockfordLhotka replied on Thursday, October 22, 2009

You are saying that it works when you remove the TargetControl property so PropertyStatus isn't trying to manipulate the TextBox control?

RockfordLhotka replied on Thursday, October 22, 2009

I think you are using Beta 1?

I do think there was a bug in Beta 1 when using dot notation to index into a property.

If you are trying to use Beta 1 for anything but testing, that is probably a mistake. Since you say this is urgent, you are probably trying to use it for more than testing :(

However, Beta 2 should be available in the next few days. I am mostly waiting to find out if the BusyAnimation bug has been resolved, and then I will release Beta 2.

I think (but I don't know for sure) that it will fix your problem.

You can always pull the latest code from the svn repository and see if your problem has been fixed. The svn path is svn://svn.lhotka.net/csla/core/branches/V3-8-x.

HenryYu replied on Thursday, October 22, 2009

Thanks for your reply,but I could not access the svn://svn.lhotka.net/csla/core/branches/V3-8-x,

could you tell me the way to access it?

RockfordLhotka replied on Thursday, October 22, 2009

http://www.lhotka.net/cslanet/Repository.aspx

 

HenryYu replied on Friday, October 23, 2009

Hi Rocky,

 I think our team is using 3.8 alpha version, not the beta1 version,

Also I differ the different version in  http://www.lhotka.net/cslanet/Repository.aspx

I tried to find the your fix codes about PropertyStatus in this link, but I found that there are not any changes about in PropertyStatus between the version(svn://svn.lhotka.net/csla/core/branches/V3-8-x) and the 3.8 alpha version(which our team is just using).

 

In other word, the PropertyStatus.cs in the 3.8 alpha version(which our team is just using) is the latest version code base on your changes logs in the link I metioned.

HenryYu replied on Friday, October 23, 2009

also I differ the  difference from the three version

Revision4288 Revision4271 Revision4267 in link

http://www.lhotka.net/cslacvs/viewvc.cgi/core/branches/V3-8-x/cslacs/Csla/Wpf/PropertyStatus.cs?view=log#rev4267

I found that the PropertyStatus  codes in 3.8 alpha(which version I am just using) is same as the codes in Revision4288. (i.e. I think maybe there is a small bug in PropertyStatus needed to be fixed)

This is an urgent problem, thanks for you help.

RockfordLhotka replied on Friday, October 23, 2009

> This is an urgent problem, thanks for you help.

 

How can you have an urgent problem with alpha code?

 

If this is really urgent then you need to help me. Remember that CSLA .NET is free, which means there’s no support (unless you’d like to pay for it).

 

You can create a small repro of this problem that occurs on Beta 1 – and by small I mean something you can put in a zip file that I can unzip, build and run without having to download dependencies, etc. To do this you’ll need to replicate the issue without using your DI framework – I don’t have time to sift through complex UI/config code. In other words, I’m not going to get pulled into debugging interactions with some random UI framework that’s not included in the .NET standard install.

 

If you get me such a repro I’ll look at it and try to identify/fix the issue.

RockfordLhotka replied on Friday, October 23, 2009

Actually the simplest thing for you and me is if you can take the MVVMexperiment solution (SL or WPF) and get it to fail.

This app already uses the "Model.Property" syntax with PropertyStatus. And you can easily change the DataListViewModel constructor to not create an instance of the Model, which means it will be null.

But that works - having a null Model value is perfectly acceptible - so I'm having a hard time understanding or replicating your issue.

RockfordLhotka replied on Friday, October 23, 2009

Hmm. I thought perhaps the problem was that the DataContext itself was null. But that doesn't trigger the problem either - I just created a simple XAML form that uses PropertyStatus with dot notation for the property name, with no DataContext at all:

<UserControl x:Class="SilverlightApplication3.MainPage"
            xmlns:csla="clr-namespace:Csla.Silverlight;assembly=Csla"
            mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
  <Grid x:Name="LayoutRoot">
    <StackPanel>
      <StackPanel Orientation="Horizontal">
        <TextBox Text="{Binding Path=Model.Name, Mode=TwoWay}" Width="150" Margin="5"/>
        <csla:PropertyStatus Property="{Binding Path=Model.Name}" Margin="5" />
      </StackPanel>
      <StackPanel Orientation="Horizontal">
        <TextBox Text="{Binding Path=Model.City, Mode=TwoWay}" Width="150" Margin="5"/>
        <csla:PropertyStatus Property="{Binding Path=Model.City}" Margin="5" />
      </StackPanel>
    </StackPanel>
  </Grid>
</UserControl>

Clearly when this form is initialized it will create the PropertyStatus controls along with the TextBox controls, and DataContext is null, because it is never set to anything (there's not even a business class in this project).

But this works fine too - so DataContext being null is OK, and Model being null is OK (based on the MVVMexperimentSL project).

So I'm really at a loss as to what your app is doing to get something to be null...

Halil replied on Thursday, December 10, 2009

I am able to recreate this issue. The key is to set the DataContext after the control has been initialized. The null reference is encountered in the GetRealSource(object source, string bindingPath) method in the PropertyStatus control. The source parameter is null.

namespace CSLA3._8._2_PropertyStatusFail
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            // does not fail when first setting data context
            //DataContext = this;

            InitializeComponent();
           
            DataContext = this;
        }
    }
}

<Window x:Class="CSLA3._8._2_PropertyStatusFail.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1"
        Height="300"
        Width="300"
        xmlns:csla="clr-namespace:Csla.Wpf;assembly=Csla">
    <Grid>
        <csla:PropertyStatus Property="{Binding Path=XXXX.YYYY}" />
    </Grid>
</Window>

Halil

RockfordLhotka replied on Thursday, December 10, 2009

Thank you, that is very helpful information!

McManus replied on Saturday, October 24, 2009

Hi,

I noticed a typo in the XAML. The Bindin is missing a "g" (should be Binding).

HTH,
Herman

Copyright (c) Marimer LLC