最好要问一下的是,在不友善的“净优势”论坛上,但说......
我理解,你想要的是只读数据网(囚室不能校正),以便有一条可观的行文添加新的项目......
- Add a
CellValuePresenter
targetted Style
under XamDatagrid.Resources
.
- This will check if the given cell value presenter is focused and represents the add new row.
如果是的话,它将通过某些附带的行为使母子的田地变得不可调和。
<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);
}
}
希望这一帮助。