我正在尝试创建一个如下所示的表,
这是我的代码:
<my:DataGrid>
<my:DataGrid.Columns>
<my:DataGridTextColumn Header="Class"/>
<my:DataGridTextColumn Header="Sec"/>
<my:DataGridTextColumn Header="Monday"/>
<my:DataGridTextColumn Header="Tuesday"/>
<my:DataGridTextColumn Header="Wednesday"/>
<my:DataGridTextColumn Header="Thursday"/>
<my:DataGridTextColumn Header="Friday"/>
</my:DataGrid.Columns>
</my:DataGrid>
如何在列星期一中包含第1列到第8列 能帮到我吗?
答案 0 :(得分:1)
你走了,
<UserControl xmlns:Controls1="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="SilverlightApplication2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:Primitives="clr-namespace:System.Windows.Controls.Primitives;assembly= System.Windows.Controls.Data"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Controls1:DataGrid>
<Controls1:DataGrid.Columns>
<Controls1:DataGridTemplateColumn Header="Monday" Width="2.5*">
<Controls1:DataGridTemplateColumn.HeaderStyle>
<Style TargetType="Primitives:DataGridColumnHeader" BasedOn="{StaticResource ColumnHeaderStyle}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Primitives:DataGridColumnHeader">
<Grid Name="Root">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed"/>
</VisualStateGroup>
<VisualStateGroup x:Name="SortStates">
<VisualState x:Name="Unsorted" />
<VisualState x:Name="SortAscending"/>
<VisualState x:Name="SortDescending"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Rectangle x:Name="BackgroundRectangle" Stretch="Fill" Fill="Yellow" Grid.ColumnSpan="2" />
<Rectangle x:Name="BackgroundGradient" Stretch="Fill" Grid.ColumnSpan="2" >
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#FFB93A42" Offset="0" />
<GradientStop Color="#FF48030A" Offset="1" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" Grid.Column="0" Grid.ColumnSpan="2">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Monday" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="2" Grid.Row="0"/>
<Border Grid.Row="1" Background="White" BorderBrush="White" BorderThickness="1" Height="1" />
<Grid Grid.Row="2" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<TextBlock Margin="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" Text="1"/>
<TextBlock Margin="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Text="2"/>
<TextBlock Margin="2" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Text="3"/>
<TextBlock Margin="2" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Center" Text="4"/>
<TextBlock Margin="2" Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Text="5"/>
</Grid>
</Grid>
<Rectangle Name="VerticalSeparator" Grid.Column="1" Width="1" VerticalAlignment="Stretch" Fill="{TemplateBinding SeparatorBrush}" Visibility="{TemplateBinding SeparatorVisibility}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Controls1:DataGridTemplateColumn.HeaderStyle>
<Controls1:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<TextBlock Margin="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding 1}"/>
<TextBlock Margin="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding 2}"/>
<TextBlock Margin="2" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding 3}"/>
<TextBlock Margin="2" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding 3}"/>
<TextBlock Margin="2" Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding 4}"/>
</Grid>
</DataTemplate>
</Controls1:DataGridTemplateColumn.CellTemplate>
</Controls1:DataGridTemplateColumn>
</Controls1:DataGrid.Columns>
</Controls1:DataGrid>
</Grid>
</UserControl>
答案 1 :(得分:0)
您只需要在其中一个单元格中放入另一个数据网格。 第二个数据网格将包含2行:第一行表示星期一,第二行应该有8列。