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);
}
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 
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);
}
why is this behavior is like this.

ITextRange.LinkProperty,ITextRange.EndPositionwill go to the end of the Text. This behavior has not been explained in the official document. According to the current behavior, please set the link in the order from the back to the front.