Answered by:
BringIntoView doesnt work properly when height is set for the stackpanel inside the ScrollViewer

Question
-
The BringIntoView doesnt work properly when height is set for the stackpanel inside the scrollviewer.
Scroll position should be moved when the bringintoview is used inside the panel but doesnt work.
But when height is removed in stackpanel and added in scrollviewer its working fine.
Code Snippet:
MainWindow.xaml
<Window x:Class="Panelcheck.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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"
xmlns:local="clr-namespace:Panelcheck"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<ScrollViewer x:Name="scrollViewer" VerticalScrollBarVisibility="Visible">
<StackPanel Height="300" CanVerticallyScroll="True">
<Button Height="30" Width="100" Content="button1" Click="Button_Click" />
<Button Height="30" Width="100" Content="button2"/>
<Button Height="30" Width="100" Content="button3"/>
<Button Height="30" Width="100" Content="button4"/>
<Button Height="30" Width="100" Content="button5"/>
<Button Height="30" Width="100" Content="button6" />
<Button Height="30" Width="100" Content="button7" />
<Button Height="30" Width="100" Content="button8"/>
<Button Height="30" Width="100" Content="button9"/>
<Button Height="30" Width="100" Content="button10"/>
<Button Height="30" Width="100" Content="button11"/>
<Button Height="30" Width="100" Content="button12" />
<Button Height="30" Width="100" Content="button13"/>
<Button Height="30" Width="100" Content="button14"/>
<Button Height="30" Width="100" Content="button15"/>
<Button Height="30" Width="100" Content="button16"/>
<Button Height="30" Width="100" Content="button17"/>
<Button Height="30" Width="100" Content="button18"/>
<Button Height="30" Width="100" Content="button19"/>
<Button Height="30" Width="100" Content="button20" x:Name="button20"/>
</StackPanel>
</ScrollViewer>
<Button x:Name="buttonClick1" Height="30" Width="150" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Click="ButtonClick1_Click"></Button>
</Grid>
</Window>MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
button20.BringIntoView();
}
private void ButtonClick1_Click(object sender, RoutedEventArgs e)
{
button20.BringIntoView();
}
}Expected result:
The bringintoview must be work when button is placed inside the panel.
Regards,
Hari Prasad.M
- Moved by Dave PatrickMVP Tuesday, November 10, 2020 2:33 PM looking for forum
Tuesday, November 10, 2020 1:05 PM
Answers
-
I'd try asking for help over here.
https://docs.microsoft.com/en-us/answers/topics/windows-forms.html
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Guido Franzke Wednesday, November 11, 2020 7:05 AM
- Marked as answer by Guido Franzke Tuesday, November 17, 2020 6:51 AM
Tuesday, November 10, 2020 2:33 PM
All replies
-
I'd try asking for help over here.
https://docs.microsoft.com/en-us/answers/topics/windows-forms.html
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Guido Franzke Wednesday, November 11, 2020 7:05 AM
- Marked as answer by Guido Franzke Tuesday, November 17, 2020 6:51 AM
Tuesday, November 10, 2020 2:33 PM -
The problem is because you specify the StackPanel Height="300". Remove the Height will resolve the issue.Wednesday, November 18, 2020 1:05 AM