PropertyInfo & WinRT

PropertyInfo & WinRT

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


TSF posted on Thursday, September 13, 2012

I'm trying to use the PropertyInfo control in a WinRT app, and I can't get the binding to work correctly.  I want to bind another control's appearance to the IsValid meta data for a BO property that the PropertyInfo control exposes. The problem is that the binding is triggered only once when the page is first loaded. Updating the BO's property via the UI doesn't trigger the PropertyInfo binding.  My XAML is below.  (Note - my ViewModelBase class is set as the page's DataContext, so "Model" below should refer to the actual business object.)

 I have tried the following four syntax variations for PropertyInfo:

<csla:PropertyInfo x:Name="piField1" Source="{Binding Model}" Property="{Binding Model.Field1}"/>

<csla:PropertyInfo x:Name="piField1" Source="{Binding Model}" Property="{Binding Field1}"/>

<csla:PropertyInfo x:Name="piField1" Property="{Binding Model.Field1}"/>

<csla:PropertyInfo x:Name="piField1" Property="{Binding Field1}"/>

I want to bind a Border element to the IsValid property exposed by the PropertyInfo control, as follows:

<Border BorderBrush="Red" BorderThickness="{Binding ElementName=piField1, Path=IsValid, Converter={StaticResource ValidationToBorderConverter}}" Margin="0,5,0,0" >
    <TextBox Name="tbField1" Text="{Binding Model.Field1, Mode=TwoWay}" />
</Border>

RockfordLhotka replied on Thursday, September 13, 2012

WinRT is missing some features used by the 'modern' PropertyInfo control in WPF/SL. The WinRT version of PropertyInfo uses an implementation more similar to what we did for Silverlight 2.0, which was also missing these features.

As a result, the Property property can't be a binding expression, it must be the string name of the property

Property="Field1"

As you note, you do need to set the Source property to a binding expression that resolves to the business object.

skagen00 replied on Friday, September 14, 2012

My mistake, talking about propertyinfo in the post above, I was thinking it was propertystatus.

Does propertystatus have the same issue?

RockfordLhotka replied on Friday, September 14, 2012

Yes, PropertyInfo and PropertyStatus (and TriggerAction) all have the same issue.

For those interested, the issue is that there's no API to get access to the Binding object for a bound property in a control. As a result, we can't get the binding and then find the binding's source and path like in WPF or SL3+. Instead, the XAML must directly provide the control with the source and the path (as a string).

Hence the Source property being required, and the Property property being a string value that must contain the path to the property.

Copyright (c) Marimer LLC