• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IEditableCollectionViewAddNewItem接口代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.ComponentModel.IEditableCollectionViewAddNewItem接口的典型用法代码示例。如果您正苦于以下问题:C# IEditableCollectionViewAddNewItem接口的具体用法?C# IEditableCollectionViewAddNewItem怎么用?C# IEditableCollectionViewAddNewItem使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。



IEditableCollectionViewAddNewItem接口属于System.ComponentModel命名空间,在下文中一共展示了IEditableCollectionViewAddNewItem接口的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Window1

//引入命名空间
using System;
using System.ComponentModel;
using System.Windows;

namespace IEditableCollectionViewAddItemExample
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            IEditableCollectionViewAddNewItem viewToAddDisparateItems =
                catalogList.Items as IEditableCollectionViewAddNewItem;

            if (!viewToAddDisparateItems.CanAddNewItem)
            {
                MessageBox.Show("You cannot add items to the list.");
                return;
            }

            // Create a window that prompts the user to enter a new
            // item to sell.
            AddItemWindow win = new AddItemWindow();

            // Create an item, depending on which RadioButton is selected.
            // Radio buttons correspond to book, cd, dvd, or other.
            LibraryItem newItem;

            if ((bool)book.IsChecked)
            {
                newItem = new Book("Enter the book title", "Enter an Author", "Enter a Genre",
                    "Enter a call number", DateTime.Now + new TimeSpan(21, 0, 0, 0));
            }
            else if ((bool)cd.IsChecked)
            {
                newItem = new MusicCD("Enter the Album", "Enter the artist", 0, "CD.******",
                    DateTime.Now + new TimeSpan(14, 0, 0, 0));
            }

            else if ((bool)dvd.IsChecked)
            {
                newItem = new MovieDVD("Enter the movie title", "Enter the director",
                    "Enter the genre", new TimeSpan(), "DVD.******",
                    DateTime.Now + new TimeSpan(7, 0, 0, 0));
            }
            else
            {
                newItem = new LibraryItem("Enter the title", "Enter the call number",
                        DateTime.Now + new TimeSpan(14, 0, 0, 0));
            }

            // Add the new item to the collection by calling
            // IEditableCollectionViewAddNewItem.AddNewItem.
            // Set the DataContext of the AddItemWindow to the
            // returned item.
            win.DataContext = viewToAddDisparateItems.AddNewItem(newItem);

            // If the user submits the new item, commit the new
            // object to the collection.  If the user cancels 
            // adding the new item, discard the new item.
            if ((bool)win.ShowDialog())
            {
                viewToAddDisparateItems.CommitNew();
            }
            else
            {
                viewToAddDisparateItems.CancelNew();
            }
        }
    }
}
开发者ID:.NET开发者,项目名称:System.ComponentModel,代码行数:76,代码来源:IEditableCollectionViewAddNewItem


示例2: AddItemWindow

//引入命名空间
using System.Windows;
using System.Windows.Controls;

namespace IEditableCollectionViewAddItemExample
{
    public partial class AddItemWindow : Window
    {
        public AddItemWindow()
        {
            InitializeComponent();
        }

        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }

        // Select all text when the TextBox gets focus.
        private void TextBoxFocus(object sender, RoutedEventArgs e)
        {
            TextBox tbx = sender as TextBox;

            tbx.SelectAll();
        }
    }
}
开发者ID:.NET开发者,项目名称:System.ComponentModel,代码行数:28,代码来源:IEditableCollectionViewAddNewItem


示例3: LibraryItem

