English 中文(简体)
Reclaiming the space from the DescriptionViewer part of the DataFields on a Silverlight Toolkit DataForm
原标题:

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.

最佳回答

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

问题回答

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.





相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签