youkebb
youkebb

Reputation: 161

WPF xaml conditionally add control?

i have the following xaml structure

<Grid>
     <Grid x:Name="innerGrid" Background="{TemplateBinding Background}"/>
</Grid>

the problem is that the inner grid may sometimes be big so a around it is needed and it should be changed to

<Grid>
     <ScrollViewer>
        <Grid x:Name="innerGrid" Background="{TemplateBinding Background}"/>
     <ScrollViewer>
</Grid>

but this should not always happen. I'm thinking to create a dependency property and based on the value if it's true then i will add and false stay the same as before. Is there a way to achieve this?

Upvotes: 0

Views: 380

Answers (1)

Flat Eric
Flat Eric

Reputation: 8111

If you want to show the scrollbar only when the content is too large for one page you can use this:

<Grid>
  <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
    <Grid />
  </ScrollViewer>
</Grid>

Upvotes: 4

Related Questions