Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Hỏi về Panel trong WPF

11:08 25-07-2022 563 lượt xem 0 bình luận

Chào anh Long và mọi người, em đang làm đồ án khóa luận phần mềm quản lý quán cafe bằng WPF, em sử dụng WrapPanel để hiển thị thông tin bàn, khi em thực hiện chức năng thì không load lại trạng thái của bàn như là: Khi em gọi món thì không load lại trạng thái bàn là "Có người" mà em phải tắt đi mở lại mới cập nhật lại là "Có người". Doạn code của em như sau:

		<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
			<WrapPanel Orientation="Horizontal" x:Name="TablePanel"></WrapPanel>
		</ScrollViewer>

Hàm LoadTable:

        private void LoadTableList()
        {
            TablePanel.Children.Clear();
            ObservableCollection<TableFood> TableList;
            TableList = new ObservableCollection<TableFood>(DataProvider.Instance.Data.TableFoods);
            foreach (var item in TableList)
            {
                Button button = new Button() { Width = TableWidth, Height = TableHeight };
                button.Content = item.Name + Environment.NewLine + item.Status;
                button.Click += Button_Click;
                button.Tag = item;
                switch (item.Status)
                {
                    case "Trống":
                        button.Background = Brushes.Red;
                        break;
                    default:
                        button.Background = Brushes.YellowGreen;
                        break;
                }
                TablePanel.Children.Add(button);
            }
        }

Code chức năng gọi món:

   private void btnOrderFood_Click(object sender, RoutedEventArgs e)
        {
            TableFood table = lsvBill.Tag as TableFood;
            int idBill = BillViewModel.Instance.GetUncheckBillIDByTableID(table.Id);
            int FoodId = (cmbFood.SelectedItem as Food).Id;
            int Count = Int32.Parse(txtCount.Text);
            if (idBill == -1)
            {
                BillViewModel.Instance.InsertBill(table.Id);
                BillViewModel.Instance.InsertBillInfo(BillViewModel.Instance.GetMaxIdBill(), FoodId, Count);
            }
            else
            {
                BillViewModel.Instance.InsertBillInfo(idBill, FoodId, Count);
            }
            MessageBox.Show("Gọi món thành công");
            ShowBill(table.Id);
            LoadTableList();
        }

Em tìm trên mạng thì hướng dẫn dùng FlowLayoutPanel trong winform và FlowLayoutControl trong DevExpress. Vậy có cách nào không dùng DevExpress không ạ? Xin anh và mọi người giúp đỡ em. Em cảm ơn anh

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập

Câu hỏi mới nhất