Lo que quiero: me gustaría tener un ScrollView en mi aplicación de Silverlight 4, que crece en altura junto con el contenido, pero sí muestra una barra de desplazamiento si de lo contrario crecería más alto que su contenedor.creciente ScrollView (Altura = "Auto" MaxHeight = "estiramiento")
soluciones que he encontrado: me encontré con un montón de preguntas, donde la solución era estirar la ScrollViewer pero que es no lo que quiero. El Scrollviewer siempre debe ser lo más pequeño posible.
Mi Problema: para que sea un poco más difícil en la parte superior de la ScrollViewer una cabecera se encuentra que es un StackPanel con la altura estática.
Solución approch 1: lo probé en primer lugar con XAML llano, pero no puedo averiguar cómo debería funcionar.
<Grid Height="Auto" x:Name="myGrid" >
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Background="AliceBlue">
<!-- Dummy Header-->
</StackPanel>
<ScrollViewer Grid.Row="1" Height="Auto">
<Button Width="100" Height="50" Click="Button_Click" />
<!-- onClick the button will switch between height="600" and height="50"
Code:
private void Button_Click(object sender, RoutedEventArgs e)
{
if (sender is Button)
{
Button btn = (Button)sender;
btn.Height = (btn.Height == 50) ? 600 : 50 ;
}
}
-->
</ScrollViewer>
</Grid>
Si hace clic en el botón, se vuelve más alto y el Scrollviewer se cortará debido a que es alto. Alguna sugerencia?
Solución Enfoque 2: Entonces trató de establecer el máximo * * Altura de la ScrollViewer con el ActualHeight del recipiente que contiene, por lo tanto inseted StackPanel alrededor del ScrollViewer. Esto funciona en el diseñador de VSAM XAML pero no en la ejecución del código. No tengo ni idea de por qué ...
<Grid Height="Auto" x:Name="myGrid" >
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Background="AliceBlue">
<!-- Dummy Header-->
</StackPanel>
<StackPanel Grid.Row="1" x:Name="myStackPanel" Height="Auto" VerticalAlignment="Stretch">
<ScrollViewer Height="Auto" MaxHeight="{Binding ElementName=myStackPanel, Path=ActualHeight}">
<Button Width="100" Height="50" Click="Button_Click" />
<!-- onClick the button will switch between height="600" and height="50"
Code:
private void Button_Click(object sender, RoutedEventArgs e)
{
if (sender is Button)
{
Button btn = (Button)sender;
btn.Height = (btn.Height == 50) ? 600 : 50 ;
}
}
-->
</ScrollViewer>
</StackPanel>
</Grid>
¡Gracias de antemano!
Bien, funciona. ¡Y tu explicación me hace sentir totalmente! ¡Muchas gracias! – heynest