T LoadXAMLAndGetShape<T>(string url)
{
string xaml = string.Empty;
StreamResourceInfo sri = Application.GetResourceStream(
new Uri(url, UriKind.Relative));
using (StreamReader sr = new StreamReader(sri.Stream))
{
xaml = sr.ReadToEnd();
}
T shape = (T)XamlReader.Load(xaml);
return shape;
}
调用方式:
myGrid = LoadXAMLAndGetShape<Grid>(
"/wp_trade;component/MetroControls/fundsHoldPositionView.xaml");