好吧,我们现在正在为我们的GUI尝试使用XAML(以及我们正在学习)......我已经能够在XAML和C#中独立于一个数据绑定另一个,但现在是时候我需要来回传递值,我有点失落。当我编译并尝试导航到页面时,它将引发XamlParseException:指定的类名称与实际的根实例类型不匹配。删除Class指令或通过XamlObjectWriterSettings.RootObjectInstance提供实例。 5号线位置2将XAML加载到C#进行数据绑定
任何帮助或在正确的方向轻柔推是极大的赞赏:)
这里就是我:
namespace TheAirline.GraphicsModel.PageModel.PageFinancesModel
{
/// <summary>
/// Interaction logic for PageFinances.xaml
/// </summary>
public partial class PageFinances : Page
{
private Airline Airline;
public PageFinances(Airline airline)
{
InitializeComponent();
this.Language = XmlLanguage.GetLanguage(new CultureInfo(AppSettings.GetInstance().getLanguage().CultureInfo, true).IetfLanguageTag);
this.Airline = airline;
Page page = null;
//loading the XAML
using (FileStream fs = new FileStream("TheAirline\\GraphicsModel\\PageModel \\PageFinancesModel\\PageFinances.xaml", FileMode.Open, FileAccess.Read))
{
page = (Page)XamlReader.Load(fs);
}
//finding XAML element and trying to set the value to a variable
string airlineCash = GameObject.GetInstance().HumanAirline.Money.ToString();
TextBox cashValue = (TextBox)page.FindName("cashValue");
cashValue.DataContext = airlineCash;
}
}
}
而XAML的前几行:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:AirlineModel="clr-namespace:TheAirline.Model.AirlineModel"
mc:Ignorable="d"
x:Class="TheAirline.GraphicsModel.PageModel.PageFinancesModel.PageFinances"
xmlns:c="clr-namespace:TheAirline.GraphicsModel.Converters"
...>
</Page>
你的发言'我已经能够做到数据,而无需在XAML和C#彼此独立,的问题结合,但现在来了,我需要通过值来回的时间,我有点lost'完全矛盾。如果你使用'DataBind','DataBinding' ITSELF'来回传递数据。我不明白你的意思。此外,你不应该做的事情,比如'文本框cashValue =(文本框)page.FindName( “cashValue”);'和'cashValue.DataContext = airlineCash;'。请说明你需要什么,我们可以帮助你。 – 2013-03-10 09:14:03
对不起,如果这是有点模糊(和矛盾) - 仍然学习XAML的来龙去脉。 无论如何 - 我的意思是我能够将滑块的值绑定到XAML或c#中的文本框,但无法将在XAML中创建的值绑定到c#中的变量,反之亦然。我希望这更有意义:) – mikedugan 2013-03-10 10:08:39