I am using the MVVM pattern and trying to stay with the view-viewModel 1-1 relationship. I have a window with a RichTextBox and I'm coding the ability for the user to add a hyperlink via firing a dialog window from an ' Add Hyperlink' ribbon button.
I've got the property into the Hyperlink dialog window by passing it into the constructor, this works fine but I'm having problems sending the appended value back to the parent ViewModel.
Here's the property which holds my RTB text from my main page ViewModel code:
private viewArticle _ModelviewArticle = new viewArticle();
public viewArticle ModelviewArticle
{
get { return _ModelviewArticle; }
set
{
OnPropertyChanged("ModelviewArticle");
}
}
This property holds my text which is bound to the RichTextBox. I then show the hyperlink window via a button clicked command and append the user's chosen hyperlink & link text from textbox input in its own ViewModel (this is still not quite finished):
public static string BuildRtfHyperlink(string Url, string Linktext)
{
if (Url != null && Linktext != null)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat(@"{0}{{\ul\\cf3\ltrch {{\field{{\*\fldinst {{ HYPERLINK ""{1}""}}}}{{\fldrslt {{{2}}}}}}}}}\li0\\ri0\sa0\sb0\fi0\ql\par}}", _ArticleBody, Url, Linktext);
return sb.ToString();
}
else
{
MessageBox.Show("Please enter valid linked text and URL");
return "";
}
}
Is there any way to append the returned string to my _ModelviewArticle property in the other ViewModel or am I best using the one ViewModel for both the main page and hyperlink page views as they share functionality?
Thanks