Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
public partial class Window1 : Window
{
private WpfDataNavigationApplication.NorthwindEntities northwindEntities = new WpfDataNavigationApplication.NorthwindEntities();
private System.Windows.Data.CollectionViewSource employeesViewSource__NorthwindEntities;
System.Data.Objects.ObjectQuery<WpfDataNavigationApplication.Employee> employeesQuery;
private int totalRowCount;
public Window1()
{
InitializeComponent();
}
private System.Data.Objects.ObjectQuery<Employee> GetEmployeesQuery(NorthwindEntities northwindEntities)
{
// Auto generated code
System.Data.Objects.ObjectQuery<WpfDataNavigationApplication.Employee> employeesQuery = northwindEntities.Employees;
// Returns an ObjectQuery.
return employeesQuery;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
employeesViewSource__NorthwindEntities = ((System.Windows.Data.CollectionViewSource)(this.FindResource("employeesViewSource__NorthwindEntities")));
employeesQuery = this.GetEmployeesQuery(northwindEntities);
employeesViewSource__NorthwindEntities.Source = employeesQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
totalRowCount = northwindEntities.Employees.Count();
totalRowCountLabel.Content = totalRowCount;
UpdateNavigatorUI();
}
private void GoToFirstButton_Click(object sender, RoutedEventArgs e)
{
employeesViewSource__NorthwindEntities.View.MoveCurrentToFirst();
UpdateNavigatorUI();
}
private void GoToPreviousButton_Click(object sender, RoutedEventArgs e)
{
employeesViewSource__NorthwindEntities.View.MoveCurrentToPrevious();
UpdateNavigatorUI();
}
private void GoToNextButton_Click(object sender, RoutedEventArgs e)
{
employeesViewSource__NorthwindEntities.View.MoveCurrentToNext();
UpdateNavigatorUI();
}
private void GoToLastButton_Click(object sender, RoutedEventArgs e)
{
employeesViewSource__NorthwindEntities.View.MoveCurrentToLast();
UpdateNavigatorUI();
}
private void GoButton_Click(object sender, RoutedEventArgs e)
{
int position;
int.TryParse(goTextBox.Text, out position);
if (position > 0 && position <= totalRowCount)
{
employeesViewSource__NorthwindEntities.View.MoveCurrentToPosition(position - 1);
}
else
{
MessageBox.Show("The input index is not valid.");
}
}
private void SetGoTextBoxOnCurrentPosition()
{
goTextBox.Text = (employeesViewSource__NorthwindEntities.View.CurrentPosition + 1).ToString();
}
private void SetButtonIsEnabled()
{
bool isFirst = (employeesViewSource__NorthwindEntities.View.CurrentPosition == 0);
bool isLast = employeesViewSource__NorthwindEntities.View.CurrentPosition > (totalRowCounts - 1);
goToFirstButton.IsEnabled = goToPreviousButton.IsEnabled = !isFirst;
goToNextButton.IsEnabled = goToLastButton.IsEnabled = !isLast;
}
private void UpdateNavigatorUI()
{
SetGoTextBoxOnCurrentPosition();
SetButtonIsEnabled();
}
}
Comments
- Anonymous
February 21, 2013
Hello Xiaoying Guo I am totally new to WPF. So can you please help me how did you get WpfDataNavigationApplication? Is it a function present in some namespace?