从另一个 window 访问 class 数据
Accessing class data from another window
我有两个 windows。在 first window 中,我使用下面的编码将数据插入 class 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
});
然后在 second window 我想访问我插入数据然后设置的相同 class (QuoteData
) QuoteData
的 ExternalLength
到我的标签 lblExternalLengthAmount
。
示例:lblExternalLengthAmount.Content = ExternalLength;
我试图在第二个 window 上创建 QuoteData
的新实例,但所有值随后都被重置为 null。
有没有办法访问这些值?任何建议将不胜感激:)
您可以将构造函数中的 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
我有两个 windows。在 first window 中,我使用下面的编码将数据插入 class 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
});
然后在 second window 我想访问我插入数据然后设置的相同 class (QuoteData
) QuoteData
的 ExternalLength
到我的标签 lblExternalLengthAmount
。
示例:lblExternalLengthAmount.Content = ExternalLength;
我试图在第二个 window 上创建 QuoteData
的新实例,但所有值随后都被重置为 null。
有没有办法访问这些值?任何建议将不胜感激:)
您可以将构造函数中的 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