在ViewModel中使用此代码:
public CollectionViewModel<EfAttach, Guid, IDomainModelContextUnitOfWork> EfIncomingAttachesDetails
{
get
{
return GetDetailsCollectionViewModel((EfIncomingViewModel x) => x.EfIncomingAttachesDetails, x => x.Attaches, x => x.DocumentId, (x, key) => x.DocumentId = key);
}
}
这是ViewModel的详细信息
和XAML代码
<Grid dxb:MergingProperties.AllowMerging="False" x:Name="EfIncomingAttachesDetailsPanel" dxb:BarNameScope.IsScopeOwner="True" DataContext="{Binding EfIncomingAttachesDetails}" dxlc:LayoutControl.TabHeader="{x:Static res:Resources.Attaches}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<dxb:ToolBarControl>
<dxb:BarButtonItem BarItemDisplayMode="ContentAndGlyph" Content="{x:Static res:Resources.New}" Command="{Binding NewCommand}" Glyph="{dx:DXImageOffice2013 Image=New_16x16.png}"/>
<dxb:BarButtonItem BarItemDisplayMode="ContentAndGlyph" Content="{x:Static res:Resources.Refresh}" Command="{Binding RefreshCommand}" Glyph="{dx:DXImageOffice2013 Image=Refresh_16x16.png}"/>
</dxb:ToolBarControl>...
如何覆盖按钮上的命令&#34;新&#34;?
答案 0 :(得分:1)
看一下GetDetailsCollectionViewModel
方法实现 - 这个实现很简单。基于此实现,您可以创建自己的方法,该方法返回特定的DetailsViewModel,如下所示:
public IncomingAttachesCollectionViewModel EfIncomingAttachesDetails {
get { return GetIncomingAttachesDetails(x => x.EfIncomingAttachesDetails); }
}
protected IncomingAttachesCollectionViewModel GetIncomingAttachesDetails(
Expression<Func<EfIncomingViewModel , IncomingAttachesCollectionViewModel>> propertyExpression) {
return GetCollectionViewModelCore<IncomingAttachesCollectionViewModel, EfAttach, EfAttach, Guid>(
propertyExpression, () => IncomingAttachesCollectionViewModel.Create(UnitOfWorkFactory,
AppendForeignKeyPredicate<EfAttach, EfAttach, Guid>(x => x.DocumentID, null),
CreateForeignKeyPropertyInitializer<EfAttach, Guid>((x, key) => x.DocumentID = key, () => PrimaryKey),
() => CanCreateNewEntity()));
}
此处IncomingAttachesCollectionViewModel
的实施方式如下:
public class IncomingAttachesCollectionViewModel : CollectionViewModel<EfAttach, Guid, IDomainModelContextUnitOfWork> {
internal static IncomingAttachesCollectionViewModel Create(IUnitOfWorkFactory<IDomainModelContextUnitOfWork> unitOfWorkFactory = null,
Func<IRepositoryQuery<EfAttach>, IQueryable<EfAttach>> projection = null,
Action<EfAttach> propertyInitializer = null,
Func<bool> canCreateNewEntity = null) {
return ViewModelSource.Create(() => new IncomingAttachesCollectionViewModel(unitOfWorkFactory, projection, propertyInitializer, canCreateNewEntity));
}
protected IncomingAttachesCollectionViewModel(IUnitOfWorkFactory<IDomainModelContextUnitOfWork> unitOfWorkFactory = null,
Func<IRepositoryQuery<EfAttach>, IQueryable<EfAttach>> projection = null,
Action<EfAttach> propertyInitializer = null,
Func<bool> canCreateNewEntity = null)
: base(unitOfWorkFactory ?? UnitOfWorkSource.GetUnitOfWorkFactory(), x => x.Attaches, projection, propertyInitializer, canCreateNewEntity) {
}
public override void New() {
base.New();
/* do something here */
}
}