我有一个简单的问题,我相信有人可以帮助我。如何在方法中使用我的accountID
变量,INavigationAware
然后在另一个类中使用它们?
下面是我的代码:
ViewModel 相关代码(HistoryAuditLogViewModel.cs):
#region Private Fields
private DatabaseConnectionSetting dbSetting;
private string tableName = "Manufacturers";
private int primaryKeyID = 1;
private string entryID;
private string manufacturerID;
private string manufacturerName;
private string auditDate;
private string sqlLogin;
private string application;
private List<string> dataList;
private string dbConnectionKey = Alliance.Infrastructure.Common.DatabaseConnectionSetting.BACKFLOW_SCOPE_KEY;
private int ShowAuditLogForPrimaryID { get; set; }
private int initialAuditID;
private int _accountID;
private string xmlString()
{
return "<row EntryID=\"" + entryID + "\" ManufacturerID=\"" + manufacturerID + "\" ManufacturerName=\"" + manufacturerName + "\" AuditDate=\"" + auditDate + "\" SqlLogin=\"" + sqlLogin + "\" Application=\"" + application + "\" />";
}
private DataSet _dataSet;
#endregion
#region Public Fields
public DataSet dataSet
{
get { return _dataSet; }
set { _dataSet = value; }
}
public int accountID
{
get { return _accountID; }
set { _accountID = value; }
}
#endregion
#region INavigationAware Members
bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
{
string tableName;
string holdStringValue;
holdStringValue = navigationContext.Parameters["primarykey"];
if (holdStringValue == null ||
!Int32.TryParse(holdStringValue, out accountID))
{
accountID = 0;
}
if (accountID == this.ShowAuditLogForPrimaryID)
{
return true;
}
else
{
return false;
}
}
void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
{
}
void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
{
string holdStringValue;
int accountID;
initialAuditID = 0;
holdStringValue = navigationContext.Parameters["TableName"];
if (holdStringValue == null ||
!Int32.TryParse(holdStringValue, out initialAuditID))
{
initialAuditID = 0;
}
holdStringValue = navigationContext.Parameters["AccountID"];
if (holdStringValue != null &&
Int32.TryParse(holdStringValue, out accountID))
{
this.ShowAuditLogForPrimaryID = accountID;
}
else
{
this.ShowAuditLogForPrimaryID = 0;
}
Load_Audit();
}
#endregion INavigationAware Members
我将需要使用accountID
在这些方法中设置的表名。至少我认为这是他们设置的地方。我从未使用过INavigation
,所以我对它的工作原理有点困惑。
这是我需要能够使用 ViewModel (CoreModuleDesktop) 中的变量的地方:
this.NavManager.RegisterCommonActionItem("History Audit Log", "AuditLog", 110,
new BitmapImage(new Uri("pack://application:,,,/Core;component/Resources/maintenance.png")),
new Action(() =>
{
IRegionManager regionManager = AllianceApp.Container.GetExportedValue<IRegionManager>();
UriQuery query = new UriQuery();
query.Add("AccountID", accountID.ToString());
//query.Add("ServiceOrderID", tableName.ToString());
regionManager.RequestNavigate(RegionNames.MainRegion, new Uri(typeof(HistoryAuditLogView).FullName + query.ToString(), UriKind.Relative));
}));
}
基本上,这将允许我在 ViewModel 中运行一个查询,将查询结果放置在数据网格视图中。任何帮助将不胜感激。