在Windows Phone7中,我创建了一个UserControl,我在其中解析一些数据。现在我无法创建Usercontrol的实例。
当我从usercontrol中删除解析时,我能够创建实例,除非我收到错误,例如
`"Cannot create instance of '<usercontrolname>'
"XapCannotFindFileInPackage]
Arguments:HelpScreenData.xml
Debugging Resource String are unavailable.Often the key and
arguments provide sufficient information to diagonise the problem.see
http://go.microsoft.com'/fwlink/?linkid=106663&version5.0.10411.00&
file=system.xml.dll&key=Xml_cannot find file in Xappackage"
我的UserControl CodeBehind
public partial class ques : UserControl
{
Popup popup = new Popup();
tutorial tut = new tutorial(); //another usercontrol
String[] str;
String[] nam;
public ques()
{
InitializeComponent();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
LayoutRoot.Visibility = Visibility.Visible;
buy_bac.Visibility = Visibility.Collapsed;
buy_hme.Visibility = Visibility.Collapsed;
buy_qestim.Visibility = Visibility.Collapsed;
buy_piti.Visibility = Visibility.Collapsed;
buy_qual.Visibility = Visibility.Collapsed;
buy_rent.Visibility = Visibility.Collapsed;
buy_rep.Visibility = Visibility.Collapsed;
buy_mre.Visibility = Visibility.Collapsed;
if (Modules.Programname == "Buyers")
{
buy_bac.Visibility = Visibility.Visible;
buy_hme.Visibility = Visibility.Visible;
buy_qestim.Visibility = Visibility.Visible;
buy_piti.Visibility = Visibility.Visible;
buy_qual.Visibility = Visibility.Visible;
buy_rent.Visibility = Visibility.Visible;
buy_rep.Visibility = Visibility.Visible;
buy_mre.Visibility = Visibility.Visible;
}
XDocument doc = XDocument.Load("HelpScreenData.xml");
string val = doc.ToString();
XElement doc1 = doc.Descendants("buyer").First();
var parsedPlist = doc1.Descendants("row");
int i = 0;
str = new string[parsedPlist.Count()];
nam = new string[parsedPlist.Count()];
foreach (XElement elem in parsedPlist)
{
nam[i] = (string)elem.Element("btn_name");
str[i] = (string)elem.Element("string");
i++;
}
}
private void i1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (nam[0] == buy_bac.Name)
{
Modules.msg = str[0];
if (Modules.msg != null)
{
if (popup.IsOpen != true)
{
popup.Child = tut;
popup.IsOpen = true;
popup.VerticalOffset = 200;
popup.HorizontalOffset = 50;
popup.IsOpen = true;
tut.lb_tut.Text = Modules.msg;
}
else
{
popup.IsOpen = false;
}
}
else if (nam[1] == buy_hme.Name)
{
Modules.msg = str[1];
if (Modules.msg != null)
{
if (popup.IsOpen != true)
{
popup.Child = tut;
popup.IsOpen = true;
popup.VerticalOffset = 400;
popup.HorizontalOffset = 50;
popup.IsOpen = true;
tut.lb_tut.Text = Modules.msg;
}
else
{
popup.IsOpen = false;
}
}
}
else if (nam[1] == buy_qestim.Name)
{
Modules.msg = str[2];
if (Modules.msg != null)
{
if (popup.IsOpen != true)
{
popup.Child = tut;
popup.IsOpen = true;
popup.VerticalOffset = 400;
popup.HorizontalOffset = 50;
popup.IsOpen = true;
tut.lb_tut.Text = Modules.msg;
}
else
{
popup.IsOpen = false;
}
}
}
}
}
private void i3_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (nam[2] == buy_piti.Name)
{
Modules.msg = str[3];
if (Modules.msg != null)
{
if (popup.IsOpen != true)
{
popup.Child = tut;
popup.IsOpen = true;
popup.VerticalOffset = 600;
popup.HorizontalOffset = 50;
popup.IsOpen = true;
tut.lb_tut.Text = Modules.msg;
}
else
{
popup.IsOpen = false;
}
}
}
else if (nam[2] == buy_rent.Name)
{
Modules.msg = str[4];
if (Modules.msg != null)
{
if (popup.IsOpen != true)
{
popup.Child = tut;
popup.IsOpen = true;
popup.VerticalOffset = 600;
popup.HorizontalOffset = 50;
popup.IsOpen = true;
tut.lb_tut.Text = Modules.msg;
}
else
{
popup.IsOpen = false;
}
}
}
else if (nam[2] == buy_qual.Name)
{
Modules.msg = str[5];
if (Modules.msg != null)
{
if (popup.IsOpen != true)
{
popup.Child = tut;
popup.IsOpen = true;
popup.VerticalOffset = 600;
popup.HorizontalOffset = 50;
popup.IsOpen = true;
tut.lb_tut.Text = Modules.msg;
}
else
{
popup.IsOpen = false;
}
}
}
else if (nam[2] == buy_mre.Name)
{
Modules.msg = str[6];
if (Modules.msg != null)
{
if (popup.IsOpen != true)
{
popup.Child = tut;
popup.IsOpen = true;
popup.VerticalOffset = 600;
popup.HorizontalOffset = 50;
popup.IsOpen = true;
tut.lb_tut.Text = Modules.msg;
}
else
{
popup.IsOpen = false;
}
}
}
}
解析
的xml示例<?xml version="1.0" encoding="utf-8" ?>
<plist version="1.0">
<Main_Screen>
<row>
<btn_name>Buyer Programs</btn_name>
<string>Answer your client’s difficult .</string>
</row>
<row>
<btn_name>Seller’s Programs</btn_name>
<string>What do sellers want s needs.</string>
</row>
</Main_Screen>
<abssas>
<row>
<btn_name>dat Programs</btn_name>
<string> your client’s </string>
</row>
<row>
<btn_name>my Programs</btn_name>
<string> sellers want s needs.</string>
</row>
</abssas>
</plist>
答案 0 :(得分:0)
您正在尝试加载“HelpScreenData.xml”但无法解析。确保已将此文件作为项目的一部分包含在内。