Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Team

I have a grid and want to implement stackpanel below it, but i dont want to affect the other controls within ui, it must just below the grid. Here is my logic below

What I have tried:

XML
<pre>
C#
<pre><Grid Background="White" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,29,0,10" Width="1766">


<!---Name of the screen on top-->
<Label Content="Premix-Batch Management" BorderThickness="1.5" BorderBrush="#FF0B0B0B" Background="#FF383838" Foreground="White" FontSize="18" HorizontalContentAlignment="Center" VerticalAlignment="Top" Margin="10,10,0,0" FontWeight="SemiBold" />

<!--Data Grid columns names-->
<DataGrid x:Name="dgvMacroRecipe" VerticalScrollBarVisibility="Visible" SelectedCellsChanged="dgvMacroRecipe_SelectedCellsChanged" CellEditEnding="dgvMacroRecipe_CellEditEnding"  VerticalAlignment="Top" HorizontalGridLinesBrush="#FFBBBBBB" AutoGenerateColumns="False" CanUserDeleteRows="False" HeadersVisibility="Column" GridLinesVisibility="Horizontal" FontWeight="Normal" BorderBrush="#FF767676" Margin="14,496,0,0" HorizontalAlignment="Left" FontSize="12" Width="780"  >
    <DataGrid.Resources>
        <Style TargetType="{x:Type DataGridCell}">
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="Blue" />
                    <Setter Property="BorderBrush" Value="Blue"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGrid.Resources>
    <DataGrid.ColumnHeaderStyle>
        <Style TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="TextElement.FontSize" Value="14"/>
            <Setter Property="Background" Value="#FF383838"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="SeparatorVisibility" Value="Visible"/>
        </Style>
    </DataGrid.ColumnHeaderStyle>
    <DataGrid.Columns>
        <DataGridTextColumn  Visibility="Visible" Width="5">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>
        <DataGridTextColumn Binding="{Binding idx}" Header="IDX" Width="Auto" IsReadOnly="True" Visibility="Hidden">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>

        <!--IDX column-->
        <DataGridTextColumn Binding="{Binding idx1}" Header="IDX" Width="Auto" IsReadOnly="True">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>
        <DataGridTextColumn  Visibility="Visible" Width="5">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>

        <!---RM Code column-->
        <DataGridTextColumn Binding="{Binding RM_Code}" Header="RM Code" Width="Auto" IsReadOnly="True" FontSize="8">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>
        <DataGridTextColumn  Visibility="Visible" Width="5">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>

        <!---Stock Code column-->
        <DataGridTemplateColumn Header="Stock Code">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock x:Name="txtStockCode"  Text="{Binding [Stock Code]}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
            <DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <ComboBox Height="22" Width="auto" x:Name="cbxMacroStockType" ItemsSource="{Binding Source={StaticResource StockCode}}" DisplayMemberPath="Code" SelectedValue="Code" SelectedValuePath="idx1" IsSynchronizedWithCurrentItem="True"   DropDownClosed="cbxMacroStockType_DropDownClosed" />
                </DataTemplate>
            </DataGridTemplateColumn.CellEditingTemplate>
        </DataGridTemplateColumn>
        <DataGridTextColumn  Visibility="Visible" Width="5">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>

        <!---Stock Description column-->
        <DataGridTextColumn Binding="{Binding [Stock Description]}" Header="Stock Description" Width="auto" IsReadOnly="True" FontWeight="SemiBold">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="TextAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                    <Style.Triggers>
                        <Trigger Property="Text" Value="Yes">
                            <Setter Property="Background" Value="LightGreen"/>
                        </Trigger>
                        <Trigger Property="Text" Value="No">
                            <Setter Property="Background" Value="#FFFF6969"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>
        <DataGridTextColumn  Visibility="Visible" Width="5">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>


        <!---Percentage column-->
        <DataGridTextColumn Binding="{Binding Percentage}" Header="Percentage" Width="auto" FontWeight="SemiBold">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="TextAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                    <Style.Triggers>
                        <Trigger Property="Text" Value="Yes">
                            <Setter Property="Background" Value="LightGreen"/>
                        </Trigger>
                        <Trigger Property="Text" Value="No">
                            <Setter Property="Background" Value="#FFFF6969"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>
        <DataGridTextColumn  Visibility="Visible" Width="5">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>

        <!---Kilograms-->
        <DataGridTextColumn Binding="{Binding Kilograms}" Header="Kilograms" Width="Auto" IsReadOnly="True" FontWeight="SemiBold">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>
        <DataGridTextColumn  Visibility="Visible" Width="5">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="HorizontalAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>



<!-- StackPanel section -->
        <StackPanel Grid.Row="6" Orientation="Horizontal" Margin="14,470,0,0">
            <TextBlock Text="NO. OF PREMIX PACKS MADE:"/>
            <TextBox Width="80"
                     Height="20"
                     VerticalAlignment="Top"
                     Margin="95,0,0,0"
                     Text="{Binding No_OF_PREMIX_PACKS_MADE}"
                     IsReadOnly="True"/>
        </StackPanel>

        <StackPanel Grid.Row="7" Margin="14,500,0,0">
            <StackPanel Orientation="Horizontal">
                <TextBlock>Weight per pack 1</TextBlock>
                <TextBox Width="80"
                         Background="Gray"
                         Margin="80,0,0,0"
                         Text="{Binding Weight_per_pack_1}"
                         IsReadOnly="True"/>
                <TextBlock>Kg</TextBlock>
            </StackPanel>
Posted

1 solution

You need to to add row definitions to your Grid Layout. Here is a tutorial for you: The Grid - Rows & columns - The complete WPF tutorial[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900