Question

Can somebody give me an idea of why the Wrapping is not working inide these Textblocks? I just don't know why, i changed all my stackpanels to grids to avoid the infinite space issue, but still it doesn't work...

<Border x:Name="SummaryRightSideContainerBorder" Grid.Column="1"
        Margin="10,10,10,10" BorderBrush="Black"
        BorderThickness="1">
    <ContentControl x:Name="SummaryRightSideContainerContentControl" Content="{Binding SelectedItem, ElementName=SummaryTreeView}">
        <ContentControl.Resources>
            <DataTemplate DataType="{x:Type ViewModelsProject:ProjectViewModel}">
                <StackPanel>
                    <TextBlock Text="Displaying Project DataContract stuff..." />
                </StackPanel>
            </DataTemplate>
            <DataTemplate DataType="{x:Type ViewModelsProject:SequenceViewModel}">
                <StackPanel>
                    <TextBlock Text="Displaying Sequence DataContract stuff..." />
                </StackPanel>
            </DataTemplate>
            <DataTemplate DataType="{x:Type ViewModelsProject:GroupViewModel}">
                <StackPanel>


                    <DataGrid Margin="10" AutoGenerateColumns="False"
                                  Background="Transparent" BorderThickness="0"
                                  CanUserAddRows="False"
                                  CellStyle="{DynamicResource dgCellStyle}"
                                  ColumnHeaderStyle="{DynamicResource dgHeader}"
                                  DataContext="{Binding ElementName=SummaryTreeView,
                                                        Path=SelectedItem}"
                                  GridLinesVisibility="None"
                                  ItemsSource="{Binding Standards}"
                                  Padding="0" RowHeaderWidth="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                        <DataGrid.Resources>
                            <Style x:Key="dgHeader" TargetType="{x:Type DataGridColumnHeader}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                                            <TextBlock Width="{TemplateBinding Width}"
                                                           Padding="5"
                                                           Text="{TemplateBinding Content}"
                                                           TextAlignment="Left">
                                                    <TextBlock.Background>
                                                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                            <GradientStop Offset="0.0" Color="#373638" />
                                                            <GradientStop Offset="1.0" Color="#77797B" />
                                                        </LinearGradientBrush>
                                                    </TextBlock.Background>
                                            </TextBlock>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="OverridesDefaultStyle" Value="True" />
                                <Setter Property="Background" Value="Green" />
                                <Setter Property="Foreground" Value="White" />
                                <Setter Property="FontSize" Value="12" />
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                            <GradientStop Offset="0.0" Color="#373638" />
                                            <GradientStop Offset="1.0" Color="#77797B" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <Style x:Key="dgCellStyle" TargetType="{x:Type DataGridCell}">
                                <Style.Triggers>
                                    <Trigger Property="DataGridCell.IsSelected" Value="True">
                                        <Setter Property="Background" Value="White" />
                                        <Setter Property="Foreground" Value="Black" />
                                        <Setter Property="BorderThickness" Value="0" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.Resources>
                        <DataGrid.Columns>
                            <DataGridTemplateColumn Header="Standards">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>


                                        <Grid Margin="5">
                                            <Grid.RowDefinitions>
                                                <RowDefinition />
                                                <RowDefinition />
                                            </Grid.RowDefinitions>
                                            <TextBlock Grid.Row="0" Text="{Binding Path=StepMaster.Description}" VerticalAlignment="Center" FontWeight="SemiBold"/>
                                            <Grid Grid.Row="1">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition />
                                                    <RowDefinition />
                                                    <RowDefinition />
                                                </Grid.RowDefinitions>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Grid.Row="0" Grid.Column="0" Text="Standard: " VerticalAlignment="Top"/>
                                                <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Standard}" Margin="5,0,0,0" VerticalAlignment="Top" TextWrapping="Wrap"/>

                                                <TextBlock Grid.Row="1" Grid.Column="0" Text="Details: " VerticalAlignment="Top"/>
                                                <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Details}" Margin="5,0,0,0" VerticalAlignment="Top" TextWrapping="Wrap"/>

                                                <TextBlock Grid.Row="2" Grid.Column="0" Text="Comments: " VerticalAlignment="Top"/>
                                                <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Path=Comments}" Margin="5,0,0,0" VerticalAlignment="Top" TextWrapping="Wrap"/>
                                            </Grid>
                                        </Grid>

                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>


                </StackPanel>
            </DataTemplate>
            <DataTemplate DataType="{x:Type ViewModelsProject:StepViewModel}">
                <UniformGrid Rows="3">
                    <TextBlock Margin="10" FontWeight="DemiBold"
                               Text="Standards" />
                    <TextBlock Margin="10" FontWeight="DemiBold"
                               Text="Standards Details" />
                    <StackPanel Orientation="Vertical">
                        <DataGrid Margin="10" AutoGenerateColumns="False"
                            <Another data grid is here />
                        </DataGrid>
                    </StackPanel>
                </UniformGrid>
            </DataTemplate>
        </ContentControl.Resources>
    </ContentControl>
</Border>
Was it helpful?

Solution

Turns out the only way to make this work is to use properties directly in the DataGrid:

MaxWidth="{Binding ElementName=SummaryRightSideContainerBorder, Path=ActualWidth}" ColumnWidth="*" 

MaxWidth is used so that the Datagrid itself does not exceed its container boundaries and ColumnWidth is used so that the columns use 100% of the space available in the datagrid.

Blam's answer put me in the right track to find the solution.

OTHER TIPS

As an answer you need to set second column to

<ColumnDefinition Width="*"/>

so it is constrained. * mean the size of the container. Right now it is growing outside the container (screen)

first column auto is OK

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top