I have a FlowDocument that is defined in XAML like this;
<FlowDocumentScrollViewer>
<FlowDocument>
<Paragraph>
<Run>Hello</Run>
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
What I'd like to do is prevent the Find and Zoom controls from appearing when you press Ctrl-F or F3.
Is this possible?
Thanks in advance!
Matt
You could handle the PreviewKeyDown event for this control, and if either Ctrl-F or F3 is pressed, mark the event as handled. This should prevent the control itself from responding to that event and displaying the Find and Zoom controls.
Related
I have a ListBoxItem with a LeftClick Gesture:
<ListBoxItem x:Name="ListViewItemMenu" Content="{Binding Path=Header}" Padding="37 14" FontSize="15" Foreground="White">
<ListBoxItem.InputBindings>
<MouseBinding Gesture="LeftClick" Command="ApplicationCommands.New" />
</ListBoxItem.InputBindings>
</ListBoxItem>
But actually it's not a real Click, it's simply a MouseLeftButtonDown Gesture. The Command is executed regardless of whether the button is raised or not after pressed.
I would like to have a complete Click with the MouseDown and MouseUp Gestures in the ListBoxItem. There is anyway to do that? Much appreciated.
Also I can't find a way to add a Command to an Expander. The method shown above to the ListBoxItem doesn't work. Any magic here? Thanks!
According to this answer you can inherit from MouseGesture to create custom gestures. There is even a full example with implementation.
An alternative is to use an System.Windows.Interactivity.EventTrigger as shown in this answer, which would let you turn the MouseLeftButtonUp or PreviewMouseLeftButtonUp event into a command trigger.
Is it possible to have content behind a scrollviewer that still reacts to user mouse input?
<Grid>
<Button Width="50" Height="50"/>
<ScrollViewer Background="{x:Null}"/>
</Grid>
I've tried combinations of zindexes and null backgrounds, but can't seem to stop the scrollviewer from not tunneling the events down.
To prevent eating clicks, make your scroll viewer non-focusable:
<ScrollViewer Focusable="False" />
The scrollviewer is eating click messages. You don't want to put things behind it.
It would be better to put things inside the scrollviewer. You can make a grid that contains the content and a usercontrol behind the content. The control can be themed to be transparent using a rectangle painted with the color "Transparent". The control would still be clickable, and would still fill up all the space within the scrolled content.
I load WPF Richtextbox contents from Xaml string in which there are some Hyperlinks. When it is loaded into control, Hyperlinks are not clickable! I want to click on them and their associated URL shows up.
No freschx, it's about WPF. A WPF RichTextBox, unlike the one in WinForms, does not have a DetectUrls property. And it's weird you wrote a Xaml code for that, even weirder there is someone who thought it useful.
Check this post out where JHubbard80 and me had two different approaches to solve this problem.
To make the Hyperlink, or any inline UIElement in general, available for hit testing, we must set RichTextBox.IsDocumentEnabled to true.
To make the Hyperlink clickable without pressing the Ctrl key, the Hyperlink must be made read-only e.g., by wrapping it into a TextBlock or by making the complete RichTextBox read-only (by setting RichTextBox.IsReadOnly to false).
<RichTextBox IsDocumentEnabled="True">
<FlowDocument>
<Paragraph>
<Run Text="Some editable text" />
<TextBlock>
<Hyperlink NavigateUri="https://duckduckgo.com">
DuckDuckGo
</Hyperlink>
</TextBlock>
</Paragraph>
</FlowDocument>
</RichTextBox>
Ensure the DetectUrls property on the RichTextbox is set to true. You can then attach an event handler to the link clicked event and do what you wish.
<RichTextBox DetectUrls="True" />
Potential duplicate thread. Credit goes to Sam Meldrum from this thread.
For an even deeper analysis you may wish to try this article.
I have a popup window like this,
<controls:ChildWindow Background="Aquamarine">
<RichTextBox>
<Paragraph x:Name="WarningMessage" >
<Run>Test 1234</Run>
</Paragraph>
</RichTextBox>
</controls:ChildWindow>
I've removed most of the xaml for clarity, but the problem is that I have set the child window to have a background of Aquamarine, but the rich text box control still has a white background.
Is there any way to make the rich text control use the colour of the parent control?
RichTextBox's template defines default background as white. To change it you have to set Background property of the RichTextBox to different color. In your case "Transparent" color will do the trick.
<RichTextBox Background="Transparent">
...
I have a WPF RichTextBox control that I want to behave like a normal RichTextBox in every way except that the user cannot edit the text and the caret is not visible. The issue I'm having is that when I change IsReadOnly to False, the RichTextBox stops reacting to keystrokes. I want it to respond normally to keystrokes like Home, End, PgUp, PgDn, Up, Down. The documentation doesn't mention this behavior.
<RichTextBox
IsReadOnly="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
Width="65" Height="20">
<FlowDocument>
<Paragraph>
Line 1
Line 2
Line 3
</Paragraph>
</FlowDocument>
</RichTextBox>
I've tried adding an OnKeyDown event handler, but it doesn't fire. I've watched the events in Snoop as I push keys with the RichTextBox in keyboard focus and no fired events are shown in Snoop. I've tried setting IsDocumentEnabled explicitly to True, but that also has no effect. I've tried wrapping the RichTextBox in a ScrollViewer, but this has no effect either.
Any suggestions for how I can maintain this RichTextBox as IsReadOnly=True, but get the expected keystroke behavior of a RichTextBox?
Set IsReadOnlyCaretVisible to True
<RichTextBox IsReadOnly="True"
IsReadOnlyCaretVisible="True"
... />
If you don't want the caret to be visible then set the CaretBrush to Transparent
<RichTextBox IsReadOnly="True"
IsReadOnlyCaretVisible="True"
CaretBrush="Transparent"
... />