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);
}
}
原文地址:https://blog.csdn.net/u012269637/article/details/144149332
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!