Skip to main content
Home Forums General Silverlight New Features in Silverlight 3 how to bind page size to datagrid properties for auto page size?
4 replies. Latest Post by Jonathan Shen – MSFT on November 2, 2009.
(0)
kent.zhou
Member
110 points
403 Posts
10-22-2009 2:28 PM |
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
Contributor
3434 points
946 Posts
10-23-2009 3:48 AM |
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...
All-Star
24992 points
2,435 Posts
10-29-2009 11:29 PM |
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
10-30-2009 12:45 PM |
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?
11-02-2009 2:52 AM |
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)};