@ruslan2570

Как привязать StackPanel к левому краю в XAMl?

StackPanel никак не прикрепляется к левому краю.
62759daea41b6657465395.png
<TabItem Header="Ассортимент">
                <Grid>
                    <ListBox VerticalAlignment="Top" ItemsSource="{Binding Source={StaticResource assortmentCollection}}"
							 HorizontalAlignment="Stretch" AlternationCount="2">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>

                                    <StackPanel>
                                        <TextBlock Padding="5" FontSize="20" FontWeight="Bold" Text="{Binding Name}"/>
                                        <StackPanel Margin="5,0,0,0"  Orientation="Horizontal">
                                            <TextBlock FontSize="14" FontWeight="Bold" Text="Калорийность "/>
                                            <TextBlock FontSize="14" Text="{Binding Calorific}"/>
                                            <TextBlock FontSize="14" Text=" ккал."/>
                                        </StackPanel>
                                        <TextBlock Padding="5" FontSize="14" Text="{Binding Description}"/>
                                    </StackPanel>

                                    <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left">
                                        <StackPanel VerticalAlignment="Center" Orientation="Horizontal" Margin="5">
                                            <TextBlock FontSize="20" FontWeight="Bold" Text="Цена: "/>
                                            <TextBlock FontSize="20" Text="{Binding Price, StringFormat=N2}"/>
                                            <TextBlock FontSize="20" Text="₽" Margin="1"/>
                                        </StackPanel>

                                        <Button Content="Добавить" Height="42" Padding="6" Command="{Binding AddToCart, Source={StaticResource cart}}"
											CommandParameter="{Binding}" Background="Transparent" BorderThickness="2" HorizontalAlignment="Right">
                                        </Button>
                                    </StackPanel>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>
            </TabItem>

В соседней вкладке почти такой же код, но всё работает
62759e159d362007335234.png
<TabItem Header="Корзина">
                <Grid DataContext="{StaticResource cart}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="60"/>
                    </Grid.RowDefinitions>

                    <ListBox VerticalAlignment="Top" ItemsSource="{Binding Path=CartItems, Mode=OneWay, Source={StaticResource cart}}"
							 HorizontalContentAlignment="Stretch" AlternationCount="2">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>

                                    <StackPanel>
                                        <TextBlock Padding="4" FontSize="20" FontWeight="Bold" Text="{Binding Product.Name}"/>

                                        <StackPanel Margin="4" Orientation="Horizontal">
                                            <TextBlock FontSize="12" FontWeight="Bold" Text="Цена товара: "/>
                                            <TextBlock FontSize="12" Text="{Binding Product.Price, StringFormat=N2}"/>
                                            <TextBlock FontSize="12" Text="₽"/>
                                        </StackPanel>

                                        <StackPanel Margin="4" Orientation="Horizontal">
                                            <TextBlock FontSize="12" FontWeight="Bold" Text="Количество: "/>
                                            <TextBlock FontSize="12" Text="{Binding Quantity}"/>
                                            <TextBlock FontSize="12" Text="шт."/>
                                        </StackPanel>

                                        <StackPanel Margin="4" Orientation="Horizontal">
                                            <TextBlock FontSize="15" FontWeight="Bold" Text="Всего за позицию: "/>
                                            <TextBlock FontSize="15" Text="{Binding Sum, StringFormat=N2}"/>
                                            <TextBlock FontSize="15" Text="₽"/>
                                        </StackPanel>
                                    </StackPanel>

                                    <StackPanel Grid.Column="2">

                                        <Button Content="Увеличить" Margin="3" FontSize="14" Padding="7" Command="{Binding AddQuantity, Source={StaticResource cart}}"
												CommandParameter="{Binding}" Background="Transparent" BorderThickness="2">

                                        </Button>

                                        <Button Content="Уменьшить" Margin="3" FontSize="14" Padding="7" Command="{Binding MinusQuantity, Source={StaticResource cart}}"
												CommandParameter="{Binding}" Background="Transparent" BorderThickness="2">
                                        </Button>

                                        <Button Content="Удалить" Margin="3" FontSize="14" Padding="7" Command="{Binding RemoveProduct, Source={StaticResource cart}}"
												CommandParameter="{Binding}" Background="Transparent" BorderThickness="2"/>
                                    </StackPanel>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                    <StackPanel Grid.Row="1" Orientation="Horizontal" Background="#D9F066">
                        <TextBlock Padding="5" VerticalAlignment="Center" FontSize="18" FontWeight="Bold" Text="ИТОГО:"/>
                        <TextBlock Padding="5" VerticalAlignment="Center" FontSize="18" FontWeight="Bold" Text="{Binding TotalPrice, StringFormat=N2}"/>
                        <TextBlock Padding="5" FontSize="18" FontWeight="Bold" VerticalAlignment="Center" Text="₽"/>
                        <Button Margin="5" Width="100" Height="50" FontSize="18" 
                                Content="Оплата" HorizontalContentAlignment="Center"
                                Command="{Binding Checkout}" Background="#e2ebda"/>
                    </StackPanel>
                </Grid>
            </TabItem>
  • Вопрос задан
  • 104 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы