我在堆棧面板和內部格式化方面存在問題, 我正在研究咖啡吧的小應用可以說,客戶可以從屏幕中間選擇飲料和 飲料將在我的堆疊面板中顯示在屏幕的右側,這就是現在的樣子(當客戶選擇某件東西 - 可以說可樂時): 如何重新組織我的堆棧面板WPF
我的代碼,一切都完成了:
public DrinksPanel(int id, int groupID, double price,double priceHappyHour, string text, int fontSize, int numberSize, int buttonWidth, int buttonHeight, int margin, Thickness border, byte[] image)
: base()
{
this.Width = buttonWidth+90;
this.Height = buttonHeight + 35;
image.Source = GetImageFromByte(image);
ID = id;
groupID = groupID;
price = price;
priceHappyHour = priceHappyHour;
LeftPanelButton.HorizontalAlignment = HorizontalAlignment.Center;
LeftPanelButton.VerticalAlignment = VerticalAlignment.Center;
LeftPanelButton.Orientation = Orientation.Vertical;
LeftPanelButton.MaxWidth = LeftPanelButton.Width = buttonWidth;
LeftPanelButton.Height = LeftPanelButton.MaxHeight = this.Height;
LeftPanelButton.Background = new SolidColorBrush(Colors.Red);
_image.Width = LeftPanelButton.Width;
_image.Height = buttonHeight;
_image.HorizontalAlignment = HorizontalAlignment.Left;
_image.VerticalAlignment = VerticalAlignment.Center;
PanelQtyNumber.HorizontalAlignment = HorizontalAlignment.Right;
PanelQtyNumber.VerticalAlignment = VerticalAlignment.Center;
PanelQtyNumber.Orientation = Orientation.Horizontal;
PanelQtyNumber.Width = PanelQtyNumber.MaxWidth = this.Width - LeftPanelButton.Width;
DrinkNameLabel.VerticalContentAlignment = VerticalAlignment.Center;
DrinkNameLabel.HorizontalContentAlignment = HorizontalAlignment.Left;
DrinkNameLabel.FontSize = fontSize;
DrinkNameLabel.Foreground = System.Windows.Media.Brushes.White;
DrinkNameLabel.MaxWidth = _image.Width;
DrinkNameLabel.FontFamily = Util.Font;
NumberLabel.FontSize = numberSize;
NumberLabel.Margin = new Thickness(margin, margin, 0, margin);
NumberLabel.VerticalAlignment = VerticalAlignment.Center;
NumberLabel.HorizontalAlignment = HorizontalAlignment.Right;
NumberLabel.HorizontalContentAlignment = HorizontalAlignment.Right;
NumberLabel.Foreground = System.Windows.Media.Brushes.White;
NumberLabel.FontWeight = FontWeights.Bold;
NumberLabel.Background = this.Background;
How to reorganize my stack panel WPF
DrinkNameLabel.Content = text;
NumberLabel.Content = "x1";
LeftPanelButton.Children.Add(image);
LeftPanelButton.Children.Add(DrinkNameLabel);
PanelQtyNumber.Children.Add(NumberLabel);
Rectangle rct = new Rectangle();
rct.Fill = System.Windows.Media.Brushes.White;
rct.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
rct.Height = 2;
_animation = new DoubleAnimation(numberSize, numberSize + 15, new Duration(new TimeSpan(0, 0, 0, 0, 300)));
_animation.AutoReverse = true;
this.Margin = border;
this.Orientation = Orientation.Horizontal;
StackPanel spNew = new StackPanel();
spNew.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
spNew.Orientation = System.Windows.Controls.Orientation.Horizontal;
spNew.Children.Add(LeftPanelButton);
spNew.Children.Add(PanelQtyNumber);
StackPanel spNew2 = new StackPanel();
spNew2.Orientation = System.Windows.Controls.Orientation.Vertical;
spNew2.Children.Add(spNew);
this.Children.Add(spNew2);
}
我不能動我的文字一樣,正確的或點兒:/任何人都可以幫我這個吧。
你的問題的寬度是你想要一個水平對齊而不是垂直於您的項目定位。但不要這樣做,檢查模板和你的xaml的UI不是c#... – gmetax
更改spNew2.Orientation = System.Windows.Controls.Orientation.Vertical; 與水平線 – gmetax
你有任何xaml?你的UI代碼真的不應該在C#中設置。對於這種情況,您應該使用xaml中的ItemsControl和數據模板,以及C#中的ObservableCollection。 – Joe