0

I have a pretty complicated task that I couldn't find much on resolving online. I have a WPF application consisting of a frame connecting to different pages in it. Sometimes, depending on the screen size, the content can't fit inside. To combat this I added a scrollviewer to the frame. Now the textbox height resize to the content within it. I need that size to stay the same size. But, when the window gets changed the textboxes need to be responsive. Not sure on how to limit changing the screen size only when needed. Here is some of my code:

Main.cs ~Holding the scrollviewer and frame

<ScrollViewer Grid.Row="2"
                      Grid.Column="1"
                      >
            
        <Frame x:Name="ActiveItem"
               NavigationUIVisibility="Hidden"
               Background="White"
               ScrollViewer.VerticalScrollBarVisibility="Auto"
               ScrollViewer.CanContentScroll="False"
               />
        </ScrollViewer>

Snippit of long ~2000 line:

<Grid.RowDefinitions>
    <RowDefinition Height="3*" />
</Grid.RowDefinitions>
<TextBox x:Name="text"  
   Grid.Row="0" />

I need the textbox to only resize when the window resizes but stay the same when content is added to ensure the textbox overflows. Removing the Scrollviewer from the frame does allow the textbox to have the scrollbar but then the content can't fit on the screen.

Edit:

To simply the question, basically, I am asking how do you allow the textbox to only resize when the window resizes and not when a user adds content without specifying the height directly? Thank you to anyone who is able to assist with this conundrum!

Jakxna360
  • 857
  • 2
  • 9
  • 31

1 Answers1

0

After Reframing my question, stackoverflow provided me with a better related question that answered my issue. The question is here: TextBox expanding with surrounding Grid but not with text

Basically I had to put in a border around the textbox like so:

<Grid.RowDefinitions>
    <RowDefinition Height="3*" />
</Grid.RowDefinitions>
<Border x:Name="textboarder">
<TextBox x:Name="text"  
   Grid.Row="0"
   Width="{Binding ActualWidth, ElementName=Descriptionboarder}"
   Height="{Binding ActualHeight, ElementName=Descriptionboarder}"
 />
</Border>

Read the full answer here for a much better idea: https://stackoverflow.com/a/2591489/1441143

Jakxna360
  • 857
  • 2
  • 9
  • 31