Workarounds for dataform bugs

by StefanOlson 6. August 2009 09:29

Unfortunately the dataform that was shipped with Silverlight 3 RTW (in the Toolkit) was massively changed from the beta version, and as a result has a number of bugs that were not there during the beta.

To find these bugs create a new project using the business application template, and run it.  Click login, type some text into Username and then click OK and you will see the following screen:

image You will note that there are two problems with this screen:

1. the first one is that the data form has become opaque

2. the second one is the fact that the password and confirm password, which are required fields are not marked in red.

3. If you add in a checkbox as a label and click OK, you get this screen:

image

Workarounds

1. This bug is caused because the DataForm doesn’t listen for IsEnabledChanged, but in the UpdateStates() function will call GoToState to change for the disabled state. Unfortunately if it doesn't go back and to update states after if you enable, you're left in the disabled state. The workaround is to create a derived class that looks like this and use it in place of the dataform:

public class LessBuggyDataForm:DataForm
   {
       private const string DATAFORM_stateDisabled = "Disabled";
       private const string DATAFORM_stateNormal = "Normal";

       public override void OnApplyTemplate()
       {
           IsEnabledChanged += LessBuggyDataForm_IsEnabledChanged;
           base.OnApplyTemplate();
       }

       void LessBuggyDataForm_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
       {
           if (!IsEnabled)
           {
               VisualStateManager.GoToState(this, DATAFORM_stateDisabled, true);
           }
           else
           {
               VisualStateManager.GoToState(this, DATAFORM_stateNormal, true);
           }
       }
   }

 

2.  I'm not entirely sure why this bug is caused. What happens is that unless the password text is updated, the validation doesn't seem to occur. Therefore, the workaround is every time you want to force validation to happen. You need to call a function like this in the password control:

public void UpdatePasswordText()
        {
            this.PasswordText = this.password.Password;
        }

Normally you'd call this before you call ValidateItem() or CommitEdit()

3. This problem is caused by the fact that when you click the okay button, CancelEdit() is called, which completely rebuilds the label. The exception is because checkbox is already the child of another control, and it tries to make it a child of the new label.

The workaround is to stop the ability to cancel the editing like this:

registerForm.EditEnding += new EventHandler<DataFormEditEndingEventArgs>(registerForm_EditEnding);
}

void registerForm_EditEnding(object sender, DataFormEditEndingEventArgs e)
{
    if (e.EditAction==DataFormEditAction.Cancel)
    {
        e.Cancel = true;
        return;
    }
}

Hopefully these solutions will save someone else some time.

…Stefan

Tags:

Silverlight

Bugs fixed (or not) in Silverlight 3 RTW

by StefanOlson 3. August 2009 09:30

As I did after the Silverlight 2 release, I thought it would be a good idea to review the bugs that I have submitted, to see what progress is. It's taken me a while to get this done because I've been busy with other things.

Four of the bugs are fixed. Unfortunately, the Silverlight team are very poor at communicating the status of bugs - often bugs will be closed then opened and then closed again and there's often never any explanation as to whether the bug is ever going to be fixed.  The majority of these issues are in situations where you would expect things to work - they do work correctly WPF but don't work in Silverlight.  In some cases, I suspect that this is because of the internal structures in Silverlight - hopefully these will be resolved soon, but I'm not holding my breath.

Suggestion implemented:

#373013 BindingOperations should be included in Silverlight (partially implemented)

Fixed:

#378419 Assigning new content to a ContentControl clears other controls in the template in Silverlight

#470822 Image.source with no source set is not null

#461978 ItemContainerStyle gets incorrectly applied within a control template

#458014 Changing title on page just does not change title on title bar

Apparently By Design:

#377494 ToggleButton doesn't display the IsChecked visual state correctly

#377655 Referencing an image via a relative path in generic.xaml causes exception in Silverlight

Not Fixed:

#373116 ToolTip causes ArgumentException

#373957 Value does not fall within the expected range assigning PointCollection in Silverlight

#377171 Using a path style from app.xaml fails the second time in Silverlight

#425334 Binding to ActualWidth ignores changes in Silverlight

#428412 Linked files in folders are not output correctly in SL 3

#459475 ImageBrush ImageSource binding parsing error

#460375 Silverlight doesn't work correctly with multiple resource dictionaries

#462271 Binding to Items.Count doesn't work

#469091 Referencing an image in a custom control which is a RootVisual will not load the image

#473411 Set Uri as "" in xaml not consistent with WPF

#475639 Silverlight should support nullable dependency properties (filed after SL 3 RTW)

Tags:

Silverlight

Updates to the Custom and Authenticating URI Mappers for Silverlight 3 RTW

by StefanOlson 3. August 2009 08:51

Update: I'd forgotten to update the sample that goes along with the download. It has now been updated to support the .net RIA services July CTP.

I’ve received a couple of requests in the past few days asking if there will be an update to the URI mappers (Updates to custom routing using the Uri Mapper in Silverlight 3 and Displaying a login dialog based on page attributes in Silverlight 3) that work with the Silverlight 3 RTW & .net RIA services July CTP. 

The CustomUriMapper works just fine with Silverlight 3. However, I have fixed one bug and provided a project you can include in your solution to make it easy to use it. You can find it under UriMapper\AuthenticatingUriMapper\CustomUriMapper.csproj.

Unfortunately I had forgotten that changes were required to get the AuthenticatingUriMapper working with the July CTP and had neglected to update it on the website.

Download

You can download the latest source code and example here.

…Stefan

Tags:

.net ria services | Silverlight

About the author

Stefan Olson is the Managing Director of Olson Software.  He has been developing software using Microsoft Technologies for nearly 20 years.

He is currently working on building the next generation Virtual Tour software in WPF and Silverlight for www.palacevirtualtours.com.