本文整理汇总了C#中ObservableCollection.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.FirstOrDefault方法的具体用法?C# ObservableCollection.FirstOrDefault怎么用?C# ObservableCollection.FirstOrDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.FirstOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DirectionDeviceSelectationViewModel
public DirectionDeviceSelectationViewModel()
{
Title = "Выбор устройства";
var devices = new HashSet<XDevice>();
foreach (var device in XManager.DeviceConfiguration.Devices)
{
if (device.Driver.IsControlDevice)
{
device.AllParents.ForEach(x => { devices.Add(x); });
devices.Add(device);
}
}
Devices = new ObservableCollection<DeviceViewModel>();
foreach (var device in devices)
{
var deviceViewModel = new DeviceViewModel(device, Devices);
deviceViewModel.IsExpanded = device.Driver.IsControlDevice;
Devices.Add(deviceViewModel);
}
foreach (var device in Devices.Where(x => x.Device.Parent != null))
{
var parent = Devices.FirstOrDefault(x => x.Device.UID == device.Device.Parent.UID);
device.Parent = parent;
parent.Children.Add(device);
}
SelectedDevice = Devices.FirstOrDefault(x => x.HasChildren == false);
}
示例2: SelectAircraftsVm
public SelectAircraftsVm(SelectAircrafts selectAircraftsWindow, IPartService service)
: base(service)
{
SelectAircraftsWindow = selectAircraftsWindow;
CommitCommand = new DelegateCommand<object>(OnCommitExecute, CanCommitExecute);
CancelCommand = new DelegateCommand<object>(OnCancelExecute, CanCancelExecute);
#region 飞机
AircraftQueries = new QueryableDataServiceCollectionView<ContractAircraftDTO>(service.Context, service.Context.ContractAircrafts);
AircraftQueries.FilterDescriptors.Add(_descriptor);
AircraftQueries.LoadedData += (e, o) =>
{
AircraftList = new ObservableCollection<ContractAircraftDTO>();
AircraftQueries.ToList().ForEach(AircraftList.Add);
SelectAircraftList = new ObservableCollection<ContractAircraftDTO>();
if (_scn != null)
{
_scn.ApplicableAircrafts.ToList().ForEach(p => SelectAircraftList.Add(AircraftList.FirstOrDefault(t => t.Id == p.ContractAircraftId)));
}
else
{
Aircrafts.ForEach(p => SelectAircraftList.Add(AircraftList.FirstOrDefault(t => t.Id == p.Id)));
}
};
#endregion
}
示例3: setNewParent
public static void setNewParent(Guid itemId, Guid parentId, ObservableCollection<Todo> _Todos)
{
var thisItm = _Todos.FirstOrDefault(x=>x.Id==itemId);
if (parentId!= Guid.Empty)
{
var prnt = _Todos.FirstOrDefault(x => x.Id == parentId);
thisItm.ParentId = prnt.Id;
thisItm.Wbs = prnt.Wbs + ">";
int newIdx = _Todos.IndexOf(prnt)+1;
if (newIdx <= _Todos.Count)
{
_Todos.Remove(thisItm);
_Todos.Insert(newIdx, thisItm);
}
else
{
_Todos.Remove(thisItm);
_Todos.Add(thisItm);
}
}
else
{
thisItm.ParentId = Guid.Empty;
thisItm.Wbs = ">";
}
//_Todos[itemIndex] = thisItm;
updateChildren(thisItm, _Todos);
}
示例4: ProjectListViewModel
public ProjectListViewModel( IViewServiceRepository viewServices = null, ISettingsRepository settingsRepo = null, IProjectRepository projectRepo = null, IMessenger messenger = null )
: base( viewServices, settingsRepo, messenger )
{
ProjectRepo = projectRepo ?? new ProjectRepository( Session );
Projects = new ObservableCollection<ProjectViewModel>( ProjectRepo.GetAll().OrderBy( p => p.Name ).Select( p => new ProjectViewModel( p ) ) );
var last = Settings.GetById( SettingKeys.LastProject );
CurrentProject = Projects.FirstOrDefault( p => p.Model.Id == last.Get<int>() ) ?? Projects.FirstOrDefault();
foreach( var proj in Projects )
{
proj.CurrentChanged += Proj_CurrentChanged;
}
if( CurrentProject != null )
{
CurrentProject.IsCurrent = true;
}
ProjectNames = new List<string>();
Validate( nameof( NewProjectName ) ).Check( () => !string.IsNullOrWhiteSpace( NewProjectName ) ).Message( Strings.ProjectMustHaveName );
Validate( nameof( NewProjectName ) ).Check( () => !ProjectNames.Contains( NewProjectName ) ).Message( Strings.ThisNameIsAlreadyUsed );
Reset();
}
示例5: DirectionDeviceSelectorViewModel
public DirectionDeviceSelectorViewModel(Direction direction, DriverType driverType)
{
Title = "Выбор устройства";
var devices = new HashSet<Device>();
foreach (var device in FiresecManager.Devices)
{
if (device.Driver.DriverType == driverType)
{
if (device.Parent.Children.Any(x => x.Driver.IsZoneDevice && x.ZoneUID != Guid.Empty && direction.ZoneUIDs.Contains(x.ZoneUID)))
{
device.AllParents.ForEach(x => { devices.Add(x); });
devices.Add(device);
}
}
}
Devices = new ObservableCollection<DeviceViewModel>();
foreach (var device in devices)
{
var deviceViewModel = new DeviceViewModel(device);
deviceViewModel.IsExpanded = true;
Devices.Add(deviceViewModel);
}
foreach (var device in Devices.Where(x => x.Device.Parent != null))
{
var parent = Devices.FirstOrDefault(x => x.Device.UID == device.Device.Parent.UID);
parent.AddChild(device);
}
SelectedDevice = Devices.FirstOrDefault(x => x.HasChildren == false);
}
示例6: AddVirtualEnvironmentView
public AddVirtualEnvironmentView(
PythonProjectNode project,
IInterpreterRegistryService interpreterService,
IPythonInterpreterFactory selectInterpreter
) {
_interpreterService = interpreterService;
_project = project;
VirtualEnvBasePath = _projectHome = project.ProjectHome;
Interpreters = new ObservableCollection<InterpreterView>(InterpreterView.GetInterpreters(project.Site, project));
var selection = Interpreters.FirstOrDefault(v => v.Interpreter == selectInterpreter);
if (selection == null) {
selection = Interpreters.FirstOrDefault(v => v.Interpreter == project.GetInterpreterFactory())
?? Interpreters.LastOrDefault();
}
BaseInterpreter = selection;
_project.InterpreterFactoriesChanged += OnInterpretersChanged;
var venvName = "env";
for (int i = 1; Directory.Exists(Path.Combine(_projectHome, venvName)); ++i) {
venvName = "env" + i.ToString();
}
VirtualEnvName = venvName;
CanInstallRequirementsTxt = File.Exists(PathUtils.GetAbsoluteFilePath(_projectHome, "requirements.txt"));
WillInstallRequirementsTxt = CanInstallRequirementsTxt;
}
示例7: DelaySelectionViewModel
public DelaySelectionViewModel(GKDelay delay)
{
Title = "Выбор задержки";
Delays = new ObservableCollection<DelayViewModel>();
GKManager.Delays.ForEach(x => Delays.Add(new DelayViewModel(x)));
if (delay != null)
SelectedDelay = Delays.FirstOrDefault(x => x.Delay.UID == delay.UID);
if (SelectedDelay == null)
SelectedDelay = Delays.FirstOrDefault();
}
示例8: GKDoorSelectionViewModel
public GKDoorSelectionViewModel(GKDoor door)
{
Title = "Выбор точки доступа";
Doors = new ObservableCollection<DoorViewModel>();
GKManager.Doors.ForEach(x => Doors.Add(new DoorViewModel(x)));
if (door != null)
SelectedDoor = Doors.FirstOrDefault(x => x.Door.UID == door.UID);
if (SelectedDoor == null)
SelectedDoor = Doors.FirstOrDefault();
}
示例9: MPTSelectionViewModel
public MPTSelectionViewModel(GKMPT mpt)
{
Title = "Выбор направления";
MPTs = new ObservableCollection<MPTViewModel>();
GKManager.MPTs.ForEach(x => MPTs.Add(new MPTViewModel(x)));
if (mpt != null)
SelectedMPT = MPTs.FirstOrDefault(x => x.MPT.UID == mpt.UID);
if (SelectedMPT == null)
SelectedMPT = MPTs.FirstOrDefault();
}
示例10: weatherViewModel
public weatherViewModel()
{
serviceModel.GetWeatherCompleted += (s, a) =>
{
var weatherlist = new ObservableCollection<weather>(a.Results);
WeatherList = weatherlist;
UpdateTile(WeatherList.FirstOrDefault().Ciudad + ' ' + WeatherList.FirstOrDefault().Temperatura); //+ "°" + WeatherList.FirstOrDefault().TypoGrados );
};
}
示例11: GuardZoneSelectionViewModel
public GuardZoneSelectionViewModel(GKGuardZone guardZone)
{
Title = "Выбор охранной зоны";
Zones = new ObservableCollection<ZoneViewModel>();
GKManager.GuardZones.ForEach(x => Zones.Add(new ZoneViewModel(x)));
if (guardZone != null)
SelectedZone = Zones.FirstOrDefault(x => x.GuardZone.UID == guardZone.UID);
if (SelectedZone == null)
SelectedZone = Zones.FirstOrDefault();
}
示例12: PumpStationSelectionViewModel
public PumpStationSelectionViewModel(GKPumpStation pumpStation)
{
Title = "Выбор насосной станции";
PumpStations = new ObservableCollection<PumpStationViewModel>();
GKManager.PumpStations.ForEach(x => PumpStations.Add(new PumpStationViewModel(x)));
if (pumpStation != null)
SelectedPumpStation = PumpStations.FirstOrDefault(x => x.PumpStation.UID == pumpStation.UID);
if (SelectedPumpStation == null)
SelectedPumpStation = PumpStations.FirstOrDefault();
}
示例13: DirectionSelectionViewModel
public DirectionSelectionViewModel(GKDirection direction)
{
Title = "Выбор направления";
Directions = new ObservableCollection<DirectionViewModel>();
GKManager.Directions.ForEach(x => Directions.Add(new DirectionViewModel(x)));
if (direction != null)
SelectedDirection = Directions.FirstOrDefault(x => x.Direction.UID == direction.UID);
if (SelectedDirection == null)
SelectedDirection = Directions.FirstOrDefault();
}
示例14: ZoneSelectionViewModel
public ZoneSelectionViewModel(GKZone zone)
{
Title = "Выбор зоны";
Zones = new ObservableCollection<ZoneViewModel>();
GKManager.Zones.ForEach(x => Zones.Add(new ZoneViewModel(x)));
if (zone != null)
SelectedZone = Zones.FirstOrDefault(x => x.Zone.UID == zone.UID);
if (SelectedZone == null)
SelectedZone = Zones.FirstOrDefault();
}
示例15: TasksViewModel
public TasksViewModel(ITaskHub taskHub)
{
Tasks = new ObservableCollection<Task>();
TaskStatuses = new ObservableCollection<string>{ "Open", "Closed", "On Hold" };
Messenger.Default.Register<GotTasksForUserEvent>(this, (e) => {
Tasks.Clear();
foreach (Task task in e.Tasks) {
Tasks.Add(task);
}
});
Messenger.Default.Register<AddedTaskEvent>(this, (e) => {
Tasks.Add(e.AddedTask);
});
Messenger.Default.Register<UpdatedTaskEvent>(this, (e) => {
if (e == null || e.UpdatedTask == null) {
return;
}
Task taskToUpdate = Tasks.FirstOrDefault(t => t.TaskID == e.UpdatedTask.TaskID);
if (taskToUpdate != null) {
if (taskToUpdate.IsDeleted || taskToUpdate.AssignedTo != Username) {
Tasks.Remove(taskToUpdate);
} else {
taskToUpdate.AssignedTo = e.UpdatedTask.AssignedTo;
taskToUpdate.Details = e.UpdatedTask.Details;
taskToUpdate.Status = e.UpdatedTask.Status;
taskToUpdate.Title = e.UpdatedTask.Title;
taskToUpdate.IsDeleted = e.UpdatedTask.IsDeleted;
}
} else {
// This is a new assigned task
Tasks.Add(e.UpdatedTask);
}
});
Messenger.Default.Register<DeletedTaskEvent>(this, (e) => {
if (e == null || e.DeletedTask == null) {
return;
}
Task deletedTask = Tasks.FirstOrDefault(t => t.TaskID == e.DeletedTask.TaskID);
if (deletedTask != null) {
Tasks.Remove(deletedTask);
}
});
Messenger.Default.Register<LoginEvent>(this, (e) => {
Username = e.Username;
});
AddTask = new RelayCommand(() => {
Messenger.Default.Send(new NewTaskEvent());
});
}