//引入命名空间
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace IEditableCollectionViewAddItemExample
{
    // LibraryItem implements INotifyPropertyChanged so that the 
    // application is notified when a property changes.  It 
    // implements IEditableObject so that pending changes can be discarded.
    public class LibraryItem : INotifyPropertyChanged, IEditableObject
    {
        struct ItemData
        {
            internal string Title;
            internal string CallNumber;
            internal DateTime DueDate;
        }

        ItemData copyData;
        ItemData currentData;

        public LibraryItem(string title, string callNum, DateTime dueDate)
        {
            Title = title;
            CallNumber = callNum;
            DueDate = dueDate;
        }

        public override string ToString()
        {
            return String.Format("{0}, {1:c}, {2:D}", Title, CallNumber, DueDate);
        }

        public string Title
        {
            get { return currentData.Title; }
            set
            {
                if (currentData.Title != value)
                {
                    currentData.Title = value;
                    NotifyPropertyChanged("Title");
                }
            }
        }

        public string CallNumber
        {
            get { return currentData.CallNumber; }
            set
            {
                if (currentData.CallNumber != value)
                {
                    currentData.CallNumber = value;
                    NotifyPropertyChanged("CallNumber");
                }
            }
        }

        public DateTime DueDate
        {
            get { return currentData.DueDate; }
            set
            {
                if (value != currentData.DueDate)
                {
                    currentData.DueDate = value;
                    NotifyPropertyChanged("DueDate");
                }
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion

        #region IEditableObject Members

        public virtual void BeginEdit()
        {
            copyData = currentData;
        }

        public virtual void CancelEdit()
        {
            currentData = copyData;
            NotifyPropertyChanged("");
        }

        public virtual void EndEdit()
        {
            copyData = new ItemData();
        }

        #endregion

    }

    public class MusicCD : LibraryItem
    {
        private struct MusicData
        {
            internal int SongNumber;
            internal string Artist;
        }

        MusicData copyData;
        MusicData currentData;

        public MusicCD(string title, string artist, int songNum, string callNum, DateTime dueDate)
            : base(title, callNum, dueDate)
        {
            currentData.SongNumber = songNum;
            currentData.Artist = artist;
        }

        public string Artist
        {
            get { return currentData.Artist; }
            set
            {
                if (value != currentData.Artist)
                {
                    currentData.Artist = value;
                    NotifyPropertyChanged("Artist");
                }
            }
        }

        public int NumberOfTracks
        {
            get { return currentData.SongNumber; }
            set
            {
                if (value != currentData.SongNumber)
                {
                    currentData.SongNumber = value;
                    NotifyPropertyChanged("NumberOfTracks");
                }
            }
        }

        public override void BeginEdit()
        {
            base.BeginEdit();
            copyData = currentData;
        }

        public override void CancelEdit()
        {
            base.CancelEdit();
            currentData = copyData;
        }

        public override void EndEdit()
        {
            base.EndEdit();
            copyData = new MusicData();
        }

        public override string ToString()
        {
            return string.Format(
                "Album: {0}\nArtist: {1}\nTracks: {2}\nDue Date: {3:d}\nCall Number: {4}",
                this.Title, this.Artist, this.NumberOfTracks, this.DueDate, this.CallNumber);
        }
    }

    public class Book : LibraryItem
    {
        private struct BookData
        {
            internal string Author;
            internal string Genre;
        }

        BookData currentData;
        BookData copyData;

        public Book(string title, string author, string genre, string callnum, DateTime dueDate)
            : base (title, callnum, dueDate)
        {
            this.Author = author;
            this.Genre = genre;
        }

        public string Author
        {
            get { return currentData.Author; }
            set
            {
                if (value != currentData.Author)
                {
                    currentData.Author = value;
                    NotifyPropertyChanged("Author");
                }
            }
        }

        public string Genre
        {
            get { return currentData.Genre; }
            set
            {
                if (value != currentData.Genre)
                {
                    currentData.Genre = value;
                    NotifyPropertyChanged("Genre");
                }
            }
        }

        public override void BeginEdit()
        {
            base.BeginEdit();
            copyData = currentData;
        }

        public override void CancelEdit()
        {
            base.CancelEdit();
            currentData = copyData;
        }

        public override void EndEdit()
        {
            base.EndEdit();
            copyData = new BookData();
        }

        public override string ToString()
        {
            return String.Format(
                "Title: {0}\nAuthor: {1}\nGenre: {2}\nDue Date: {3:d}\nCall Number: {4}",
                this.Title, this.Author, this.Genre, this.DueDate, this.CallNumber);
        }
    }

    public class MovieDVD : LibraryItem
    {
        private struct MovieData
        {
            internal TimeSpan Length;
            internal string Director;
            internal string Genre;
        }

        private MovieData currentData;
        private MovieData copyData;

        public MovieDVD(string title, string director, string genre, TimeSpan length, string callnum, DateTime dueDate)
            : base(title, callnum, dueDate)
        {
            this.Director = director;
            this.Length = length;
            this.Genre = genre;
        }

        public TimeSpan Length
        {
            get { return currentData.Length; }
            set
            {
                if (value != currentData.Length)
                {
                    currentData.Length = value;
                    NotifyPropertyChanged("Length");
                }
            }
        }

        public string Director
        {
            get { return currentData.Director; }
            set
            {
                if (value != currentData.Director)
                {
                    currentData.Director = value;
                    NotifyPropertyChanged("Director");
                }
            }
        }

        public string Genre
        {
            get { return currentData.Genre; }
            set
            {
                if (value != currentData.Genre)
                {
                    currentData.Genre = value;
                    NotifyPropertyChanged("Genre");
                }
            }
        }

        public override void BeginEdit()
        {
            base.BeginEdit();
            copyData = currentData;
        }

        public override void CancelEdit()
        {
            base.CancelEdit();
            currentData = copyData;
        }

        public override void EndEdit()
        {
            base.EndEdit();
            copyData = new MovieData();
        }

        public override string  ToString()
        {
            return String.Format("Title: {0}\nDirector: {1}\nGenre: {2}\nLength: {3}\nDue Date: {4:d}\nCall Number: {5}",
                this.Title, this.Director, this.Genre, this.Length, this.DueDate, this.CallNumber);
        }
    }

    public class LibraryCatalog : ObservableCollection<LibraryItem>
    {
        public LibraryCatalog()
        {
            Add(new MusicCD("A Programmers Plight", "Jon Orton", 
                12, "CD.OrtPro", new DateTime(2010, 3, 24)));
    
            Add(new Book("Cooking with Thyme", "Eliot J. Graff",
                "Home Economics", "HE.GraThy", new DateTime(2010, 2, 26)));
            
            Add(new MovieDVD("Terror of the Testers", "Molly Dempsey", 
                "Horror", new TimeSpan(1, 27, 19), "DVD.DemTer",
                new DateTime(2010, 2, 1)));
            
            Add(new MusicCD("The Best of Jim Hance", "Jim Hance", 
                15, "CD.HanBes", new DateTime(2010, 1, 31)));
            
            Add(new Book("Victor and the VB Vehicle", "Tommy Hortono", 
                "YA Fiction", "YA.HorVic", new DateTime(2010, 3, 1)));
        }
    }
}
开发者ID:.NET开发者,项目名称:System.ComponentModel,代码行数:355,代码来源:IEditableCollectionViewAddNewItem



注:本文中的System.ComponentModel.IEditableCollectionViewAddNewItem接口示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IEditableObject接口代码示例发布时间:2022-05-26
下一篇:
C# IEditableCollectionView接口代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap