バックグラウンド:
設定ページのUIを生成しています。設定は問題のオブジェクトごとに異なるため、設定はディクショナリ内に保存されます。
問題:
ScrollableHeight
aのはScrollViewer
、コンテンツのサイズに正確ではありません。ScrollViewer
変更の内容がScrollableHeight
リセットされると、はリセットされませんが、新しい内容の高さが追加されます。
いつ:
Grid
内の子要素である、内でコンテンツを生成していScrollViewer
ます。RowDefinitions
名前と値のペアがTextBlocks
ととして表示されるコンテンツTextBoxes
。プロパティを編集するために別のオブジェクトを選択すると、グリッドの子がクリアされ、プロパティを表示するためのUIが再生成されます。問題の定義で前述したように、生成されたコンテンツの高さはScrollViewer
のScrollableHeight
プロパティに追加されます。
私が学んだこと:
ScrollViewer
私の最初の考えは、をクリアし、ScrollableHeight
追加された行ごとに、正しいサイズを実現するために行の高さを追加することでした。問題は、ScrollableHeight
設定できないことです(プライベートセッター)。
コード:
XAML:
<ScrollViewer Name="svScroller" Grid.Row="0">
<Grid x:Name="gdPropertyGrid" Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="35*" />
<ColumnDefinition Width="65*" />
</Grid.ColumnDefinitions>
</Grid>
</ScrollViewer>
C#:
//Get Selected Item
var listBox = ((ListBox)sender);
var provider = listBox.SelectedItem as IProviderConfiguration;
if (provider != null)
{
tbTitle.Text = String.Format("Properties for {0}",provider.Name);
int rowCount = 0;
PropertyGrid.Children.Clear();
//Get properties
foreach (var property in provider.Properties)
{
//Create Grid Row
var rowDef = new RowDefinition() {Height = new GridLength(30)};
PropertyGrid.RowDefinitions.Add(rowDef);
//Create Name Label
var tbPropertyName = new TextBlock {
Text = property.Key,
VerticalAlignment = VerticalAlignment.Center
};
//Create Value input
var tbPropertyValue = new TextBox {
Text = property.Value.ToString(),
VerticalAlignment = VerticalAlignment.Center
};
//Add TextBlock & TextBox Grid
PropertyGrid.Children.Add(tbPropertyName);
PropertyGrid.Children.Add(tbPropertyValue);
//Set Grid.Row Attached property
Grid.SetRow(tbPropertyName, rowCount);
Grid.SetRow(tbPropertyValue, rowCount);
Grid.SetColumn(tbPropertyValue, 1);
rowCount++;
}
}