I've got a little help from another Thread here, which I not fully understood.
It's a UserControl which differentiates between several types of texts and makes them look like as one single textbox. Some of the types (i.e. Hyperlinks) are clickable.
To click on them I've got this code.
public class RelayCommand<T> : ICommand
{
readonly Action<T> _execute;
readonly Func<T, bool> _canExecute;
public event EventHandler CanExecuteChanged;
public RelayCommand(Action<T> execute, Func<T, bool> canExecute = null)
{
_execute = execute;
_canExecute = canExecute;
}
public void RefreshCommand()
{
var cec = CanExecuteChanged;
if (cec != null)
cec(this, EventArgs.Empty);
}
public bool CanExecute(object parameter)
{
if (_canExecute == null) return true;
return _canExecute((T)parameter);
}
public void Execute(object parameter)
{
_execute((T)parameter);
}
}
The problem is now, that I want to stop the Tap/Click event after clicking on the links. Usually to prevent the event from bubbling up I would do this e.Handled = True
. But in this case I've got no TappEvent on the links.
The code- behind of the user control look like this:
private void Init()
{
//ComplexTextPresenterElement.Input = "This is where the Content string has to be....";
ComplexTextPresenterElement.OnHyperlinkCommand = new RelayCommand<object>(Execute);
}
private async void Execute(object o)
{
List<object> passingParameters = new List<object>();
//put here the code that can open browser
if (o is HyperLinkPart)
{
var obj = (HyperLinkPart)o;
await Windows.System.Launcher.LaunchUriAsync(new Uri(obj.RealUrl, UriKind.Absolute));
} [...]
Before the webbrowser opens I have to stop the TapEvent which gets called from the UI Element surrounding this UserControl.
I hope this is enough information. Let me know otherwise.
Cheers,
Ulpin