Issue: I am unable to select the Richtextbox 'rtbx_COMMENTS' either using keyboard or mouse. Having tried and retried various properties and values for this control I am at a loss as to why this is not selectable
The controls useage is read only but it needs to be selectable so it can be vertically scrolled
I have manually added the properties IsEnabled="True" and Focusable ="True" into the XAML definition for the control as a belts and braces effort to try and get this control selectable. I even set the stackpanel as focusable wondering if the richtextbox was inheriting properties from it
In the codebehind, I use ONLY the follow to manipulate this control, clearing the control, appending text etc
rtbx_COMMENTS.Document.Blocks.Clear();
rtbx_COMMENTS.AppendText(_x.COMMENT);
where _x.COMMENT refers to a string, example being
"Select If : Gas Issue affecting every burner\r Smell of gas when appliance not in use"
and the XAML
<StackPanel x:Name="spnl_COMMENTS" Orientation="Horizontal" Margin="5,2.5,5,0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="780" Focusable="True">
<Label x:Name="lbl_COMMENTS" Content="COMMENTS" Margin="5,1,0,0" BorderThickness="1" BorderBrush="#FF45CDDA" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="18" Foreground="#FFABA63A" Width="115" TabIndex="-1" Height="145"/>
<RichTextBox x:Name="rtbx_COMMENTS" IsEnabled="True" Focusable ="True" BorderBrush="#FF45CDDA" Padding="2" Margin="0,1,5,0" Background="{x:Null}" Foreground="#FFE48989" IsReadOnly="False" FontSize="16" MinWidth="655" Width="655" Height="145" TabIndex="19" IsHitTestVisible="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" MinHeight="145" IsDocumentEnabled="True" Cursor="Arrow" UseLayoutRounding="False" AllowDrop="False" IsTabStop="True" >
</RichTextBox>
</StackPanel>
Your IsHitTestVisible="False" property in XAML, causes the problem of not selecting the text in rich text box.
Related
In my program, I have a TextBlock where my result text is shown. In a textbox I can just use TextWrapping="Wrap" and I can scroll down if it's still too much for the textbox. Now in my TextBlock that I talked about I wanted to have the same thing and used TextWrapping="Wrap" again. That works except for the scrolling thing. What can I do now to let it scroll like in the textbox?
Use following structure
<ScrollViewer HorizontalScrollBarVisibility="Auto" x:Name="scrView" VerticalScrollBarVisibility="Auto" Width="100" Height="100">
<TextBlock Width="{Binding Path=ActualWidth, ElementName=scrView}" TextWrapping="Wrap">your text</TextBlock>
</ScrollViewer>
I trying to wrap text at textBox but there are no success..
<Grid Margin="0,0,0,0" BorderThickness="1" BorderBrush="Gray">
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" >
<TextBox x:Name="Details" IsReadOnly="True" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Stretch" BorderThickness="0" Height="500" />
</ScrollViewer>
</Grid>
If I have long line without \n I have long string with horizontal scrollbar. But how I understand TextWrapping="Wrap" should cut this string.
I saw this answer but this is not suitable for me because I can have different width of this textBox.
Also I tried to use AcceptsReturn="True" with no success.
I glad to hear any ideas on how to make it works.
I'm not sure if this is what you are looking for, but i'm wondering why you don'disable horizontal Scrolling.
<ScrollViewer Grid.Column="2" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled">
<TextBlock Text="TextusLongusTextusLongusTextusLongusTextusLongusTextusLongusTextusLongusTextusLongus" TextWrapping="Wrap" VerticalAlignment="Stretch"/>
</ScrollViewer>
You don't define any sort of width restriction. Which means that your TextBox can theoratically expand infinitely in width.
Try to either set its width in your XAML code or its maxwidth.
You can also forget about the ScrollViewer. It's already a part of the TextBox and you could just add the elements that you set in your ScrollViewer as an element of the TextBox.
Justt add it like ScrollViewer.VerticalScrollBarVisibility="Visible"
The text in my TextBlock is bound to an element in my code. However, when I first open my window, the Textblock is completely empty. As I add text, I need the ScrollViewer to allow me to scroll down the text, or automatically scroll down as more text is added. Using the MVVM, so no code behind would be ideal.
<StackPanel Grid.Column="0" Grid.Row="1" Margin="0 10">
<Label Style="{StaticResource LabelStyle}">Output</Label>
<ScrollViewer VerticalScrollBarVisibility="Visible" Height="100">
<TextBlock ScrollViewer.CanContentScroll="True" Height="100" VerticalAlignment="Stretch" TextWrapping="Wrap" Text="{Binding Path=ProcessingOutput}"/>
</ScrollViewer>
</StackPanel>
How can I make this happen? Is there a way to update the ScrollViewer so that it sees more text is beyond what I can see in the TextBlock and allows the user to scroll down, or allows me to set an autoscroll feature that scrolls down automatically as text is added via binding?
Thanks in advance!
scrollbar will work if you remove Height="100" from TextBlock
to make it scroll when Text changes other answers suggest to use ScrollViwer.ScrollToBottom() method, e.g. like this:
<ScrollViewer Name="scroll"
VerticalScrollBarVisibility="Visible"
Height="100">
<TextBlock ScrollViewer.CanContentScroll="True"
VerticalAlignment="Stretch"
TextWrapping="Wrap"
Text="{Binding Path=ProcessingOutput, NotifyOnTargetUpdated=True}"
TargetUpdated="Txt_OnTargetUpdated">
</TextBlock>
</ScrollViewer>
private void Txt_OnTargetUpdated(object sender, DataTransferEventArgs e)
{
scroll.ScrollToBottom();
}
I have a WPF application in which i want to add "Expander" control.
The XAML code is like this
<Expander Header="More Options" Margin="30,286,0,0" Height="145" Width="547">
<Grid>
<TextBox Height="104" HorizontalAlignment="Left" Margin="30,286,0,0" Name="logsTextBox" VerticalAlignment="Top" Width="547"
ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" />
</Grid>
</Expander>
The textBox gets updated with the output of the bat file(which runs using Process).
when I run my application, textBox is not visible when expanding the expander.
What property I have to set to make it visible when expanding the expander?
Thanks
The margin property is applied to the parent's region.
Your declaration...
<TextBox Height="104" HorizontalAlignment="Left" Margin="30,286,0,0" Name="logsTextBox" VerticalAlignment="Top" Width="547"
ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" />
...indicates that the TextBox should appear inside the Expander and 286 units BELOW the Exander's top. Remove the TextBox margin and you will see it as expected.
I've two comboBoxes one above another. The problem appear if you open the form that contain this comboBoxes and avoid mouse over at lower comboBox, you just click on first comboBox and from drop down list choose item that is located right over the second comboBox. Once you click on an item the drop down list will close but your mouse will remain over the second comboBox. But this comboBox will not highlight and react on your clicks at all. Take a look at this picture please:
Both comboBoxes IsEditable = false; But if you move your mouse out of the 2nd comboBox and back over to it - everything will works fine. Help me please how to fix this.
UPD. XAML:
<ComboBox Background="{x:Null}" Height="33" HorizontalAlignment="Left" IsEditable="False" IsEnabled="True" Margin="10,151,0,0" Name="comboBox2" VerticalAlignment="Top" Width="239" VerticalContentAlignment="Center" FontSize="14" IsReadOnly="False" Text="" SelectionChanged="comboBox2_SelectionChanged" TabIndex="6" HorizontalContentAlignment="Left" Padding="10,3" FontWeight="SemiBold" AllowDrop="False" Cursor="Hand" IsTabStop="True" />
<ComboBox Background="{x:Null}" FontSize="14" Height="33" HorizontalAlignment="Left" IsEditable="False" IsEnabled="True" Margin="10,190,0,0" Name="comboBox3" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="439" IsReadOnly="False" Text="" SelectionChanged="comboBox3_SelectionChanged" TabIndex="8" HorizontalContentAlignment="Left" Padding="10,3" FontWeight="SemiBold" ClipToBounds="False" Cursor="Hand" IsHitTestVisible="True" SnapsToDevicePixels="True" UseLayoutRounding="True" />
Set Background property to White or Transparent instead of {x:Null}. Null background affects control hit-test behavior.