0

I try to make multiline row at ListBox.

So, i read this question and make this xaml:

<ListBox Grid.Row="1" x:Name="lbKeyPhrases" BorderBrush="Gray" 
      ItemsSource="{Binding  Templates}"                                         
      IsSynchronizedWithCurrentItem="True" 
      Focusable="True"                                                                   
      ScrollViewer.HorizontalScrollBarVisibility="Disabled"
      ScrollViewer.VerticalScrollBarVisibility="Auto"
      HorizontalContentAlignment="Stretch" Grid.ColumnSpan="2"                                         
      >
    <ListBox.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Add Word" Click="MenuItem_Click">
                <Image Source="/SomeProj.UI.Resources;component/PNGImages/ItemAdd.png"/>
            </MenuItem>
        </ContextMenu>
    </ListBox.ContextMenu>

    <ListBox.ItemTemplate>
        <DataTemplate>
            <DockPanel>
                <Border x:Name="brRow" BorderThickness="1" BorderBrush="LightGray" 
                        Background="WhiteSmoke"
                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <TextBox x:Name="tblbRow" 
                             Text="{Binding Text,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Tag="{Binding}" 
                             GotFocus="tblbRow_GotFocus"
                             AcceptsReturn="True"                                    
                             TextWrapping="Wrap" Margin="2"
                             Focusable="True"
                             Background="Transparent"
                             HorizontalAlignment="Stretch"
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                             >
                        <TextBox.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Remove Word"
                                          Click="MenuItem_Click_RemoveTemplate">
                                    <Image Source="/SomeProj.UI.Resources;component/PNGImages/ItemDel.png"/>
                                </MenuItem>
                            </ContextMenu>
                        </TextBox.ContextMenu>
                    </TextBox>
                </Border>
            </DockPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

But is seems, that is not work for me. I use TextBox instead TextBlock, because i need to edit line. So, i want if text line will be very large- it wraps to mulitile.

And Scroll not diposed (but should be).

Can you tell me, how to do that?

P.S. it seems that Scroll not disposed,because it is from another Grid.

Community
  • 1
  • 1
Admiral Land
  • 2,304
  • 7
  • 43
  • 81
  • Your XAML seems to work properly... are you sure there is not something else (i.e. a style) that does not allow your `TextBox` to wrap? – Il Vic Apr 08 '16 at 08:26
  • @IlVic, At upper Grid, ScrollViewer.HorizontalScrollBarVisibility="Auto",ScrollViewer.CanContentScroll="True" – Admiral Land Apr 08 '16 at 08:56
  • 1
    Does a horizontal scrollbar appear when it get's long enough that it should be wrapping? (Ignore me, noticed you have ScrollViewer.HorizontalScrollBarVisibility="Disabled") – Joe Apr 08 '16 at 11:50
  • 1
    I had an issue where a style I had targeting ScrollViewer was missing this ``. I would check to make sure this is not the case. `CanContentScroll="False"` reproduces this exact problem. –  Apr 08 '16 at 15:36
  • @Joe, when i set large text, i have a horizontal scroll.... and no wrapping – Admiral Land Apr 08 '16 at 19:22

2 Answers2

1

As requested, my comment as an answer:

Does a horizontal scrollbar appear when it get's long enough that it should be wrapping? The wrapping is not occuring because the content can scale as much as it wants within the ScrollViewer. Wrapping comes secondary to the control filling all horizontal space, so allowing it to scroll allows it to consume an infinite space.

Setting:

ScrollViewer.HorizontalScrollBarVisibility="Disabled"

in the control containing your textbox (the ListBox) should prevent this behavior.

Joe
  • 6,773
  • 2
  • 47
  • 81
0

@Joe was right: upper grid have ScrollView.HorizontalBarVisible:Auto, so i change it to Disable and it works!

Admiral Land
  • 2,304
  • 7
  • 43
  • 81
  • Great, I must have totally misread your code because I thought I'd checked and saw you already put ScrollViewer.HorizontalScrollBarVisibility="Disabled". Glad I made the comment anyway though! – Joe Apr 11 '16 at 08:45
  • @Joe, you can write your own answer and i make it as right answer, because your advice help me. – Admiral Land Apr 13 '16 at 06:32