• 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();
            }
        }
    }
  • 相关阅读:
    echo "不允许上传该类型的文件
    php构造函数,引入数据库操作类函数
    php函数描述及例子
    php如何判断远程文件是否存在
    多线程面试题系列(16):多线程十大经典案例之一 双线程读写队列数据
    多线程面试题系列(15):关键段,事件,互斥量,信号量的“遗弃”问题
    多线程面试题系列(14):读者写者问题继 读写锁SRWLock
    多线程面试体系列(13):多线程同步内功心法——PV操作下
    多线程面试题系列(12):多线程同步内功心法——PV操作上
    多线程面试题系列(11):读者写者问题
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434671.html
Copyright © 2020-2023  润新知