NameSpace:
using System.Windows.Controls;
using System.IO;
using System.Windows.Markup;
using System.Text.RegularExpressions;
Coding:
public static ResourceDictionary ChangeXAML(double incFactor, string fontStyleUri)
{
Uri _styleUri = new Uri(fontStyleUri, UriKind.Relative);
if (_styleUri == null)
return null;
int _index = 0;
int _count = 0;
StreamReader strmReader = new StreamReader(Application.GetResourceStream(_styleUri).Stream);
string resText = strmReader.ReadToEnd();
IEnumerable<string> strFontSize = GetSubStrings(resText, "FontSize\">", "</sys:Double>");
foreach (string value in strFontSize)
{
if (resText.Contains("FontSize\">" + value))
{
_index = resText.IndexOf("FontSize\">" + value) + ("FontSize\">").Length;
_count = value.Length;
resText = resText.Remove(_index, _count);
}
}
foreach (string value in strFontSize)
{
if (resText.Contains("FontSize\"></sys:Double>"))
{
_index = resText.IndexOf("FontSize\"></sys:Double>") + ("FontSize\">").Length;
double newFontSize = Double.Parse(value) * incFactor;
resText = resText.Insert(_index, newFontSize.ToString());
}
}
return XamlReader.Load(resText) as ResourceDictionary;
}
private static IEnumerable<string> GetSubStrings(string input, string start, string end)
{
Regex r = new Regex(Regex.Escape(start) + "(.*?)" + Regex.Escape(end));
MatchCollection matches = r.Matches(input);
foreach (Match match in matches)
yield
return match.Groups[1].Value;
}
No comments:
Post a Comment