none
Trying to put DataGrid and Rectangle in a Grid problem

    Question

  • Hi,

    I have a layout problem. In a TabItem my idéa is to put a Rectangle with a Height="50" at the very top and just below, I will put a datagrid.

    So I have tried to use a Grid and put 2 RowDefinitions and put the Rectangle on Grid.Row="0" and the DataGrid on Grid.Row="1". It works when starting up the project but in Blend I cant see the rectangle. I wonder I missing something out here?

                <controls:TabItem Header="Tab1" Foreground="Black" Background="Gray" FontSize="12" Opacity="0" >
    
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="50"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
    
    
    
                        <Rectangle Height="50" Grid.Row="0" Grid.Column="0" Fill="Green">
                        </Rectangle>
    
    
                        <data:DataGrid x:Name="Grid1" Grid.Row="1" Grid.Column="0" CanUserReorderColumns="False" CanUserSortColumns="False" Height="Auto" RowHeight="18" GridLinesVisibility="All" 
    Background="Black" FontSize="11" AutoGenerateColumns="False" RowBackground="Black" 
                                       HorizontalGridLinesBrush="#FF141414" VerticalGridLinesBrush="#FF141414" Foreground="White" BorderBrush="Gray"  BorderThickness="0.2" VerticalAlignment="Top" Margin="-5,-5,-5,0"   >
                        <data:DataGrid.Columns>
                            
                            <data:DataGridTemplateColumn>
                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Height="22" Background="Transparent">
                                            <TextBox Text="{Binding gtNum}" BorderThickness="0"  Background="{Binding gtNumColor}" FontSize="11" Foreground="White" IsReadOnly="True" IsEnabled="False"></TextBox>
                                        </StackPanel>
                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>
                            </data:DataGridTemplateColumn>
    
                        </data:DataGrid.Columns>
                    </data:DataGrid>
                    </Grid>
                </controls:TabItem>
    
    Tuesday, March 27, 2012 12:39 PM

Answers

All replies

  • Strangely it seems that is appeared in Blend. So I think this is solved.

    Tuesday, March 27, 2012 12:50 PM
  • follow the sample
    <UserControl              
        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:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
        xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" mc:Ignorable="d"                 
                 x:Class="SilverlightApplication1.MainPage"
        d:DesignHeight="300" d:DesignWidth="400" Height="600" Width="1000">  
    
        <Grid x:Name="LayoutRoot" >   
            <controls:TabControl >
                <controls:TabItem Header="First Item">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                            <RowDefinition Height="10*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Rectangle Height="50" Grid.Row="0" Grid.Column="0" Fill="Green">
                        </Rectangle>
                        <data:DataGrid x:Name="DtGrid" Grid.Row="1" Grid.Column="0" AutoGenerateColumns="False" SelectionChanged="DtGrid_SelectionChanged"    >
                            <data:DataGrid.Columns>
                                <data:DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
                                <data:DataGridTextColumn Header="Designation" Binding="{Binding Designation}"/>
                                <data:DataGridTextColumn Header="Dept" Binding="{Binding Dept}"/>
                            </data:DataGrid.Columns>
                        </data:DataGrid>
                    </Grid>
                </controls:TabItem>
            </controls:TabControl>
        </Grid>
    </UserControl>
    Tuesday, March 27, 2012 12:53 PM