Skip to main content

Microsoft Silverlight

Answered Question how to bind page size to datagrid properties for auto page size?RSS Feed

(0)

kent.zhou
kent.zhou

Member

Member

110 points

403 Posts

how to bind page size to datagrid properties for auto page size?

 Suppose I have a viewmodel with page size property.Data is displayed in a datagrid. page size can be set dynamically based on the container for datagrid(maybe stackpanel or grid). So I wanto set pagesize like:

pagesize =(dataGrid.ActualHeight/DataGridRow.ActualHeight) - 1; 

In xaml, I have makup like

<UserControl.DataContext>
        <MyViewModel:ViewModel PageSize="100"/>
    </UserControl.DataContext>

With silverlight 3, it can be bind property to another element property, so I want to set dynamic page size in xaml like

         <MyViewModel:ViewModel PageSize="{Binding (dataGrid.ActualHeight/DataGridRow.ActualHeight) - 1 }"/>

How to write the binding for this purpose in xaml?

Ardman
Ardman

Contributor

Contributor

3434 points

946 Posts

Answered Question

Re: how to bind page size to datagrid properties for auto page size?

Could you create a struct that contains a PageSize property which works out what the pagesize should be and then Bind to the PageSize property?

Jonathan Shen – MSFT
Jonathan...

All-Star

All-Star

24992 points

2,435 Posts

Microsoft

Re: how to bind page size to datagrid properties for auto page size?

Hi Kent.zhou,

kent.zhou:
<MyViewModel:ViewModel PageSize="{Binding (dataGrid.ActualHeight/DataGridRow.ActualHeight) - 1 }"/>

Currently, this is not supported now.  We can use a Converter or Shared Property.

Best regards,

Jonathan

Jonathan Shen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

kent.zhou
kent.zhou

Member

Member

110 points

403 Posts

Re: how to bind page size to datagrid properties for auto page size?

 Thank you. If use converter for this pagesize, how to pass dataGrid.ActualHeight, DataGridRow.ActualHeight as param in to converter?

Could you please give me the demo xaml code for this case?

Jonathan Shen – MSFT
Jonathan...

All-Star

All-Star

24992 points

2,435 Posts

Microsoft

Re: how to bind page size to datagrid properties for auto page size?

Hi Kent.Zhou,

Silverlight 3 doesn't support the dynamic ConverterParameter.  Currently, we need to do it on code behind.  For example,

RadioStringConverter rsc = new RadioStringConverter();

Double expresion = (dataGrid.ActualHeight/DataGridRow.ActualHeight) - 1;
Binding binding = new Binding(layout.FieldName)

 { Source = mainLayout.DataContext, Mode = BindingMode.TwoWay,ConverterParameter = expresion ,Converter = (rsc as IValueConverter)};

Best regards,

Jonathan

Jonathan Shen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities