0

Boas pessoal.

Tenho um pequeno problema e não estou a conseguir encontrar a onde está o "erro". Estou a tentar por a Window responsivo, no qual o Width acompanha sem problemas alguns o tamanho da janela, agora o problema é mesmo o Heigth, as DataGrid estão sempre no mesmo tamanho e disse que elas iriam ter apenas um MinHeigth="300".

BtW tenho dentro de um StackPanel porque a grid com o nome gridManager poderá aparecer ou não consoante uma condição, fazendo o Colapse quando não for para aparecer para não andar a fazer em codigo depois para ajustar as coisas novamente.

Aqui está o codigo:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:RetailInfo"
        xmlns:Controls="clr-namespace:RetailInfo.Controls" x:Class="RetailInfo.WindowDocumentPriceCheck"
        mc:Ignorable="d"
        Title="Verificar preços" Height="610" MinHeight="610" Width="600" MinWidth="400" BorderThickness="0" WindowStyle="ToolWindow" Focusable="True" ShowInTaskbar="False" ShowActivated="True">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel x:Name="stackPanelMain" Grid.Column="0" Grid.Row="0" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <Grid x:Name="gridManager" VerticalAlignment="Top" HorizontalAlignment="Left" Height="50" Width="298" Margin="10,0,0,0">
                <StackPanel>
                    <GroupBox x:Name="groupBoxRadio" Header="Tipo de Entidade" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="250">
                        <Grid>
                            <RadioButton x:Name="radioButtonClient" Content="Cliente" HorizontalAlignment="Left" Margin="10,9,0,0" VerticalAlignment="Top" IsChecked="True"/>
                            <RadioButton x:Name="radioButtonSupplier" Content="Fornecedor" HorizontalAlignment="Left" Margin="100,9,0,0" VerticalAlignment="Top"/>
                        </Grid>
                    </GroupBox>
                </StackPanel>
            </Grid>
            <Grid Margin="0,10,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" Name="GridWithDataGridLeft"/>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid Grid.Column="0" Grid.Row="0">
                    <StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        <Label x:Name="labelTypeOfSearch" Content="Nome do cliente" HorizontalAlignment="Left" Margin="10,5,0,5" VerticalAlignment="Top" FontSize="14"/>
                        <Grid Margin="10,5,10,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="30"/>
                            </Grid.RowDefinitions>
                            <TextBox Grid.Column="0" Grid.Row="0" x:Name="textBoxFilterEntity" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="Wrap" Text="" VerticalContentAlignment="Center" FontSize="16"/>
                        </Grid>
                        <Grid Margin="10,5,10,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition MinHeight="300" Height="*"/>
                            </Grid.RowDefinitions>
                            <DataGrid x:Name="dataGridEntity" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                                <DataGrid.Columns>
                                    <DataGridTextColumn Binding="{Binding Path=Id}" Visibility="Hidden"/>
                                    <DataGridTextColumn Binding="{Binding Path=Name}" Width="*" Header="Nome"/>
                                </DataGrid.Columns>
                                <DataGrid.ItemContainerStyle>
                                    <Style TargetType="DataGridRow">
                                        <EventSetter x:Name="dataGridEntityPreviewLeftClick" Event="PreviewMouseLeftButtonUp" Handler="DataGridEntityRow_PreviewMouseLeftButtonUp"/>
                                    </Style>
                                </DataGrid.ItemContainerStyle>
                            </DataGrid>
                        </Grid>
                    </StackPanel>
                </Grid>
                <Grid Grid.Column="1" Grid.Row="0">
                    <StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        <Label Content="Artigos" HorizontalAlignment="Left" Margin="10,5,0,5" VerticalAlignment="Top" FontSize="14"/>
                        <Grid Margin="10,5,10,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="30"/>
                            </Grid.RowDefinitions>
                            <TextBox Grid.Column="0" Grid.Row="0" x:Name="textBoxFilterProd" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="Wrap" Text="" VerticalContentAlignment="Center" FontSize="16"/>
                        </Grid>
                        <Grid Margin="10,5,10,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition MinHeight="300"/>
                            </Grid.RowDefinitions>
                            <DataGrid x:Name="dataGridProds" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                                <DataGrid.Columns>
                                    <DataGridTextColumn Binding="{Binding Path=Id}" Visibility="Hidden"/>
                                    <DataGridTextColumn Binding="{Binding Path=Name}" Width="*" Header="Nome"/>
                                </DataGrid.Columns>
                                <DataGrid.ItemContainerStyle>
                                    <Style TargetType="DataGridRow">
                                        <EventSetter x:Name="dataGridProdsPreviewLeftClick" Event="PreviewMouseLeftButtonUp" Handler="DataGridProdRow_PreviewMouseLeftButtonUp"/>
                                    </Style>
                                </DataGrid.ItemContainerStyle>
                            </DataGrid>
                        </Grid>
                    </StackPanel>
                </Grid>
            </Grid>
            <Grid Margin="0,10,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="50"/>
                </Grid.RowDefinitions>
                <Grid Grid.Column="0" Grid.Row="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Label Grid.Column="0" Grid.Row="0" Content="Cod. Barras/Artigo" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="14" Margin="10,0,10,0"/>
                    <Label Grid.Column="1" Grid.Row="0" Content="Preço" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="14" Margin="10,0,10,0"/>
                </Grid>
                <Grid Grid.Column="0" Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBox x:Name="textBoxBarCode" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="Wrap" Text="" VerticalContentAlignment="Center" FontSize="16" Margin="10,0,10,0"/>
                    <TextBox x:Name="textBoxPrice" Grid.Column="1" Grid.Row="0" Margin="10,0,10,0" TextWrapping="Wrap" Text="{Binding Price, UpdateSourceTrigger=Explicit}" Width="60" IsReadOnly="True" HorizontalAlignment="Left"/>
                </Grid>
                <Grid Grid.Column="0" Grid.Row="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock x:Name="textBlockDescription" Grid.Column="0" Grid.Row="0" Margin="10,5,10,0" TextWrapping="WrapWithOverflow" Text="{Binding Descr, Mode=TwoWay, UpdateSourceTrigger=Explicit}" FontSize="16"/>
                </Grid>
            </Grid>
        </StackPanel>
    </Grid>
</Window>

Peço desculpas se o problema for obvio, comecei a trabalhar relativamente a pouco tempo com WPF.

Obrigada pela ajuda

1 Resposta 1

0

Bom tive que mudar um bocado as coisas para que funciona-se como eu queria.

Aqui fica a solução caso alguém venha a ter os mesmos problemas que eu.

Substitui StackPanel por uma grid, ondo a RowDefenition Heightpara estar associado ao height do groupBoxRadio e ao passar a height para 0 ele adapta-se sem problemas nenhuns.

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:RetailInfo"
        xmlns:Controls="clr-namespace:RetailInfo.Controls" x:Class="RetailInfo.WindowDocumentPriceCheck"
        mc:Ignorable="d"
        Title="Verificar preços" Height="610" MinHeight="610" Width="600" MinWidth="400" BorderThickness="0" WindowStyle="ToolWindow" Focusable="True" ShowInTaskbar="False" ShowActivated="True">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" MaxHeight="{Binding ElementName=groupBoxRadio, Path=Height}"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="120"/>
        </Grid.RowDefinitions>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>
                <VisualState x:Name="FullScreenPortrait"/>
                <VisualState x:Name="Snapped"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <!-- Para fazer o colapse basta passar o Height do groupBoxRadio para 0 como tenho a RowDefinition deste para 0 e ele adapta-se sem problemas -->
        <Grid x:Name="gridManagerInfo" Grid.Column="0" Grid.Row="0" Margin="10,0,0,0">
            <StackPanel>
                <GroupBox x:Name="groupBoxRadio" Header="Tipo de Entidade" HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="250">
                    <Grid>
                        <RadioButton x:Name="radioButtonClient" Content="Cliente" HorizontalAlignment="Left" Margin="10,9,0,0" VerticalAlignment="Top" IsChecked="True"/>
                        <RadioButton x:Name="radioButtonSupplier" Content="Fornecedor" HorizontalAlignment="Left" Margin="100,9,0,0" VerticalAlignment="Top"/>
                    </Grid>
                </GroupBox>
            </StackPanel>
        </Grid>
        <Grid x:Name="gridForDataGrids" Grid.Column="0" Grid.Row="1" Margin="0,5,0,0">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid Grid.Column="0" Grid.Row="0" Margin="0,5,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Label Grid.Column="0" Grid.Row="0" x:Name="labelTypeOfSearch" Content="Nome do Cliente" Margin="10,0,0,0" FontSize="16" VerticalAlignment="Stretch"/>
                    <Label Grid.Column="1" Grid.Row="0" Content="Artigos" Margin="10,0,0,0" FontSize="16" VerticalAlignment="Stretch"/>
                </Grid>
                <Grid Grid.Column="0" Grid.Row="1" Margin="0,5,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBox Grid.Column="0" Grid.Row="0" x:Name="textBoxFilterEntity" TextChanged="textBoxFilterEntity_TextChanged" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="Wrap" Text="" VerticalContentAlignment="Center" FontSize="16" Margin="10,0,10,0"/>
                    <TextBox Grid.Column="1" Grid.Row="0" x:Name="textBoxFilterProd" TextChanged="textBoxFilterProd_TextChanged" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="Wrap" Text="" VerticalContentAlignment="Center" FontSize="16" Margin="10,0,10,0"/>
                </Grid>
                <Grid Grid.Column="0" Grid.Row="2" Margin="0,5,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <!-- DataGrid for the Entity -->
                    <DataGrid x:Name="dataGridEntity" Grid.Column="0" Grid.Row="0" Margin="10,5,10,0" CanUserAddRows="False" AutoGenerateColumns="False" LoadingRow="DataGrid_LoadingRow">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Path=Id}" Visibility="Hidden"/>
                            <DataGridTextColumn Binding="{Binding Path=Name}" Width="*" Header="Nome" IsReadOnly="True"/>
                        </DataGrid.Columns>
                        <DataGrid.ItemContainerStyle>
                            <Style TargetType="DataGridRow">
                                <EventSetter x:Name="dataGridEntityPreviewLeftClick" Event="PreviewMouseLeftButtonUp" Handler="DataGridEntityRow_PreviewMouseLeftButtonUp"/>
                                <Setter Property="FontSize" Value="16"/>
                                <Setter Property="VerticalContentAlignment" Value="Center"/>
                            </Style>
                        </DataGrid.ItemContainerStyle>
                    </DataGrid>
                    <!-- DataGrid for the Products -->
                    <DataGrid x:Name="dataGridProds" Grid.Column="1" Grid.Row="0" Margin="10,5,10,0" CanUserAddRows="False" AutoGenerateColumns="False" LoadingRow="DataGrid_LoadingRow">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Path=Id}" Visibility="Hidden"/>
                            <DataGridTextColumn Binding="{Binding Path=Name}" Width="*" Header="Nome" IsReadOnly="True"/>
                        </DataGrid.Columns>
                        <DataGrid.ItemContainerStyle>
                            <Style TargetType="DataGridRow">
                                <EventSetter x:Name="dataGridProdsPreviewLeftClick" Event="PreviewMouseLeftButtonUp" Handler="DataGridProdRow_PreviewMouseLeftButtonUp"/>
                                <Setter Property="FontSize" Value="16"/>
                                <Setter Property="VerticalContentAlignment" Value="Center"/>
                            </Style>
                        </DataGrid.ItemContainerStyle>
                    </DataGrid>
                </Grid>
            </Grid>
        </Grid>
        <Grid x:Name="gridForProdInfo" Grid.Column="0" Grid.Row="2" Margin="0,5,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="75"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="30"/>
                <RowDefinition Height="50"/>
            </Grid.RowDefinitions>
            <Grid Grid.Column="0" Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Label Grid.Column="0" Grid.Row="0" Content="Cod. Barras/Artigo" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="14" Margin="10,0,10,0"/>
                <Label Grid.Column="1" Grid.Row="0" Content="Preço" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="14" Margin="10,0,10,0"/>
            </Grid>
            <Grid Grid.Column="0" Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <TextBox x:Name="textBoxBarCode" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="Wrap" Text="" VerticalContentAlignment="Center" FontSize="16" Margin="10,0,10,0"/>
                <Grid Grid.Column="1" Grid.Row="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBox x:Name="textBoxPrice" Margin="10,0,0,0" TextWrapping="Wrap" Text="{Binding Price, UpdateSourceTrigger=Explicit}" IsReadOnly="True" HorizontalAlignment="Stretch" FontSize="16" VerticalContentAlignment="Center"/>
                </Grid>
            </Grid>
            <Grid Grid.Column="0" Grid.Row="2">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <TextBlock x:Name="textBlockDescription" Grid.Column="0" Grid.Row="0" Margin="10,5,10,0" TextWrapping="WrapWithOverflow" Text="{Binding Descr, Mode=TwoWay, UpdateSourceTrigger=Explicit}" FontSize="16"/>
            </Grid>
            <Grid x:Name="buttonClose" Grid.Column="1" Grid.RowSpan="3" Background="Transparent" Margin="10,10,10,10" MouseDown="buttonClose_MouseDown">
                <Image x:Name="imageClose" Source="/Images/close.png"/>
            </Grid>
        </Grid>
    </Grid>
</Window>

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .