本文整理汇总了C#中System.Collections.Dictionary.ValueForKey方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.ValueForKey方法的具体用法?C# Dictionary.ValueForKey怎么用?C# Dictionary.ValueForKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.ValueForKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObserveValueForKeyPathOfObject
public void ObserveValueForKeyPathOfObject(String keyPath, Object obj, Dictionary<String, Object> change, Object context)
{
String message = "KVO change notification received" + Environment.NewLine + Environment.NewLine;
if (change.ValueForKey(KNKVOConstants.KNKeyValueChangeNewKey) != null)
{
message += "New: " + change.ValueForKey(KNKVOConstants.KNKeyValueChangeNewKey).ToString() + Environment.NewLine;
}
if (change.ValueForKey(KNKVOConstants.KNKeyValueChangeOldKey) != null)
{
message += "Old: " + change.ValueForKey(KNKVOConstants.KNKeyValueChangeOldKey).ToString() + Environment.NewLine;
}
MessageBox.Show(message);
}
示例2: ObserveValueForKeyPathOfObject
public void ObserveValueForKeyPathOfObject(String aKeyPath, Object anObj, Dictionary<String, Object> change, Object aContext)
{
if (change != null && change.ValueForKey(KNKVOConstants.KNKeyValueChangeNotificationIsPriorKey) != null) {
Object oldValue = observedObject.ValueForKeyPath(keyPath);
KNKVOObservationChangeTracker tracker = new KNKVOObservationChangeTracker(oldValue, aKeyPath);
changes.Push(tracker);
// Remove our observers completely
Object currentObj = observedObject;
ArrayList keys = new ArrayList(keyPath.Split('.'));
foreach (String key in keys) {
previousObservations.Add(new KeyValuePair<Object, String>(currentObj, key));
currentObj = currentObj.ValueForKey(key);
if (currentObj == null) { break; }
}
if ((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionPrior) == KNKeyValueObservingOptions.KNKeyValueObservingOptionPrior) {
Dictionary<String, Object> changeDict = new Dictionary<String, Object>();
changeDict.SetValueForKey(true, KNKVOConstants.KNKeyValueChangeNotificationIsPriorKey);
changeDict.SetValueForKey(oldValue, KNKVOConstants.KNKeyValueChangeOldKey);
observer.ObserveValueForKeyPathOfObject(keyPath, observedObject, changeDict, context);
}
} else {
ResetObservationTree();
Dictionary<String, Object> changeDict = new Dictionary<String, Object>();
if (changes.Count > 0) {
KNKVOObservationChangeTracker tracker = changes.Pop();
if (((options & KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) == KNKeyValueObservingOptions.KNKeyValueObservingOptionOld) && (tracker != null)) {
changeDict.SetValueForKey(tracker.OldValue, KNKVOConstants.KNKeyValueChangeOldKey);
}
}
changeDict.SetValueForKey(observedObject.ValueForKeyPath(keyPath), KNKVOConstants.KNKeyValueChangeNewKey);
observer.ObserveValueForKeyPathOfObject(keyPath, observedObject, changeDict, context);
}
}
示例3: ObserveValueForKeyPathOfObject
public void ObserveValueForKeyPathOfObject(string keyPath, object obj, Dictionary<string, object> change, object context)
{
if (context != null && context.Equals(kColumnWidthKVOContext)) {
RebuildBasicLayout();
RebuildColumnLayout();
return;
}
if (keyPath.Equals("SelectedRows")) {
RebuildSelectionLayout();
}
if (keyPath.Equals("HeaderHeight")) {
foreach (KNTableColumn column in Columns) {
column.HeaderHeight = HeaderHeight;
}
}
if (keyPath.Equals("RowHeight")) {
foreach (KNTableColumn column in Columns) {
column.RowHeight = RowHeight;
}
}
if (keyPath.Equals("ContentPadding")) {
foreach (KNTableColumn column in Columns) {
column.RowHeight = RowHeight;
}
}
if (keyPath.Equals("ContentPadding") || keyPath.Equals("Width") || keyPath.Equals("RowHeight") || keyPath.Equals("HeaderHeight") || keyPath.Equals("VerticalScrollBarVisibility") || keyPath.Equals("HorizontalScrollBarVisibility")) {
RebuildBasicLayout();
}
if (keyPath.Equals("Columns")) {
KNTableColumn[] oldColumns = (KNTableColumn[])change.ValueForKey(KNKVOConstants.KNKeyValueChangeOldKey);
if (oldColumns != null) {
foreach (KNTableColumn column in oldColumns) {
column.RemoveObserverFromKeyPath(this, "Width");
}
}
KNTableColumn[] newColumns = (KNTableColumn[])change.ValueForKey(KNKVOConstants.KNKeyValueChangeNewKey);
if (newColumns != null) {
foreach (KNTableColumn column in oldColumns) {
column.AddObserverToKeyPathWithOptions(this, "Width", 0, kColumnWidthKVOContext);
}
}
foreach (KNTableColumn column in Columns) {
column.RowHeight = RowHeight;
column.HeaderHeight = HeaderHeight;
column.ContentPadding = ContentPadding;
}
RebuildColumnLayout();
}
}