Background:
I am creating a user interface for the settings page. Settings are saved in the Dictionary, because the settings for each object will be different.
Problem:
ScrollableHeight ScrollViewerDoesn't match the size of the content. When the content ScrollViewerchanges, do not reset, but adds the height of the new content. ScrollableHeight
When:
I am creating content inside Gridwhich is a child of in ScrollViewer. Content RowDefinitionswhere name-value pairs are displayed as TextBlocksand TextBoxes. When another object is selected for editing its properties, the children of the grid are cleared and the user interface for displaying properties is restored. As I mentioned earlier when defining the problem, the created content height is added to the property ScrollViewer ScrollableHeight.
What I learned:
My first thought was to clear ScrollViewer ScrollableHeight, and for each line added, add the height of the line to achieve the desired size. The problem is that ScrollableHeightit cannot be installed (private setter).
Code:
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>
FROM#:
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();
foreach (var property in provider.Properties)
{
var rowDef = new RowDefinition() {Height = new GridLength(30)};
PropertyGrid.RowDefinitions.Add(rowDef);
var tbPropertyName = new TextBlock {
Text = property.Key,
VerticalAlignment = VerticalAlignment.Center
};
var tbPropertyValue = new TextBox {
Text = property.Value.ToString(),
VerticalAlignment = VerticalAlignment.Center
};
PropertyGrid.Children.Add(tbPropertyName);
PropertyGrid.Children.Add(tbPropertyValue);
Grid.SetRow(tbPropertyName, rowCount);
Grid.SetRow(tbPropertyValue, rowCount);
Grid.SetColumn(tbPropertyValue, 1);
rowCount++;
}
}
source
share