当然,我在两个不同的位置使用它是最小的:
<UserControl x:Class="Unattended_Tool.View.UserControls.Admin.UserControls.Detail"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<dxlc:GroupBox MinimizeElementVisibility="Visible" IsManipulationEnabled="True" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<dxg:GridControl Name="GridControlUser" ItemsSource="{Binding AlleICTSUser, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" AutoExpandAllGroups="True" ShowBorder="True" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2">
<dxg:GridControl.View>
<dxg:TableView Name="tableViewGrid" FocusedRow="{Binding SelecetetUser, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" >
<dxg:TableView.InputBindings>
<KeyBinding Key="Del" Modifiers="Control" Command="{Binding RemoveICTSUserCommand}"/>
<KeyBinding Key="N" Modifiers="Control" Command="{Binding AddICTSUserCommand}"/>
</dxg:TableView.InputBindings>
</dxg:TableView>
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Name" Header="Name"/>
<dxg:GridColumn FieldName="Password" Header="Password" AllowEditing="{Binding SelecetetUser.CanEditPassword, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
<dxg:GridColumn.EditSettings>
<dxe:PasswordBoxEditSettings IsEnabled="{Binding CanEditPassword}" />
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
<dxg:GridColumn FieldName="CanEditPassword" Header="CanEdit">
<dxg:GridColumn.EditSettings>
<dxe:CheckEditSettings />
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
<dxg:GridColumn Header="Categorie" FieldName="SelectetProgrammCategorieIds">
<dxg:GridColumn.EditSettings>
<dxe:ComboBoxEditSettings ItemsSource="{Binding AlleCategorien, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ValueMember="ID" DisplayMember="Name">
<dxe:ComboBoxEditSettings.StyleSettings>
<dxe:CheckedComboBoxStyleSettings/>
</dxe:ComboBoxEditSettings.StyleSettings>
</dxe:ComboBoxEditSettings>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
</dxg:GridControl.Columns>
</dxg:GridControl>
</Grid>
</dxlc:GroupBox>
好的,我找到了一种方法,但它不是真正的事情,它是一个“小”脏我希望有另一种方法。我的目标类必须如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Unattended_Tool.View.DataStore;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
namespace Unattended_Tool
{
public class ICTSPrinter : IDataErrorInfo
{
string _name;
string _versionsname;
string _location;
ObservableCollection<int> _categorie;
public ObservableCollection<int> Categorie
{
get { return _categorie; }
set { _categorie = value; }
}
[XmlIgnore]
public object SelectetProgrammCategorieIds
{
get { return (Object)Categorie; }
set { Categories = new ObservableCollection<int>((value as IEnumerable<Object>).ToObservableCollection<int>()) { };
}
public string Location
{
get { return _location; }
set { _location = value; }
}
public string VersionsName
{
get { return _versionsname; }
set { _versionsname = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Error
{
get;
set;
}
public string this[string columnName]
{
get
{
Error = string.Empty;
switch (columnName)
{
case "Name":
if (string.IsNullOrEmpty(Name))
{
Error = "Error";
}
break;
case "SelectetProgrammCategorieId":
if (DataStoreSingelton.Instance.AlleCategories.FirstOrDefault(S => ((List<int>)SelectetProgrammCategorieIds).FirstOrDefault(s => s == S.ID) == S.ID) != null)
{
Error = "Please enter a vaild programm categorie";
}
break;
default: break;
}
return Error;
}
}
}
}
似乎 DevExpress 只接受绑定中的对象......我可以使用转换器,但这只是一种解决方法
我使用的是 12.1.5 版本