本文整理汇总了C#中ObservableCollection类的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection类的具体用法?C# ObservableCollection怎么用?C# ObservableCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObservableCollection类属于命名空间,在下文中一共展示了ObservableCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectControlViewModel_AddNewServer_ResourceRepositoryReturnExistingServers_False
public void ConnectControlViewModel_AddNewServer_ResourceRepositoryReturnExistingServers_False()
{
//------------Setup for test--------------------------
var mainViewModel = new Mock<IMainViewModel>();
var connectControlSingleton = new Mock<IConnectControlSingleton>();
var env1 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
var env2 = new TestEnvironmentModel(new Mock<IEventAggregator>().Object, Guid.NewGuid(), CreateConnection(true, false).Object, new Mock<IResourceRepository>().Object, false);
var connectControlEnvironments = new ObservableCollection<IConnectControlEnvironment>();
var controEnv1 = new Mock<IConnectControlEnvironment>();
var controEnv2 = new Mock<IConnectControlEnvironment>();
controEnv1.Setup(c => c.EnvironmentModel).Returns(env1);
controEnv2.Setup(c => c.EnvironmentModel).Returns(env2);
controEnv1.Setup(c => c.IsConnected).Returns(true);
connectControlEnvironments.Add(controEnv2.Object);
connectControlEnvironments.Add(controEnv1.Object);
connectControlSingleton.Setup(c => c.Servers).Returns(connectControlEnvironments);
var environmentRepository = new Mock<IEnvironmentRepository>();
ICollection<IEnvironmentModel> environments = new Collection<IEnvironmentModel>
{
env1
};
environmentRepository.Setup(e => e.All()).Returns(environments);
var viewModel = new ConnectControlViewModel(mainViewModel.Object, environmentRepository.Object, e => { }, connectControlSingleton.Object, "TEST : ", false);
//------------Execution-------------------------------
int serverIndex;
var didAddNew = viewModel.AddNewServer(out serverIndex, i => { });
//------------Assert----------------------------------
Assert.IsNotNull(viewModel);
Assert.IsFalse(didAddNew);
}
示例2: ViewModel
public ViewModel()
{
mgt = new ManagementClass("Win32_Processor");
procs = mgt.GetInstances();
CPU = new ObservableCollection<Model>();
timer = new DispatcherTimer();
random = new Random();
time = DateTime.Now;
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
ProcessorID = GetProcessorID();
processes = Process.GetProcesses();
Processes = processes.Length;
MaximumSpeed = GetMaxClockSpeed();
LogicalProcessors = GetNumberOfLogicalProcessors();
Cores = GetNumberOfCores();
L2Cache = GetL2CacheSize();
L3Cache = GetL3CacheSize();
foreach (ManagementObject item in procs)
L1Cache = ((UInt32)item.Properties["L2CacheSize"].Value / 2).ToString() + " KB";
timer.Interval = TimeSpan.FromMilliseconds(1000);
timer.Tick += timer_Tick;
timer.Start();
for (int i = 0; i < 60; i++)
{
CPU.Add(new Model(time, 0,0));
time = time.AddSeconds(1);
}
}
示例3: Dependencia_Insert
public bool Dependencia_Insert(string KeySesion, string DependenciaName)
{
bool res = true;
ObservableCollection<WAPP_USUARIO_SESION> Key = new ObservableCollection<WAPP_USUARIO_SESION>();
try
{
using (var entity_ = new db_SeguimientoProtocolo_r2Entities())
{
(from s in entity_.WAPP_USUARIO_SESION
where s.IdSesion == KeySesion
select s).ToList().ForEach(row =>
{
Key.Add(new WAPP_USUARIO_SESION()
{
IdUsuario = row.IdUsuario,
IdSesion = row.IdSesion
});
});
if (Key[0].IdSesion == KeySesion.ToString())
{
using (var entity = new db_SeguimientoProtocolo_r2Entities())
{
entity.SP_DependenciaInsert(DependenciaName);
}
}
}
}
catch (Exception ex)
{
var errr = ex.Message;
}
return res;
}
示例4: GridViewModel
public GridViewModel()
{
ResultData = new ObservableCollection<TestPointDataObject>();
//get the unique test points
var definedTestPoints = _resultValueTags.Where(dt => dt.Name.ToLower().Contains("testpoint")).GroupBy(dt => dt.Name.Split('.').First()).Select(grp => grp.First().Name.Split('.').First());
//var q2 = _resultValueTags.Where(dt => Regex.Match(dt.Name.Split('.').Single((s) => s.Contains("test")), @"(testpoint)[\d+]", RegexOptions.IgnoreCase).Success);
//Add the test point with a header value of it's number.
foreach (string tp in definedTestPoints)
ResultData.Add(new TestPointDataObject(Regex.Match(tp,@"[\d+]").Value));
foreach (DataTag tag in _resultValueTags.Where(dt => dt.Name.ToLower().Contains("testpoint")))
ResultData.ElementAt(Convert.ToInt32(Regex.Match(tag.Name, @"[\d+]").Value) - 1).Results.Add(new ResultDataObject(tag.Name,tag.Double));
foreach (DataTag tag in _results)
{
tag.ValueChanged += Tag_ValueChanged;
tag.ValueSet += Tag_ValueSet;
}
foreach (var v in ResultData)
{
_view = CollectionViewSource.GetDefaultView(v.Results);
_view.GroupDescriptions.Add(new PropertyGroupDescription("Name", new ResultNameGrouper()));
}
}
示例5: EventCatalogSingleton
//Constructor
private EventCatalogSingleton()
{
Events = new ObservableCollection<Event>();
// The purpose of this is to make some instances of events. It creates instances of events and adds it to the observable collection.
LoadEventAsync();
}
示例6: AddProductViewModel
public AddProductViewModel()
{
LstStatus = new ObservableCollection<ProductStatusDTO>();
LstCategories = new ObservableCollection<ProductCategoryDTO>();
////Hide attributes for all the items sold in loose quantity
////This is default setting, which will be overriden once
////user checks the checkbox on screen.
HideAttributesForLooseItems();
////Get Product status from database
GetProductStatus();
////Get all active Product categories from database
GetCategories();
SaveProductCommand = new RelayCommand(SaveProductSetting);
CancelProductCommand = new RelayCommand(CancelSetting);
SearchProductCommand = new RelayCommand(SearchProducts);
CancelSearchCommand = new RelayCommand(CancelSearch);
GenerateBarCodeCommand = new RelayCommand(GenerateBarCode);
LstProducts = new List<ProductDTO>();
///Get all products
GetProducts(string.Empty);
}
示例7: AutoSuggestBox_TextChanged
private async void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
try
{
if (sender.Text.Length != 0)
{
//ObservableCollection<String>
var data = new ObservableCollection<string>();
var httpclient = new Noear.UWP.Http.AsyncHttpClient();
httpclient.Url("http://mobilecdn.kugou.com/new/app/i/search.php?cmd=302&keyword="+sender.Text);
var httpresult = await httpclient.Get();
var jsondata = httpresult.GetString();
var obj = Windows.Data.Json.JsonObject.Parse(jsondata);
var arryobj = obj.GetNamedArray("data");
foreach (var item in arryobj)
{
data.Add(item.GetObject().GetNamedString("keyword"));
}
sender.ItemsSource = data;
//sender.IsSuggestionListOpen = true;
}
else
{
sender.IsSuggestionListOpen = false;
}
}
catch (Exception)
{
}
}
示例8: ConnectWindow
public ConnectWindow()
{
InitializeComponent();
try
{
IsAvailableServer = ServiceCtrlClass.ServiceIsInstalled("EpgTimer Service") == true ||
System.IO.File.Exists(SettingPath.ModulePath.TrimEnd('\\') + "\\EpgTimerSrv.exe") == true;
btn_edit.Visibility = Visibility.Collapsed;
ConnectionList = new ObservableCollection<NWPresetItem>(Settings.Instance.NWPreset);
var nowSet = new NWPresetItem(DefPresetStr, Settings.Instance.NWServerIP, Settings.Instance.NWServerPort, Settings.Instance.NWWaitPort, Settings.Instance.NWMacAdd, Settings.Instance.NWPassword);
int pos = ConnectionList.ToList().FindIndex(item => item.EqualsTo(nowSet, true));
if (pos == -1)
{
ConnectionList.Add(nowSet);
pos = ConnectionList.Count - 1;
}
if (IsAvailableServer == true)
{
ConnectionList.Insert(0, new NWPresetItem("ローカル接続", "", 0, 0, "", new SerializableSecureString()));
pos++;
}
ConnectionList.Add(new NWPresetItem("<新規登録>", "", 0, 0, "", new SerializableSecureString()));
listView_List.ItemsSource = ConnectionList;
if (IsAvailableServer == false)
{
Settings.Instance.NWMode = true;
}
listView_List.SelectedIndex = Settings.Instance.NWMode == true ? pos : 0;
}
catch { }
}
示例9: MachineStationsVM
public MachineStationsVM(MachineVM machine, AccessType access)
: base(access)
{
UnitOfWork = new SoheilEdmContext();
CurrentMachine = machine;
MachineDataService = new MachineDataService(UnitOfWork);
MachineDataService.StationAdded += OnStationAdded;
MachineDataService.StationRemoved += OnStationRemoved;
StationDataService = new StationDataService(UnitOfWork);
var selectedVms = new ObservableCollection<StationMachineVM>();
foreach (var stationMachine in MachineDataService.GetStations(machine.Id))
{
selectedVms.Add(new StationMachineVM(stationMachine, Access, StationMachineDataService, RelationDirection.Reverse));
}
SelectedItems = new ListCollectionView(selectedVms);
var allVms = new ObservableCollection<StationVM>();
foreach (var station in StationDataService.GetActives(SoheilEntityType.Machines, CurrentMachine.Id))
{
allVms.Add(new StationVM(station, Access, StationDataService));
}
AllItems = new ListCollectionView(allVms);
IncludeCommand = new Command(Include, CanInclude);
ExcludeCommand = new Command(Exclude, CanExclude);
}
示例10: DocumentManagerViewModel
public DocumentManagerViewModel()
{
TaxPayerList = new ObservableCollection<TaxPayerEntity>();
TaxPayerTypeList = new ObservableCollection<TaxPayerTypeEntity>();
TaxPayerTypeEntityDictionary = new Dictionary<int, TaxPayerTypeEntity>();
FileTypeList = new ObservableCollection<FileTypeEntity>();
FileTypeDictionary = new Dictionary<int, FileTypeEntity>();
UserEntityDictionary = new Dictionary<int, UserEntity>();
DocumentViewModel = new DocumentViewModel();
DocumentViewModel.BeginLoadings += BeginLoading;
DocumentViewModel.FinishLoadings += FinishLoading;
documentManagerContext = new DocumentManager.Web.DocumentManagerDomainContext();
OnAddTaxPayer = new DelegateCommand(onAddTaxPayer);
OnAddProject = new DelegateCommand(onAddProject, canAddProject);
OnModifyTaxPayer = new DelegateCommand(onModifyTaxPayer, canModifyTaxPayer);
OnDeleteTaxPayer = new DelegateCommand(onDeleteTaxPayer, canDeleteTacPayer);
OnRefresh = new DelegateCommand(onRefresh);
OnDoubleClickList = new DelegateCommand(onDoubleClickList);
taxPayerDocumentSource = new EntityList<Web.Model.taxpayerdocument>(documentManagerContext.taxpayerdocuments);
taxPayerDocumentLoader = new DomainCollectionViewLoader<Web.Model.taxpayerdocument>(
LoadTaxPayerDocument,
LoadTaxPayerDocument_Complete
);
taxPayerDocumentView = new DomainCollectionView<Web.Model.taxpayerdocument>(taxPayerDocumentLoader, taxPayerDocumentSource);
}
示例11: ServersList
public ServersList(ServersListMessage msg)
{
if (msg == null) throw new ArgumentNullException("msg");
m_collection = new ObservableCollection<ServersListEntry>(msg.servers.Select(entry => new ServersListEntry(entry)));
m_readOnlyCollection = new ReadOnlyObservableCollection<ServersListEntry>(m_collection);
}
示例12: PaymentButtonGroupViewModel
public PaymentButtonGroupViewModel(ICaptionCommand makePaymentCommand, ICaptionCommand settleCommand, ICaptionCommand closeCommand)
{
_makePaymentCommand = makePaymentCommand;
_settleCommand = settleCommand;
_closeCommand = closeCommand;
_paymentButtons = new ObservableCollection<CommandButtonViewModel<PaymentTemplate>>();
}
示例13: ConfigurationWindow
public ConfigurationWindow()
{
InitializeComponent();
DataContext = this;
ObservableCollection<Personality> personalities = new ObservableCollection<Personality>();
// Add our default personality
personalities.Add(Personality.Default());
foreach (Personality personality in Personality.AllFromDirectory())
{
personalities.Add(personality);
}
// Add local personalities
foreach (Personality personality in personalities)
{
Logging.Debug("Found personality " + personality.Name);
}
Personalities = personalities;
SpeechResponderConfiguration configuration = SpeechResponderConfiguration.FromFile();
foreach (Personality personality in Personalities)
{
if (personality.Name == configuration.Personality)
{
Personality = personality;
break;
}
}
}
示例14: MenuGeneral
public MenuGeneral()
{
//Delegate pour exécuter du code personnalisé lors du changement de langue de l'UI.
CultureManager.UICultureChanged += CultureManager_UICultureChanged;
mapLangue = new ObservableCollection<LangueUI>();
//Le tag de langue IETF (ie: fr-CA) utilisé directement pour changer la langue d'affichage.
//Récupéré selon la Langue active.
string codeLangueActif;
//Si l'utilisateur est connecté, utilise la langue sauvegarder sous son profil.
if (App.MembreCourant.IdMembre != null)
{
codeLangueActif = App.MembreCourant.LangueMembre.IETF;
}
else
{
//Sinon, utilise la valeur par défault tel que défini sous App.
codeLangueActif = App.LangueInstance.IETF;
}
mapLangue.Add(francais);
mapLangue.Add(anglais);
//Dans le dictionnaire, trouve l'élément qui a le tag IETF équivalent à selui enregistré sous codeLangueActif et le met à actif.
mapLangue.FirstOrDefault(l => l.LangueSys.IETF == codeLangueActif).Actif = true;
InitializeComponent();
//Configure la source de notre dataGrid.
dgLangues.ItemsSource = mapLangue;
}
示例15: btnCerca_Click
private void btnCerca_Click(object sender, RoutedEventArgs e)
{
var list = dag.cercaSoggiorni((DateTime)datePickerArrivo.SelectedDate, (DateTime)datePickerPartenza.SelectedDate, cliente);
soggiorniResult = new ObservableCollection<Soggiorno>(list);
dataGridSoggiorni.DataContext = soggiorniResult;
}