鉴于,
<igDP:XamDataGrid Name="dataGrid"
DataSource="{Binding RecordList}">
<igDP:XamDataGrid.FieldLayoutSettings >
<igDP:FieldLayoutSettings AllowAddNew="true" AddNewRecordLocation="OnTopFixed"/>
</igDP:XamDataGrid.FieldLayoutSettings>
在运行时,我可以在网格顶部看到一个空的新行。但是新行中的所有列都不可编辑!当我将每个字段标记为可编辑时,列可以编辑。
是否可以让添加记录功能正常工作,而“不”明确地将每个字段标记为可编辑?
感谢您的关注。
答案 0 :(得分:2)
你最好的选择是在infragistics netadvantage论坛上问这个,但是说了......
据我所知,你想要的是一个只读数据网格(在其单元格上不可编辑),以便有一个可编辑的行来添加新项...
CellValuePresenter
下添加Style
定位XamDatagrid.Resources
。如果是这样,它将通过某些附加行为使父字段可编辑。
<igDP:XamDataGrid Grid.Row="1"
DataSource="{Binding}"
AutoFit="True">
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsFocused,
RelativeSource={RelativeSource Self}}"
Value="True"/>
<Condition Binding="{Binding Record.IsAddRecord,
RelativeSource={RelativeSource Self}}"
Value="True"/>
</MultiDataTrigger.Conditions>
<Setter
Property="local:CellValuePresenterBehavior.AllowFieldEdit"
Value="True"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<!-- Only show the first 4 fields to keep the display simple -->
<igDP:Field Name="Key" Visibility="Visible">
<igDP:Field.Settings>
<igDP:FieldSettings
EditAsType="{x:Type System:String}"
EditorType="{x:Type Editors:XamTextEditor}"
AllowEdit="False"/>
</igDP:Field.Settings>
</igDP:Field>
<igDP:Field Name="Value" Visibility="Visible">
<igDP:Field.Settings>
<igDP:FieldSettings
EditAsType="{x:Type System:String}"
EditorType="{x:Type Editors:XamTextEditor}"
AllowEdit="False"/>
</igDP:Field.Settings>
</igDP:Field>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False"
AllowAddNew="True"
AddNewRecordLocation="OnTopFixed"
HighlightAlternateRecords="True"/>
</igDP:XamDataGrid.FieldLayoutSettings>
</igDP:XamDataGrid>
所附行为如下......
public class CellValuePresenterBehavior
{
public static DependencyProperty AllowFieldEditProperty
= DependencyProperty.RegisterAttached(
"AllowFieldEdit",
typeof(bool),
typeof(CellValuePresenterBehavior),
new PropertyMetadata(false, OnAllowFieldEditChanged));
private static void OnAllowFieldEditChanged(
DependencyObject depObj,
DependencyPropertyChangedEventArgs args)
{
var cvp = depObj as CellValuePresenter;
if (cvp != null)
{
cvp.Field.Settings.AllowEdit = (bool)args.NewValue;
}
}
public static bool GetAllowFieldEdit(DependencyObject depObj)
{
return (bool) depObj.GetValue(AllowFieldEditProperty);
}
public static void SetAllowFieldEdit(DependencyObject depObj, bool value)
{
depObj.SetValue(AllowFieldEditProperty, value);
}
}
希望这有帮助。