我有一个Infragistics 15.1 WPF XamDataGrid,当用户将数据保存在表单的其他位置时会刷新。我已经想出如何以编程方式选择保存前选择的行。我的问题是,如果该行不是网格上的顶行之一,则用户必须向下滚动到突出显示的行。有没有办法让网格滚动到选定的行?
XAML代码
<inf:XamDataGrid GroupByAreaLocation="None"
SelectedDataItem="{Binding SelectedPayItem, Mode=TwoWay}"
ActiveDataItem="{Binding SelectedPayItem, Mode=OneWay}"
DataSource="{Binding SelectedProject.ContractProjectPayItems}" ScrollViewer.VerticalScrollBarVisibility="Auto"
Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" Margin="2.8,3.4,3,2.8">
查看型号代码
private void SetSelectedPayItem()
{
if (SelectedProject != null)
{
if (SelectedProject.ContractProjectPayItems.Count() > 0)
{
if (SelectedProject.SelectedPayItemLineNbr == -1)
{
SelectedPayItem = SelectedProject.ContractProjectPayItems.First();
}
else
{
if (strLineItemNbr != null)
{
SelectedPayItem = SelectedProject.ContractProjectPayItems.FirstOrDefault(CPPI => CPPI.LineItemNbr == strLineItemNbr);
}
else
{ SelectedPayItem = SelectedProject.ContractProjectPayItems[SelectedProject.SelectedPayItemLineNbr]; }
}
}
else
{
SelectedPayItem = null;
}
}
}
string strLineItemNbr;
private ContractProjectPayItemModel _selectedPayItem;
public ContractProjectPayItemModel SelectedPayItem
{
get { return _selectedPayItem; }
set
{
_selectedPayItem = value;
if (_selectedPayItem != null)
{
SelectedProject.SelectedPayItemLineNbr = SelectedProject.ContractProjectPayItems.IndexOf(_selectedPayItem);
if (_selectedPayItem.ItemInstallations == null)
{
var oItemInstallation = new clsItemInstallation();
_selectedPayItem.ItemInstallations = oItemInstallation.GetItemInstallsByProjectPayItem(_selectedPayItem.ProjectGuid, _selectedPayItem.PayItemGuid);
foreach (var itemInstallation in _selectedPayItem.ItemInstallations)
{
itemInstallation.PropertyChanged += ItemInstallationsPropertyChanged;
itemInstallation.AcceptChanges();
}
_selectedPayItem.AcceptChanges();
foreach (var ii in SelectedProject.ContractProjectPayItems)
{
if (ii.ItemInstallations != null)
{
foreach (var i2 in ii.ItemInstallations)
{
i2.AcceptChanges();
}
}
}
RaisePropertyChanged("TotalInstallQty");
}
_itemInstallViewModel.SelectedProjectLineItem = SelectedPayItem;
strLineItemNbr = SelectedPayItem.LineItemNbr;
}
RaisePropertyChanged("SelectedPayItem");
RaisePropertyChanged("IsBitumen");
//----------------------------------
// Populate the User Control tabs.
//----------------------------------
PopulateUserControls();
SetSelectedItemInstallation();
RaisePropertyChanged("TotalInstallQty");
}
}
答案 0 :(得分:1)
通过在DataSource属性中移动SelectedDataItem,我能够以我想要的方式运行。
<inf:XamDataGrid GroupByAreaLocation="None"
DataSource="{Binding SelectedProject.ContractProjectPayItems}"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectedDataItem="{Binding SelectedPayItem, Mode=TwoWay}"
ActiveDataItem="{Binding SelectedPayItem, Mode=TwoWay}"
Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" Margin="2.8,3.4,3,2.8">
</inf:XamDataGrid>