what is this ambiguous behavior of RichEditBox while setting Link in UWP

pavan yekabote
5
Reputation points
After setting the Link
for the range 5 to 10 before setting the Link and RichText for the range 25 to 30 which some how getting applied for the range 5 to 10 instead of 25 to 30. here is the output
public MainPage()
{
this.InitializeComponent();
box1 = new RichEditBox()
{
Width = 500,
Height = 500,
BorderBrush = new SolidColorBrush(Colors.Blue),
BorderThickness = new Thickness(1, 1, 1, 1)
};
btn = new Button() { Content = "button" };
btn.Click += Btn_Click;
string str = "ppppppavaniiiiipavanlllllpavankjhgfcdsa";
box1.Document.SetText(0, str);
box1.TextAlignment = TextAlignment.Center;
{
ITextSelection selection1 = box1.Document.Selection;
selection1.StartPosition = 5;
selection1.EndPosition = 10;
Debug.WriteLine("<<<<<<<<<<<<<<<<<<<<<" + selection1.StartPosition);
Debug.WriteLine("<<<<<<<<<<<<<<<<<<<<<" + selection1.EndPosition);
selection1.CharacterFormat.Bold = FormatEffect.On;
string s = "\"google.com\"";
selection1.Link = s;
selection1.Collapse(false);
}
{
ITextSelection selection2 = box1.Document.Selection;
selection2.StartPosition = 25;
selection2.EndPosition = 30;
Debug.WriteLine("<<<<<<<<<<<<<<<<<<<<<" + selection2.StartPosition);
Debug.WriteLine("<<<<<<<<<<<<<<<<<<<<<" + selection2.EndPosition);
selection2.CharacterFormat.Bold = FormatEffect.On;
selection2.CharacterFormat.Size = 20;
selection2.CharacterFormat.BackgroundColor = Color.FromArgb(0, 50, 77, 98);
selection2.CharacterFormat.Name = "Algerian";
string s = "\"gjhgfdghje.com\"";
selection2.Link = s;
}
grid.Children.Add(box1);
grid.Children.Add(btn);
}
If I move the second block of code above the first as below
public MainPage()
{
this.InitializeComponent();
box1 = new RichEditBox()
{
Width = 500,
Height = 500,
BorderBrush = new SolidColorBrush(Colors.Blue),
BorderThickness = new Thickness(1, 1, 1, 1)
};
btn = new Button() { Content = "button" };
btn.Click += Btn_Click;
string str = "ppppppavaniiiiipavanlllllpavankjhgfcdsa";
box1.Document.SetText(0, str);
box1.TextAlignment = TextAlignment.Center;
{
ITextSelection selection2 = box1.Document.Selection;
selection2.StartPosition = 25;
selection2.EndPosition = 30;
Debug.WriteLine("<<<<<<<<<<<<<<<<<<<<<" + selection2.StartPosition);
Debug.WriteLine("<<<<<<<<<<<<<<<<<<<<<" + selection2.EndPosition);
selection2.CharacterFormat.Bold = FormatEffect.On;
selection2.CharacterFormat.Size = 20;
selection2.CharacterFormat.BackgroundColor = Color.FromArgb(0, 50, 77, 98);
selection2.CharacterFormat.Name = "Algerian";
string s = "\"gjhgfdghje.com\"";
selection2.Link = s;
}
{
ITextSelection selection1 = box1.Document.Selection;
selection1.StartPosition = 5;
selection1.EndPosition = 10;
Debug.WriteLine("<<<<<<<<<<<<<<<<<<<<<" + selection1.StartPosition);
Debug.WriteLine("<<<<<<<<<<<<<<<<<<<<<" + selection1.EndPosition);
selection1.CharacterFormat.Bold = FormatEffect.On;
string s = "\"google.com\"";
selection1.Link = s;
selection1.Collapse(false);
}
grid.Children.Add(box1);
grid.Children.Add(btn);
}
then the output is this
why is this behavior is like this.
How to Remove the link which has been set. how to compress or extend the range of link.