WPF关于打开新窗口获取数据的回调方法的两种方式

一种基于消息发送模式

一种基于回调机制

基于消息发送模式

父页面定义接收的_selectedPnNumberStandarMsg保证是唯一

Messenger.Default.Register<PlateReplaceApplyModel>(this, _selectedPnNumberStandarMsgToken, platePnNumberModel =>

{

if (platePnNumberModel == null) return;

Item.ProductNumberId = platePnNumberModel.ProductNumberId;

Item.ProductNumber = platePnNumberModel.ProductNumber;

Item.IndustryCategory = platePnNumberModel.IndustryCategory;

Item.ProductName = platePnNumberModel.ProductName;

GetPartChangeByProductNumberId(platePnNumberModel.ProductNumberId);

//getPartChangeByProductNumberId(platePnNumberModel.ProductNumberId);

RaisePropertyChanged(() => Item);

});

子页面

获取数据后的发送父页面

public RelayCommand SelectionChangeCommand

{

get

{

return new RelayCommand(() =>

{

if (CurrentItem == null) return;

Messenger.Default.Send(CurrentItem, PlateReplaceApplyFormVM._selectedPnNumberStandarMsgToken);

CloseWin();

}, () => CurrentItem != null);

}

}

第二种回调

<c1:Column Header="销售订单号" Binding="{Binding SalesOrderNo,Mode=TwoWay}" Width="180" ColumnName="SalesOrderNo" >

<c1:Column.CellTemplate>

<DataTemplate>

<Grid>

<Grid.ColumnDefinitions>

<ColumnDefinition Width="*"/>

<ColumnDefinition Width="Auto"/>

</Grid.ColumnDefinitions>

<TextBlock Padding="3,0,3,0" Text="{Binding SalesOrderNo,Mode=TwoWay}" TextWrapping="Wrap" />

<Button Grid.Column="1" Style="{StaticResource FlexGrid-SelectBtn}" Name="BtnSalesOrderItem" Click="BtnSalesOrderNo_Click" />

</Grid>

</DataTemplate>

</c1:Column.CellTemplate>

<c1:Column.CellEditingTemplate>

<DataTemplate>

<c1:C1MaskedTextBox Text="{Binding SalesOrderNo, Mode=TwoWay, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" TextWrapping="Wrap"/>

</DataTemplate>

</c1:Column.CellEditingTemplate>

</c1:Column>

BtnRelationId_Click触发

private void BtnRelationId_Click(object sender, RoutedEventArgs e)

{

var vm = DataContext as PlateReplaceApplyFormVM;

if (vm == null)

{

return;

}

var testInfo = CfgRiskReviewItem.HitTest(Mouse.GetPosition(CfgRiskReviewItem));

if (testInfo.Row > -1)

{

var selectedItem = CfgRiskReviewItem.Rows[testInfo.Row].DataItem as PlateReplaceRiskReviewModel;

vm.CurrentRiskReviewItem = selectedItem;

//五种不同的关联方式跳转不同的页面关联.目前只处理客户投诉RelationType=1为客诉

if (selectedItem.RelationType == 1&& selectedItem.RelationWay==1)

{

vm.SelectComplaintsSubject();

}

}

}

//选择父页面vm

public void SelectComplaintsSubject()

{

if (CurrentRiskReviewItem != null)

{

string action = "选择客诉";

var custimerWin = PageRouter.GetWindow<ComplaintsCodeSelectedFormWin>(action);

var vm = AutofacInstaceFactory.GetInstance<ComplaintsCodeSelectedFormVM>();

vm.ProductNumber = Item.ProductNumberOutVer;

var wheres = new List<QueryWhere>();

vm.Init1(CurrentItem =>

{

if (CurrentItem != null)

{

CurrentRiskReviewItem.RelationField = CurrentItem.Code;

CurrentRiskReviewItem.ReviewResult = 1;

RaisePropertyChanged(() => CurrentRiskReviewItem);

}

});

custimerWin.DataContext = vm;

custimerWin.ShowDialog();

}

}

子页面vm 回传对象CurrentItem

public RelayCommand SelectionChangeCommand

{

get

{

return new RelayCommand(() =>

{

if (_callBack != null)

{

_callBack(CurrentItem);

CloseWin();

}

}, () => CurrentItem != null);

}

}

相关推荐
callJJ19 分钟前
Spring Data Redis 两种编程模型详解:同步 vs 响应式
java·spring boot·redis·python·spring
小郑加油22 分钟前
python学习Day12:pandas安装与实际运用
开发语言·python·学习
AC赳赳老秦22 分钟前
投标合规提效:用 OpenClaw 实现标书 / 合同自动审核、关键词校验、格式优化,降低废标风险
开发语言·前端·python·eclipse·emacs·deepseek·openclaw
KuaCpp1 小时前
C++面向对象(速过复习版)
开发语言·c++
wbs_scy1 小时前
Linux线程同步与互斥(三):线程同步深度解析之POSIX 信号量与环形队列生产者消费者模型,从原理到源码彻底吃透
java·开发语言
2zcode1 小时前
基于MATLAB元胞自动机(CA)的AZ80A镁合金动态再结晶(DRX)过程模拟
开发语言·matlab·动态再结晶
iCxhust2 小时前
微机原理实践教程(C语言篇)---A001闪烁灯
c语言·开发语言·汇编·单片机·嵌入式硬件·51单片机·微机原理
MATLAB代码顾问2 小时前
Python实现蜂群算法优化TSP问题
开发语言·python·算法
jinanwuhuaguo3 小时前
(第三十三篇)五月的文明奠基:OpenClaw 2026.5.2版本的文明级解读
android·java·开发语言·人工智能·github·拓扑学·openclaw
xmjd msup3 小时前
spring security 超详细使用教程(接入springboot、前后端分离)
java·spring boot·spring