WPF 中的剧院座位应用程序 - 数据绑定问题
我是 WPF 新手,我想在 WPF-c#.net 中开发一个用于剧院座位的应用程序。 我做了一些研究,但我迷失了,因为我不知道每个座位的数据(是否出售、价格、在哪一行)最终应如何绑定到 SQL Express 中表中的字段。 我应该使用 ObservableCollection 来填充其中数据表的内容吗? 另外,我应该使用按钮网格吗?还是矩形?如果我希望左前和右前按钮稍微倾斜而不是水平,我应该如何操作? 如果我想要三个区域的座椅,我应该使用包裹板吗?左边区域,修改空间,中间区域,修改空间,右边区域? 如果有人能给我一些开始的提示,我会非常高兴。 提前致谢...
I am new to WPF, and I want to develop an application for Theater seating in WPF- c#.net.
I did some research but i am lost as i do not know how each seat's data (sold or not, price, in which row) should be eventually bound to field in a table in SQL Express.
Should i be using ObservableCollection to populate the contents of a Datatable in it?
Also, should i be using a grid of buttons? or rectangles? How should i proceed if i want the front left and front right buttons to be inclined a bit instead of being horizontal?
Should i be using a wrappanel if i want to have three areas for the seats? Left area, space for alter, middle area, space for alter and right area?
If somebody can give me some hints for me to start, i will be more than glad.
Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您同时提出了很多问题,如果不为您编写程序,任何人都不可能回答所有问题,但我将提供我将采取的高级方法。您必须花一些时间来深入研究细节。有关 StackOverflow 的大量信息以及其他有关这些详细信息的帮助信息。
无论如何 -
数据库,3 个表
SeatStatus
表已售出、已损坏)
PricePoint
表OnSale、Premium)
Seat
表SeatStatus 表
PricePoint Table
应用程序模型
我将使用Entity Framework 4 并从 TheaterSeating 数据库生成模型。这将为您创建
Seat
对象,其中自动包含对SeatStatus
和PricePoint
的引用。非常光滑。编辑 1
创建模型后,您将拥有一个代表数据的 .edmx 文件,并且可以轻松读取/写入数据库。假设此文件名为
TheaterSeatingModel.edmx
,自动生成的类将为您提供调用以下内容的方法:您现在可以访问整个数据库,包括:
等等。
您可以按照您自然期望的方式使用这些类,例如:
在类中使用这些席位填充
ObservableCollection
,并将您的视图(XAML 控件)的 DataContext 设置为此类。这将使用所有 Seat 对象填充您的集合。
与此集合的简单 WPF 绑定将类似于:
UI
如果是我,我会使用 WPF
ItemsControl
,其ItemsSource
是设置为您的ObservableCollection
席位。将此ItemsControl
放置在Canvas
内。ItemsControl 的
ItemsControl.ItemTemplate
控制每个Seat
在您的视图中的外观。您可以将ItemTemplates
Canvas.Left
和Canvas.Top
绑定到Seat.Row
和Seat .Column
将座位放置在屏幕上适当的位置。您可以将模板设为按钮、矩形、座位图像等任何内容。您可以设置Styles
和Triggers
以使座位根据PricePoint
、SeatStatus
等以不同方式显示。认为 WPF 对于您正在启动的项目非常有用。
祝你好运!
You're asking a lot of questions at once, and it would be impossible for anyone to answer them all without writing your program for you, but I'll offer the high-level approach that I would take. You'll have to spend some time to dig into the details. Plenty of info on StackOverflow and otherwise to get help on these details.
Anyways-
Database, 3 tables
SeatStatus
TableSold, Broken)
PricePoint
TableOnSale, Premium)
Seat
TableSeatStatus Table
PricePoint Table
Application Model
I would use Entity Framework 4 and generate your model from your TheaterSeating database. This will create
Seat
objects for you that automatically contain references toSeatStatus
andPricePoint
. Very slick.Edit 1
Once you've created your model you will have an .edmx file that represents your data, and can read/write to your database easily. Assuming this file is called
TheaterSeatingModel.edmx
, the auto-generated classes will provide you with the means to call something along the lines of:You now have access to your entire database, including:
etc.
You can use these classes as you would naturally expect, an example:
Populate an
ObservableCollection
with these seats inside a class, and set your View's (the XAML control's) DataContext to this class.This will populate your collection with all the Seat objects.
A simple WPF binding to this collection would be something along the lines of:
UI
If it were me I would use a WPF
ItemsControl
whoseItemsSource
is set to yourObservableCollection
of Seats. Place thisItemsControl
inside of aCanvas
. TheItemsControl's
ItemsControl.ItemTemplate
control what eachSeat
will look like in your view. You can bind theItemTemplates
Canvas.Left
andCanvas.Top
to theSeat.Row
andSeat.Column
to place the seats in their appropriate positions on screen. You can make the template be a button, rectangle, image of a seat, anything. You can set upStyles
andTriggers
to make the Seat display differently depending onPricePoint
,SeatStatus
, etc.I think WPF will be great for the project you're starting.
Good luck!