无法和DataPager和datagrid无法关联上。
xmal代码:
<data:DataGrid x:Name="mydata" AutoGenerateColumns="False">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="ID" Binding="{Binding FirstName}"></data:DataGridTextColumn>
<data:DataGridTextColumn Header="中国" Binding="{Binding LastName}"></data:DataGridTextColumn>
<data:DataGridTextColumn Header="Name" Binding="{Binding Age}"></data:DataGridTextColumn>
<data:DataGridTextColumn Header="Id2" Binding="{Binding IsMale}"></data:DataGridTextColumn>
</data:DataGrid.Columns>
</data:DataGrid>
<data:DataPager PageSize="4" x:Name="FirstLastPreviousNextNumeric" DisplayMode="FirstLastPreviousNextNumeric" Margin="0,0,0,4" HorizontalAlignment="Center" Source="{Binding ItemsSource,ElementName=mydata}"
/>
后台:
XDocument oDoc = XDocument.Load("File.xml");
var myData1 = from info in oDoc.Descendants("item")
select new Person
{
FirstName = Convert.ToString(info.Element("FirstName").Value),
LastName = Convert.ToString(info.Element("LastName").Value),
Age = Convert.ToString(info.Element("Age").Value),
IsMale = Convert.ToString(info.Element("IsMale").Value)
};
mydata.ItemsSource = myData1;
mydata.DataContext = myData1;
PagedCollectionView listview = new PagedCollectionView(myData1);
//FirstLastPreviousNextNumeric.Source = listview;
FirstLastPreviousNextNumeric.PageSize = 3;
FirstLastPreviousNextNumeric.DataContext = listview;
[解决办法]
你的datapager绑定有错误。
<data:DataPager PageSize="4" x:Name="FirstLastPreviousNextNumeric" DisplayMode="FirstLastPreviousNextNumeric" Margin="0,0,0,4" HorizontalAlignment="Center" Source="{Binding ItemsSource,ElementName=mydata}"
试这个:
<TextBlock Style="{StaticResource ApiDescription}" Text="FirstLastNumeric"/> <data:DataPager DisplayMode="FirstLastNumeric" Margin="0,0,0,4" HorizontalAlignment="Center" Source="{Binding}" NumericButtonCount="{Binding Value, ElementName=numericButtonCount}" AutoEllipsis="{Binding IsChecked, ElementName=autoEllipsis}" IsTotalItemCountFixed="{Binding IsChecked, ElementName=totalItemCountFixed}"/> <TextBlock Style="{StaticResource ApiDescription}" Text="FirstLastPreviousNext"/> <data:DataPager DisplayMode="FirstLastPreviousNext" Margin="0,0,0,4" HorizontalAlignment="Center" Source="{Binding}" NumericButtonCount="{Binding Value, ElementName=numericButtonCount}" AutoEllipsis="{Binding IsChecked, ElementName=autoEllipsis}" IsTotalItemCountFixed="{Binding IsChecked, ElementName=totalItemCountFixed}"/> <TextBlock Style="{StaticResource ApiDescription}" Text="FirstLastPreviousNextNumeric"/> <data:DataPager DisplayMode="FirstLastPreviousNextNumeric" Margin="0,0,0,4" HorizontalAlignment="Center" Source="{Binding}" NumericButtonCount="{Binding Value, ElementName=numericButtonCount}" AutoEllipsis="{Binding IsChecked, ElementName=autoEllipsis}" IsTotalItemCountFixed="{Binding IsChecked, ElementName=totalItemCountFixed}"/> <TextBlock Style="{StaticResource ApiDescription}" Text="Numeric"/> <data:DataPager DisplayMode="Numeric" Margin="0,0,0,4" HorizontalAlignment="Center" Source="{Binding}" NumericButtonCount="{Binding Value, ElementName=numericButtonCount}" AutoEllipsis="{Binding IsChecked, ElementName=autoEllipsis}" IsTotalItemCountFixed="{Binding IsChecked, ElementName=totalItemCountFixed}"/> <TextBlock Style="{StaticResource ApiDescription}" Text="PreviousNext"/> <data:DataPager DisplayMode="PreviousNext" Margin="0,0,0,4" HorizontalAlignment="Center" Source="{Binding}" NumericButtonCount="{Binding Value, ElementName=numericButtonCount}" AutoEllipsis="{Binding IsChecked, ElementName=autoEllipsis}" IsTotalItemCountFixed="{Binding IsChecked, ElementName=totalItemCountFixed}"/> <TextBlock Style="{StaticResource ApiDescription}" Text="PreviousNextNumeric"/> <data:DataPager DisplayMode="PreviousNextNumeric" Margin="0,0,0,4" HorizontalAlignment="Center" Source="{Binding}" NumericButtonCount="{Binding Value, ElementName=numericButtonCount}" AutoEllipsis="{Binding IsChecked, ElementName=autoEllipsis}" IsTotalItemCountFixed="{Binding IsChecked, ElementName=totalItemCountFixed}"/> <CheckBox x:Name="autoEllipsis" Content="AutoEllipsis" Margin="4"/> <CheckBox x:Name="totalItemCountFixed" Content="IsTotalItemCountFixed" IsChecked="True" Margin="4"/>