滚动到 XamDataGrid 中的选定行
Scroll to Selected Row in XamDataGrid
我有一个 Infragistics 15.1 WPF XamDataGrid,它会在用户将数据保存在表单的其他位置时刷新。我已经弄清楚如何以编程方式 select 在保存之前 selected 的行。我的问题是,如果该行不是网格中最上面的行之一,则用户必须向下滚动到突出显示的行。有没有办法让网格滚动到 selected 行?
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");
}
}
通过将 SelectedDataItem 移动到 DataSource 属性。
,我能够按照我想要的方式运行
<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>
我有一个 Infragistics 15.1 WPF XamDataGrid,它会在用户将数据保存在表单的其他位置时刷新。我已经弄清楚如何以编程方式 select 在保存之前 selected 的行。我的问题是,如果该行不是网格中最上面的行之一,则用户必须向下滚动到突出显示的行。有没有办法让网格滚动到 selected 行?
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");
}
}
通过将 SelectedDataItem 移动到 DataSource 属性。
,我能够按照我想要的方式运行<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>