Question about the template of the DataGrid

Source: Internet
Author: User

Recently, Silverlight 5 beta was released. As a developer focusing on Silverlight, I am still very happy. At least it proves that Sl is still being improved and still developing.

This post is mainly used to solve the common problems in datagrid development:

When scrollview appears in the DataGrid, if you drag it, you will find that the checkbox and expander in the DataGrid will be disordered.

You can effectively solve this problem by adding a datagridrowspresenter to the scrollview in the template of the DataGrid:

 
<Scrollviewer >

<SDK: datagridrowspresenter X: Name= "Rowspresenter" />

</Scrollviewer>

DetailsCodeIt will not be pasted,: datagridscrollview.rar

Remove the DataGrid style and test it.

In actual situations, we may need to process records when the value is 0. Here we provide a method

here, the template of the DataGrid is modified, and The xaml of the datagridrowspresenter section is found.

<SDK: datagridrowspresenter X: Name= "Rowspresenter" Grid.Columnspan= "2" Grid.Row= "1" />

Replace it:

<Grid Grid.Columnspan= "2" Grid.Row= "1" >

<SDK: datagridrowspresenter X: Name= "Rowspresenter"/>

<Textblock Text= "No related records" 

Visibility= "{Binding elementname = rowspresenter, Path = children. Count, converter = {staticresource norecordsconverter }}" 

Horizontalalignment= "Center" Verticalalignment= "Center" Fontsize= "12"/>

</Grid>

We can see that it is binding the children attribute of the datagridrowspresenter object.

Code of the value converter section:

Public ObjectConvert (Object Value, Type targettype,ObjectParameter, cultureinfo Culture)

{

Return Value. Tostring () ="0"? Visibility. Visible: visibility. collapsed;

}

 
 

Public ObjectConvertback (Object Value, Type targettype,ObjectParameter, cultureinfo Culture)

{

 
Return Null;

}

This article is written here. I hope these two useful skills will help you with your ideas.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.