我有两个窗户。在第一个窗口中,我将数据插入到类QuoteData
中,编码如下
using (TruckServiceClient client = new TruckServiceClient())
{
quoteFinalize = await client.GetQuoteAsync(new QuoteData
{
BodyTypeId = cmbBodyType.GetDisplayItemId(),
ChassisId = cmbChassisCab.GetDisplayItemId(),
FloorId = cmbFloorSpecification.GetDisplayItemId(),
ExternalLength = externalLength,
ExternalWidth = externalWidth,
ExternalHeight = externalHeight
});
然后在第二个窗口中,我想访问我插入数据的同一个类(QuoteData
),然后将ExternalLength
QuoteData
设置为我的标签名为lblExternalLengthAmount
。
示例:lblExternalLengthAmount.Content = ExternalLength;
我已尝试在第二个窗口中创建QuoteData
的新实例,但所有值都重新显示为 null 。
有没有办法访问这些值?任何建议将不胜感激:)
答案 0 :(得分:1)
您可以将构造函数中的Window1对象传递给Window2
Window1.xaml.cs
Window2 dialog = new Window2(this);//this is current window(Window1) object
并在Window2.xaml.cs
中public Window2(Window1 obj)
{
InitializeComponent();
//obj is your Window1 object
}
对obj所做的任何更改都将反映到Window1