在Windows Phone7中,我創建了一個UserControl,我正在解析一些數據。現在我無法制作該Usercontrol的實例。Usercontrol無法創建實例[XapCannotFindFileInPackage]
當我刪除從用戶控件解析我能夠做的實例,除非我收到錯誤,如
`"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"
我的用戶控件代碼隱藏
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>
你知道哈利波特嗎?他發現了一個神奇的詞,可以幫助猜測你的控制是如何編碼的。不幸的是,他沒有在stackoverflow上註冊。尚未 – 2012-07-31 13:40:42
abracadabra!哪一行導致此問題?用//解析的那個?如果是,那麼xml文件的內容是什麼? – 2012-07-31 14:13:23
錯誤不會發生在代碼但是,當我拖n刪除UserControl.Check編輯,我已解析的XML – 2012-07-31 14:23:48