本文整理汇总了C#中System.Collections.ObservableCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.Add方法的具体用法?C# ObservableCollection.Add怎么用?C# ObservableCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCollectionSync
public void TestCollectionSync()
{
string item0 = "Item0";
string item1 = "Item1";
string item2 = "Item2";
string item3 = "Item3";
ObservableCollection<string> collection = new ObservableCollection<string>();
HelperLabeledViewModelCollection viewModel = new HelperLabeledViewModelCollection(null, collection, o => o);
collection.Add(item0);
collection.Add(item1);
collection.Add(item3);
Assert.IsTrue(CompareCollectionValues(collection, viewModel), "Add did not work.");
collection.Insert(2, item2);
Assert.IsTrue(CompareCollectionValues(collection, viewModel), "Insert did not work.");
collection.Remove(item3);
Assert.IsTrue(CompareCollectionValues(collection, viewModel), "Remove did not work.");
collection.Move(0, 1);
Assert.IsTrue(CompareCollectionValues(collection, viewModel), "Move did not work.");
collection.Clear();
Assert.IsTrue(CompareCollectionValues(collection, viewModel), "Clear did not work.");
}
示例2: Convert
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var results = new ObservableCollection<object>();
string[] parameters;
if (parameter is string)
{
parameters = ((string)parameter).Split(',');
for (var i = 0; i < parameters.Length; i++)
{
parameters[i] = parameters[i].Trim();
}
}
else
{
parameters = new string[0];
}
var index = 0;
foreach (var value in values)
{
if (value is IEnumerable)
{
results.Add(index < parameters.Length
? new BindingGroup(value as IEnumerable, parameters[index])
: value);
}
else
{
results.Add(value);
}
index++;
}
return results;
}
示例3: UserControl_Loaded
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
_permission_List = new ObservableCollection<SYSPermission>();
_permission_List2 = new List<sys_permission_rpc>();
/*
ad 广告操作
community 社区操作
entrance 编辑门禁
role 角色管理操作
user 用户操作
*/
_permission_List.Add(new SYSPermission(new sys_permission_rpc() { name = "ad", desc = "广告操作" }));
_permission_List.Add(new SYSPermission(new sys_permission_rpc() { name = "community", desc = "社区操作" }));
_permission_List.Add(new SYSPermission(new sys_permission_rpc() { name = "entrance", desc = "编辑门禁" }));
_permission_List.Add(new SYSPermission(new sys_permission_rpc() { name = "role", desc = "角色管理操作" }));
_permission_List.Add(new SYSPermission(new sys_permission_rpc() { name = "user", desc = "用户操作" }));
//var list = (Application.Current as App).Client.Proxy.get_permissions();
//foreach(var item in list)
//{
// _permission_List.Add(new SYSPermission(item));
//}
_permission_List2.Add(new sys_permission_rpc() { name = "user", desc = "用户操作" });
PermissionList = _permission_List;
SelectedList = _permission_List2;
//listView.ItemsSelected = SelectedList;
}
示例4: ProductCommentsViewModel
public ProductCommentsViewModel()
{
ProductDisplayed = new Product()
{
Name = "Bolacha Maria"
};
UserRatings = new ObservableCollection<UserRating>();
UserRatings.Add(new UserRating(){
Id="1",
Like = true,
Comment="Me fez super bem",
Profile=EnumProfile.Lactose,
User=new User(){
Id="1",
Name="Zé Carioca",
Profiles = EnumProfile.Lactose | EnumProfile.Wheat
}
});
UserRatings.Add (new UserRating () {
Id = "21",
Like = true,
Comment = "Gostei do produto sem lactose",
Profile = EnumProfile.Lactose,
User = new User () {
Id = "21",
Name = "Zé Colméia",
Profiles = EnumProfile.Lactose | EnumProfile.Wheat
}
});
}
示例5: LeftPaneViewModel
public LeftPaneViewModel()
{
_assetTypesList = new ObservableCollection<AssetType>();
_assetTypesList.Add(new AssetType { Name = "Bond", Value = "Bond" });
_assetTypesList.Add(new AssetType { Name = "Stock", Value = "Stock" });
this.addAssetCommand = new DelegateCommand(this.AddAssetExecute, this.AddAssetCanExecute);
}
示例6: Test_ObservableCollection_Count
public void Test_ObservableCollection_Count()
{
var list = new ObservableCollection<int>();
Assert.Equal(0, list.Count);
list.Add(3);
Assert.Equal(1, list.Count);
list.Add(3);
Assert.Equal(2, list.Count);
}
示例7: Main
static void Main()
{
ObservableCollection<string> items = new ObservableCollection<string>();
items.CollectionChanged += items_CollectionChanged;
items.Add("new item");
items.Add("another item");
items.Add("one more item");
items[1] = "new value";
items.RemoveAt(0);
}
示例8: MainWindowViewModel
public MainWindowViewModel()
{
_SelectableItemCollection = new ObservableCollection<SelectableItem>();
_SelectableItemCollection.Add(new SelectableItem() { IsSelected = false, Name = "One" });
_SelectableItemCollection.Add(new SelectableItem() { IsSelected = true, Name = "Two" });
_SelectableItemCollection.Add(new SelectableItem() { IsSelected = false, Name = "Three" });
_DateValue = DateTime.Now;
_ExitCommand = new DelegateCommand(DoExit, CanDoExit);
}
示例9: LibraryViewModel
public LibraryViewModel()
{
Sources = new ObservableCollection<Source>();
Mangas = new ObservableCollection<MangaViewModel>();
Sources.Add(new MangaHereSource());
Sources.Add(new MangaReaderSource());
UpdateMangasWithRecentChaptersCommand = new Command(UpdateMangasWithRecentChapters, true);
UpdateMangasWithRecentChapters();
ListCollectionView _customerView = CollectionViewSource.GetDefaultView(Mangas) as ListCollectionView;
//_customerView.CustomSort = new MangaSorter();
}
示例10: ShouldSynchroniseChangedListAddMultipleSelectedItems
public void ShouldSynchroniseChangedListAddMultipleSelectedItems()
{
//Arrange
ObservableCollection<string> secondSelectedNames = new ObservableCollection<string>();
// Act
MultiSelectorBehaviours.SetSynchronizedSelectedItems(listView, (IList)secondSelectedNames);
secondSelectedNames.Add(this.names.First());
secondSelectedNames.Add(this.names.Last());
// Assert
this.listView.SelectedItems.ShouldBeEquivalentTo(secondSelectedNames);
}
示例11: InitializeMarks
public void InitializeMarks()
{
marks = new ObservableCollection<Mark>();
// add default marks
marks.Add(new Mark() { Name = "Herz" });
marks.Add(new Mark() { Name = "Leber" });
marks.Add(new Mark() { Name = "Nieren" });
// binding
marksListBox.ItemsSource = marks;
// update labels in project
updateLabels();
}
示例12: CanFilterCollection
public void CanFilterCollection()
{
var originalCollection = new ObservableCollection<ItemMetadata>();
IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => x.Name == "Posible");
originalCollection.Add(new ItemMetadata(new object()));
Assert.AreEqual(0, viewsCollection.Count());
var item = new object();
originalCollection.Add(new ItemMetadata(item) { Name = "Posible" });
Assert.AreEqual(1, viewsCollection.Count());
Assert.AreSame(item, viewsCollection.First());
}
示例13: PopulateReminderList
public void PopulateReminderList()
{
//Populate complete list inside Reminder list
ReminderItemList = new ObservableCollection<ReminderItem>();
ReminderItemList.Add(new ReminderItem { Id = 1, Description = "desc1" });
ReminderItemList.Add(new ReminderItem { Id = 2, Description = "desc2" });
ReminderItemList.Add(new ReminderItem { Id = 3, Description = "desc3" });
//foreach (var item in new ReminderItemDatabase().GetItems())
//{
// ReminderList.Add(new ReminderListItem { Id = item.Id, VehiclePhoto = item.VehicleType + ".png", Name = item.Name, NextServiceDate = item.NextServiceDate.ToString("d") });
//}
}
示例14: InitializeAvailableDevices
public void InitializeAvailableDevices(GKGuardZone zone)
{
AvailableDevices = new ObservableCollection<GuardZoneDeviceViewModel>();
foreach (var device in GKManager.Devices)
{
if (device.Driver.HasGuardZone && !zone.GuardZoneDevices.Any(x => x.DeviceUID == device.UID))
{
if (device.GuardZones.Count > 0 || (device.IsInMPT && !GlobalSettingsHelper.GlobalSettings.ShowMPTsDevices)
|| (device.ZoneUIDs.Count > 0 && !GlobalSettingsHelper.GlobalSettings.ShowZonesDevices)
|| (device.Door != null && !GlobalSettingsHelper.GlobalSettings.ShowDoorsDevices))
continue;
var guardZoneDevice = new GKGuardZoneDevice
{
DeviceUID = device.UID,
Device = device
};
var deviceViewModel = new GuardZoneDeviceViewModel(guardZoneDevice);
AvailableDevices.Add(deviceViewModel);
}
}
OnPropertyChanged(() => AvailableDevices);
SelectedAvailableDevice = AvailableDevices.FirstOrDefault();
}
示例15: selectAllDate
public ObservableCollection<LinkageSetOR> selectAllDate()
{
string sql = @"select tl.*,t.StationName,d.DeviceName,c.ChannelName
,tLine.StationName as LineStationName,dLine.DeviceName as LineDeviceName,cLine.ChannelName as LineChannelName
from t_LinkageSet tl
inner join t_Station t on tl.StationID=t.StationID
inner join t_Device d on tl.DeviceID=d.DeviceID
inner join t_Channel c on tl.ChannelNo=c.ChannelNo and c.DeviceID=d.DeviceID
inner join t_Station tLine on tl.LinkageStationID=tLine.StationID
inner join t_Device dLine on tl.LinkageDeviceID=dLine.DeviceID
inner join t_Channel cLine on tl.LinkageChannelNo=cLine.ChannelNo and cLine.DeviceID=dLine.DeviceID";
DataTable dt = null;
try
{
dt = db.ExecuteQuery(sql);
}
catch (Exception ex)
{
throw ex;
}
ObservableCollection<LinkageSetOR> _List = new ObservableCollection<LinkageSetOR>();
foreach (DataRow dr in dt.Rows)
{
LinkageSetOR obj = new LinkageSetOR(dr);
_List.Add(obj);
}
return _List;
}