Tapped event of RichTextblock - windows-store-apps

Why we can not handle the tapped event of richtextblock, I want to get the tapped point of the richtextblock or richtextblockoverflow, how to workaround?

if you set IsTextSelectionEnabled to false its work but you cant use ScrollViewer to scroll i solved this with this issue
this.RichTextBlock.AddHandler(TappedEvent, new TappedEventHandler(RichTextBlock_Tapped), true);
private void medical_history_Tapped(object sender, TappedRoutedEventArgs e)
{
}
hope this helped you!

Related

WebBrowser Control TextInput events

I'm struggling with the WebBrowser control (both in Winforms and WPF). Basically I want to achieve the same behavior I got with a RTF editor: Handling some kind of OnTextInput event in order to get the last typed character for every keystroke.
I mean the textual characters, not Control, Alt, F5, Enter, ... that can be captured with the Keydown/Keyup events.
Any help? Thanks in advance.
You can hanlde KeyPress event of this.webBrowser1.Document.Body:
private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://www.google.com");
//Attach a handler to DocumentCompleted
this.webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//Attach a handler to Body.KeyPress when the document completed
this.webBrowser1.Document.Body.KeyPress += Body_KeyPress;
}
void Body_KeyPress(object sender, HtmlElementEventArgs e)
{
//handle the event, for example show a message box
MessageBox.Show(((char)e.KeyPressedCode).ToString());
}
Note:
It doesn't handle non-input keys as you need.
You can also suppress the input by setting e.ReturnValue = false; based on some criteria if you need.
You can also handle other key events like KeyUp and KeyDown the same way

MediaElement Windows phone 8.1

I have a weird bug here and i don't know how to call this,but here's the thing.. i have my MediaElement in my XAML ->> <MediaElement Height="10" Width="10" x:Name="Nomes"/> and i have a Button to call that Element which is mp3 audio, and works fine C# ->>
private async void AMN(object sender, RoutedEventArgs e)
{
Nomes.Source = new Uri("ms-appx:///Sounds/AMN.mp3", UriKind.RelativeOrAbsolute);
Nomes.Play();
await Task.Delay(TimeSpan.FromSeconds(1));
VibrationDevice vb = VibrationDevice.GetDefault();
vb.Vibrate(TimeSpan.FromMilliseconds(100));
await Task.Delay(TimeSpan.FromSeconds(1));
Frame.Navigate(typeof(AmericaDoNorte));
}
Here is my SecondPage Override Method
protected override void OnNavigatedTo(NavigationEventArgs e)
{
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if(rootFrame == null)
{
return;
}
if (rootFrame.CanGoBack)
{
rootFrame.GoBack();
e.Handled = true;
}
}
And when the Vibrate Method is call i navigate through a new page,and works fine,but when i comeback to that page, the audio which supposed be to play when i hit the button play by yourself without i click, how this is possible? Thanks!
I guess your MediaElement property AutoPlay is enabled. Go to properties and have a look.
Hope this helps.
Thanks!

Windows phone 8.1 backbutton not returning to last form

When I go to the login page with this code.
private void AppBarButton_Click_1(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(LoginPage));
}
But when I push the back button on the loginpage it does not go back to the first page. Did I do something wrong?
This is the code I use in my App.xaml.cs
void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame != null && rootFrame.CanGoBack)
{
e.Handled = true;
rootFrame.GoBack();
}
}
Fixed the issue by changing the blank pages to Basic pages. Now it will de all the backbutton navigation automatic.
Fixed the issue by changing the blank pages to Basic pages. Now it will de all the backbutton navigation automatic.

Back button to go back in WebBrowser WP8 youtube site

I made a WebBrowser and it works except the back button in a youtube site. Youtube have a redirect to mobile version and this cause a loop
this code not works
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
webBrowser.InvokeScript("eval", "history.go(-1)" );
}
I know if it is a redirect (302) in this event?
webBrowser_Navigated(object sender, NavigationEventArgs e)
In the WebBrowserControl documentation you can find all available methods and events.
It is not very pretty but you should try that:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
webBrowser.GoBack();
e.Cancel = true;
}
void webBrowser_Navigating(object sender, NavigatingEventArgs e)
{
if (e.Uri.ToString().Contains("YouTubeUriYouGetAlwaysRedirectedTo"))
{
// Do some stuff here
e.Cancel = true;
}
}

Better way of logic loop while button is pressed?

So I have a button on a WinRT UserControl that I want to increase or decrease a integer value (CurrentValue) while you hold down the button.
I ended up with this implementation below, which works but does not look to good or is it okay?
I searched for an event to use but I got stuck using click and setting the button.clickmode to press.
I use the bool _increasePushed to track if already pushed in so I don't get multiple event triggers.
private bool _increasePushed;
private const int PushDelay = 200;
private async void ButtonIncreaseClick(object sender, RoutedEventArgs e)
{
var button = sender as Button;
if (button == null) return;
if (_increasePushed)
{
return;
}
_increasePushed = true;
while (button.IsPressed)
{
CurrentValue++;
await Task.Delay(PushDelay);
}
_increasePushed = false;
}
XAML on UserControl
<Button x:Name="buttonIncrease" Content="Bla bla"
Click="ButtonIncreaseClick" ClickMode="Press" />
The better way would be to use a RepeatButton which does exactly what you are trying to replicate. It has a Delay property to wait for the first repeated click as well as an Interval property that controls how often the Click event is raised.