views:

309

answers:

2

The DescriptionViewer part of the DataField is used to display the Description property of the System.ComponentModel.DisplayAttribute as a ToolTip in the generated form. I don't want to use this capability and although I can make sure the UI element is not visible by using a style to set either the DescriptionViewerVisibility to Collapsed or by setting the DescriptionViewerStyle to be null as shown below, there is still space reserved in the DataField layout for this element.

<Style x:Key="DataFieldStyle1" TargetType="dataFormToolkit:DataField">
    <Setter Property="DescriptionViewerVisibility" Value="Collapsed"/>
    <Setter Property="DescriptionViewerStyle" Value="{x:Null}" />
</Style>

This space is as waste in my scenario and I want to get rid of it. I would expect this layout to be exposed by the DataField.Template property but when I use Blend to edit a copy of the default template the layout is not there.

I'm using the System.Windows.Controls.Data.DataForm.Toolkit, Version=2.0.5.0 from the October 2009 release of the Silverlight Toolkit within a WCF RIA Services Beta Business Application Silverlight 3 project. I'm using Visual Studio 2008 SP1. I know there is a November 2009 release but I can't see any mention of this changing in the release notes.

A: 

Using Reflector I can see that the DataField.OnApplyTemplate method calls a private method called GenerateUI, which uses conventional code to create a Grid with a Column for the DescriptionViewer, and I can't see a way to prevent this, without doing some very low level .NET clr kind of hack which would be inappropriate. Am I missing something here?

I'm starting to come to the conclusion that you either need to stick very close to the default behaviour of these Silverlight Toolkit controls if you want to benefit from the supposed productivity gains. Anything more that pretty trivial customisation seems to be an incomplete story at the moment.

Martin Hollingsworth
+1  A: 

An alternative solution is to use DataForm Label and a control to display your field.

Instead of using a DataField like this and eventually having space for DescriptionViewer

<dataControls:DataField>
    <TextBox Text="{Binding FirstName, Mode=TwoWay}" />
</dataControls:DataField>

You can use this code, and you will not have the DescriptionViewer

<dataInput:Label Target="{Binding ElementName=tbFirstName}" />
<TextBox x:Name="tbFirstName" Text="{Binding FirstName, Mode=TwoWay}" />

With this solution, you will loose the generated layout that come with the DataForm but you can do it easily with a simple Grid

Zied
That sounds like a good idea. Does the DataField provide any other value besides adding the Label and DescriptionViewer that I would lose and need to implement myself? I would expect there would be some Validation behaviour that is implemented by the DataField control.
Martin Hollingsworth
This solution also requires you to implement the visual and behaviour for other DataAnnotation attributes like ReadOnly and Required.
Martin Hollingsworth
The Required DataAnnotation works.For the ReadOnly I didn't test it yet. Other DataAnnotation works too like Display for example.
Zied