この例のデータグリッドが、それを含む Grid.Row の境界を超えて大きくなると、なぜデータグリッドが切り取られるのか教えてもらえますか? VS 2010 の「Silverlight アプリケーション」テンプレートで使用できる xaml とコード ビハインドを次に示します。前もって感謝します。
<UserControl
x:Class="SilverlightApplication3.MainPage"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
mc:Ignorable="d" >
<Grid>
<Border>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- header -->
<Border Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="40" >
</Border>
<!-- employee category selection -->
<Grid Grid.Row="1" Margin="10">
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Category:" Margin="0,0,10,0" VerticalAlignment="Center" />
<ComboBox ItemsSource="{Binding EmployeeTypes}" SelectedItem="{Binding EmployeeType, Mode=TwoWay}" MinWidth="100" />
</StackPanel>
<Border BorderBrush="Black" BorderThickness="10" Height="2" Margin="0,10,0,0" ></Border>
</StackPanel>
</Grid>
<!-- content -->
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- daily employee grid -->
<Grid Grid.Row="0" Visibility="Visible" Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Text="Category Type:" />
<ComboBox ItemsSource="{Binding Categories}"
SelectedItem="{Binding Category, Mode=TwoWay}"
DisplayMemberPath="Name" HorizontalAlignment="Left" Width="250">
</ComboBox>
<TextBlock Text="Category Types:" Margin="0,10,0,0" />
<sdk:DataGrid x:Name="dataGrid" AutoGenerateColumns="True"
HorizontalAlignment="Left" VerticalAlignment="Stretch" MinWidth="250" VerticalScrollBarVisibility="Visible" >
<sdk:DataGrid.ColumnHeaderStyle>
<Style TargetType="sdk:DataGridColumnHeader">
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</sdk:DataGrid.ColumnHeaderStyle>
</sdk:DataGrid>
</StackPanel>
</Grid>
</Grid>
<!-- buttons -->
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,0,0" >
<Button Command="{Binding SaveCommand}"
Width="80" HorizontalContentAlignment="Center" Margin="0,0,2,0">
<StackPanel Orientation="Horizontal">
<Image Source="../Images/Approve24x24.png" Height="24" Width="24"/>
<TextBlock Text="Save" VerticalAlignment="Center" Margin="2"/>
</StackPanel>
</Button>
<Button Command="{Binding CancelCommand}"
Width="80" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<Image Source="../Images/Delete24x24.png" Height="24" Width="24"/>
<TextBlock Text="Cancel" VerticalAlignment="Center" Margin="2"/>
</StackPanel>
</Button>
</StackPanel>
</Grid>
</Border>
</Grid>
および分離コード:
using System.Collections.Generic;
System.Windows.Controls を使用します。
名前空間 SilverlightApplication3 { public 部分クラス MainPage : UserControl { public MainPage() { InitializeComponent();
List<string> testItems = new List<string>();
for (int i = 0; i < 50; i++)
{
testItems.Add(string.Format("Item Number {0}", i.ToString()));
}
this.dataGrid.ItemsSource = testItems;
}
}
}