zoukankan      html  css  js  c++  java
  • WPF 视图导航

    <Window x:Class="ViewExam.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded_1">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>             
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <TextBlock>Model Number</TextBlock>
                <TextBox Text="{Binding Path=ModelNumber}" Grid.Column="1"></TextBox>
                <TextBlock Grid.Row="1">Model Name</TextBlock>
                <TextBox Text="{Binding Path=ModelName}" Grid.Column="1" Grid.Row="1"></TextBox>
                <TextBlock Grid.Row="2">Unit Cost</TextBlock>
                <TextBox Text="{Binding Path=UnitCost}" Grid.Column="1" Grid.Row="2"></TextBox>
                <TextBlock Grid.Row="3">Description</TextBlock>
                <TextBox Text="{Binding Path=Description}" TextWrapping="Wrap"  Grid.Row="5" Grid.ColumnSpan="2"></TextBox>
            </Grid>
            <StackPanel Grid.Row="1" Orientation="Horizontal">
                <Button Name="btnPrevious" Click="btnPrevious_Click_1">previous</Button>
                <Label x:Name="lblPosition" Width="400"></Label>
                <Button Name="btnNext" Click="btnNext_Click_1">Next</Button>
            </StackPanel>
        </Grid>
    </Window>


    using DBAccess;

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;


    namespace ViewExam
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }


            private ListCollectionView view;


            private void Window_Loaded_1(object sender, RoutedEventArgs e)
            {
                ICollection<Product> products = StoreDB.GetProducts();
                this.DataContext = products;
                view = (ListCollectionView)CollectionViewSource.GetDefaultView(products);


                view.CurrentChanged += view_CurrentChanged;

                view_CurrentChanged(this, null);
                
            }


            void view_CurrentChanged(object sender, EventArgs e)
            {
                lblPosition.Content = "Record " + (view.CurrentPosition + 1).ToString() + " of " + view.Count.ToString();
                btnPrevious.IsEnabled = view.CurrentPosition > 0;
                btnNext.IsEnabled = view.CurrentPosition < view.Count - 1;
            }


            private void btnPrevious_Click_1(object sender, RoutedEventArgs e)
            {
                view.MoveCurrentToPrevious();
            }


            private void btnNext_Click_1(object sender, RoutedEventArgs e)
            {
                view.MoveCurrentToNext();
            }
        }
    }
  • 相关阅读:
    火狐黑客插件
    使用POI对EXCEL 读入写出
    使用spring quartz实现定时任务
    toad for oracle 快捷键总结
    Oracle查询性能优化
    2.C语言中文网学习Python
    1.编程基础(C语言中文网)
    一键打开ASP.NET WEB网站项目
    解决VS2010无法添加Sql Server数据库的问题
    VS2010 的一个小Bug(已报告给Microsoft Connect并得到确认)
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434671.html
Copyright © 2011-2022 走看看