I have the following controls:
<UserControl >
<!--<ScrollViewer >-->
<Viewbox >
<Canvas/>
</Viewbox>
<!--</ScrollViewer>-->
</UserControl>
I want to add and remove dynamically the ScrollViewer as my ViewBox parent (for example when I click a Button):
private void Button_Click(object sender, RoutedEventArgs e)
{
// Here add or remove ScrollViewer
}
How can I do?
Assuming your
UserControlis nameduserControl:Why set the
Contenttonull, you might wonder? Because WPF won’t let you have one element be the child of two elements at once, and immediately throws an exception if you try to do that (e.g. by just sayinguserControl.Content = scrollViewer.Content;).