views:

89

answers:

1

From a UserControl, I would like to disable a ScrollViewer which is defined one level higher. My scenario looks something like this:

<!-- ... -->
<ScrollViewer VerticalScrollBarVisibility="Auto"
              HorizontalScrollBarVisibility="Disabled">
    <custom:MyUserControl ... />
</ScrollViewer>

Now, I would like to disable the ScrollViewer from within MyUserControl. Is this possible?

Background:
I have defined a custom TabControl style where I added a ScrollViewer for each item's content automatically. However, in one case, I do not want to use that ScrollViewer, but rather make the content size to the available space, whereas in all other cases I do want to use the ScrollViewer. Any ideas? Of course, I could add a ScrollViewer to every tab item manually, except for the one item, but that is not what I want.

A: 

In code you should be able to do it like this:

try
{
    ((ScrollViewer)Parent).IsEnabled = false;
}
catch (Exception exc)
{
    MessageBox.Show(exc.Message);
}

I've also done it before using triggers in XAML if you need to do it that way let me know and I can post code

Oliver
Thanks for the answer. Unfortunately, code-behind is not an option in my case. How would you do that in XAML? Would be great if you could post the code.
gehho
Reading over your question again, I think that what I have previously done does not resolve your question. Simply disabling the ScrollViewer will not change any layout of the items inside, it just wont scroll, so it wont make the content size to the available space.It sounds like you might be able to define another TabControl style without the ScrollViewer in it, rather than having a disabled ScrollViewer.
Oliver