本文整理汇总了C#中System.Windows.DependencyObject类的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject类的具体用法?C# DependencyObject怎么用?C# DependencyObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DependencyObject类属于System.Windows命名空间,在下文中一共展示了DependencyObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnValidSpinDirectionPropertyChanged
/// <summary>
/// ValidSpinDirectionProperty property changed handler.
/// </summary>
/// <param name="d">ButtonSpinner that changed its ValidSpinDirection.</param>
/// <param name="e">Event arguments.</param>
private static void OnValidSpinDirectionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Spinner source = (Spinner)d;
ValidSpinDirections oldvalue = (ValidSpinDirections)e.OldValue;
ValidSpinDirections newvalue = (ValidSpinDirections)e.NewValue;
source.OnValidSpinDirectionChanged(oldvalue, newvalue);
}
示例2: ViewToViewModelMappingContainer
/// <summary>
/// Initializes a new instance of the <see cref="ViewToViewModelMappingContainer"/> class.
/// </summary>
/// <param name="dependencyObject">The dependency object.</param>
/// <exception cref="ArgumentNullException">The <paramref name="dependencyObject"/> is <c>null</c>.</exception>
public ViewToViewModelMappingContainer(DependencyObject dependencyObject)
{
Argument.IsNotNull("dependencyObject", dependencyObject);
var properties = dependencyObject.GetType().GetPropertiesEx();
foreach (var property in properties)
{
object[] viewToViewModelAttributes = property.GetCustomAttributesEx(typeof(ViewToViewModelAttribute), false);
if (viewToViewModelAttributes.Length > 0)
{
Log.Debug("Property '{0}' is decorated with the ViewToViewModelAttribute, creating a mapping", property.Name);
var viewToViewModelAttribute = (ViewToViewModelAttribute)viewToViewModelAttributes[0];
string propertyName = property.Name;
string viewModelPropertyName = (string.IsNullOrEmpty(viewToViewModelAttribute.ViewModelPropertyName)) ? propertyName : viewToViewModelAttribute.ViewModelPropertyName;
var mapping = new ViewToViewModelMapping(propertyName, viewModelPropertyName, viewToViewModelAttribute.MappingType);
// Store it (in 2 dictionaries for high-speed access)
_viewToViewModelMappings.Add(property.Name, mapping);
_viewModelToViewMappings.Add(viewModelPropertyName, mapping);
}
}
}
示例3: AttachmentChangedCallback
private static void AttachmentChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var item = d as AttachmentListBoxItem;
if (item == null)
return;
if (File.Exists(item.Attachment))
{
item.ShortName = Path.GetFileName(item.Attachment);
var icon = Icon.ExtractAssociatedIcon(item.Attachment);
if (icon == null)
return;
item.FileIcon = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
icon.Dispose();
GC.Collect(1);
item.UpdateLayout();
}
}
示例4: HandleIsEnabledChanged
private static void HandleIsEnabledChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
var textBlock = source as TextBlock;
if (textBlock == null)
{
return;
}
if ((bool)e.OldValue)
{
var fader = GetFader(textBlock);
if (fader != null)
{
fader.Detach();
SetFader(textBlock, null);
}
textBlock.Loaded -= HandleTextBlockLoaded;
textBlock.Unloaded -= HandleTextBlockUnloaded;
}
if ((bool)e.NewValue)
{
textBlock.Loaded += HandleTextBlockLoaded;
textBlock.Unloaded += HandleTextBlockUnloaded;
var fader = new Fader(textBlock);
SetFader(textBlock, fader);
fader.Attach();
}
}
示例5: SetBinding
internal static void SetBinding(this DependencyObject sourceObject, DependencyObject targetObject, DependencyProperty sourceProperty, DependencyProperty targetProperty)
{
Binding b = new Binding();
b.Source = sourceObject;
b.Path = new PropertyPath(sourceProperty);
BindingOperations.SetBinding(targetObject, targetProperty, b);
}
示例6: SelectTemplate
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
var ctxt = (container as FrameworkElement);
if (ctxt == null) return null;
if (item == null)
{
//System.Diagnostics.Trace.WriteLine("Warning: Null item in data template selector");
return ctxt.FindResource("Empty") as DataTemplate;
}
// Allow type-specific data templates to take precedence (should we)?
var key = new DataTemplateKey(item.GetType());
var typeTemplate = ctxt.TryFindResource(key) as DataTemplate;
if (typeTemplate != null)
return typeTemplate;
// Common problem if the MEF import failed to find any suitable DLLs
if (!Renderers.Any())
System.Diagnostics.Trace.WriteLine("Warning: No visualizer components loaded");
var template = "";
var r = Renderers
.OrderByDescending(i => i.Importance)
.FirstOrDefault(i => (i.CanRender(item, ref template)));
if (r == null || String.IsNullOrEmpty(template))
{
System.Diagnostics.Trace.WriteLine("Warning: No renderers that can handle object");
return ctxt.FindResource("Default") as DataTemplate;
}
return ctxt.TryFindResource(template) as DataTemplate ?? ctxt.FindResource("Missing") as DataTemplate;
}
示例7: BusyCountChangedCallback
private static void BusyCountChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (0.Equals(e.NewValue))
SetIsBusy(d, false);
else
SetIsBusy(d, true);
}
示例8: OnUserQueryChanged
private static void OnUserQueryChanged(DependencyObject s, UserQueryEntity uc)
{
UserQueryPermission.ViewUserQuery.Authorize();
var currentEntity = UserAssetsClient.GetCurrentEntity(s);
var csc = s as CountSearchControl;
if (csc != null)
{
csc.QueryName = QueryClient.GetQueryName(uc.Query.Key);
using (currentEntity == null ? null : CurrentEntityConverter.SetCurrentEntity(currentEntity))
UserQueryClient.ToCountSearchControl(uc, csc);
csc.Search();
return;
}
var sc = s as SearchControl;
if (sc != null && sc.ShowHeader == false)
{
sc.QueryName = QueryClient.GetQueryName(uc.Query.Key);
using (currentEntity == null ? null : CurrentEntityConverter.SetCurrentEntity(currentEntity))
UserQueryClient.ToSearchControl(uc, sc);
sc.Search();
return;
}
return;
}
示例9: OnIsPivotAnimatedChanged
private static void OnIsPivotAnimatedChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
{
ItemsControl list = d as ItemsControl;
list.Loaded += (s2, e2) =>
{
// locate the pivot control that this list is within
Pivot pivot = list.Ancestors<Pivot>().Single() as Pivot;
// and its index within the pivot
int pivotIndex = pivot.Items.IndexOf(list.Ancestors<PivotItem>().Single());
bool selectionChanged = false;
pivot.SelectionChanged += (s3, e3) =>
{
selectionChanged = true;
};
// handle manipulation events which occur when the user
// moves between pivot items
pivot.ManipulationCompleted += (s, e) =>
{
if (!selectionChanged)
return;
selectionChanged = false;
if (pivotIndex != pivot.SelectedIndex)
return;
// determine which direction this tab will be scrolling in from
bool fromRight = e.TotalManipulation.Translation.X <= 0;
// locate the stack panel that hosts the items
VirtualizingStackPanel vsp = list.Descendants<VirtualizingStackPanel>().First() as VirtualizingStackPanel;
// iterate over each of the items in view
int firstVisibleItem = (int)vsp.VerticalOffset;
int visibleItemCount = (int)vsp.ViewportHeight;
for (int index = firstVisibleItem; index <= firstVisibleItem + visibleItemCount; index++)
{
// find all the item that have the AnimationLevel attached property set
var lbi = list.ItemContainerGenerator.ContainerFromIndex(index);
if (lbi == null)
continue;
vsp.Dispatcher.BeginInvoke(() =>
{
var animationTargets = lbi.Descendants().Where(p => ListAnimation.GetAnimationLevel(p) > -1);
foreach (FrameworkElement target in animationTargets)
{
// trigger the required animation
GetAnimation(target, fromRight).Begin();
}
});
};
};
};
}
示例10: OnDeckChanged
private static void OnDeckChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var viewer = d as DeckCardsViewer;
var newdeck = e.NewValue as MetaDeck ?? new MetaDeck(){IsCorrupt = true};
var g = GameManager.Get().GetById(newdeck.GameId);
viewer.deck = newdeck.IsCorrupt ?
null
: g == null ?
null
: newdeck;
viewer._view = viewer.deck == null ?
new ListCollectionView(new List<MetaMultiCard>())
: new ListCollectionView(viewer.deck.Sections.SelectMany(x => x.Cards).ToList());
viewer.OnPropertyChanged("Deck");
viewer.OnPropertyChanged("SelectedCard");
Task.Factory.StartNew(
() =>
{
Thread.Sleep(0);
viewer.Dispatcher.BeginInvoke(new Action(
() =>
{
viewer.FilterChanged(viewer._filter);
}));
});
}
示例11: IsReadOnlyPropertyChangedCallback
private static void IsReadOnlyPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue != e.NewValue && e.NewValue != null) {
var numUpDown = (NumericUpDown)dependencyObject;
numUpDown.ToggleReadOnlyMode((bool)e.NewValue);
}
}
示例12: OnPanelContentPropertyChanged
private static void OnPanelContentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
try
{
ParentPanel item = d as ParentPanel;
ICleanup oldValue = e.OldValue as ICleanup;
if (oldValue != null)
{
oldValue.Cleanup();
oldValue = null;
}
if (e.NewValue != null)
{
item.ParentContent.Content = null;
item.ParentContent.Content = e.NewValue;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例13: OnGroupNameChanged
private static void OnGroupNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//Add an entry to the group name collection
var menuItem = d as MenuItem;
if (menuItem != null)
{
String newGroupName = e.NewValue.ToString();
String oldGroupName = e.OldValue.ToString();
if (String.IsNullOrEmpty(newGroupName))
{
//Removing the toggle button from grouping
RemoveCheckboxFromGrouping(menuItem);
}
else
{
//Switching to a new group
if (newGroupName != oldGroupName)
{
if (!String.IsNullOrEmpty(oldGroupName))
{
//Remove the old group mapping
RemoveCheckboxFromGrouping(menuItem);
}
ElementToGroupNames.Add(menuItem, e.NewValue.ToString());
menuItem.Checked += MenuItemChecked;
}
}
}
}
示例14: OnScrollGroupChanged
private static void OnScrollGroupChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
var scrollViewer = d as ScrollViewer;
if (scrollViewer != null) {
if (!string.IsNullOrEmpty((string)e.OldValue)) {
// Remove scrollviewer
if (scrollViewers.ContainsKey(scrollViewer)) {
scrollViewer.ScrollChanged -=
new ScrollChangedEventHandler(ScrollViewer_ScrollChanged);
scrollViewers.Remove(scrollViewer);
}
}
if (!string.IsNullOrEmpty((string)e.NewValue)) {
if (verticalScrollOffsets.Keys.Contains((string)e.NewValue)) {
scrollViewer.ScrollToVerticalOffset(verticalScrollOffsets[(string)e.NewValue]);
} else {
verticalScrollOffsets.Add((string)e.NewValue, scrollViewer.VerticalOffset);
}
// Add scrollviewer
scrollViewers.Add(scrollViewer, (string)e.NewValue);
scrollViewer.ScrollChanged += new ScrollChangedEventHandler(ScrollViewer_ScrollChanged);
}
}
}
示例15: IsValid
public static bool IsValid(DependencyObject node)
{
bool result;
if (node != null)
{
if (Validation.GetHasError(node))
{
if (node is IInputElement)
{
Keyboard.Focus((IInputElement)node);
}
result = false;
return result;
}
}
foreach (object subnode in LogicalTreeHelper.GetChildren(node))
{
if (subnode is DependencyObject)
{
if (!ValidationUtil.IsValid((DependencyObject)subnode))
{
result = false;
return result;
}
}
}
result = true;
return result;
}