本文整理汇总了C#中UIElement.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.GetType方法的具体用法?C# UIElement.GetType怎么用?C# UIElement.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIElement
的用法示例。
在下文中一共展示了UIElement.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRenderer
public ElementRenderer GetRenderer(UIElement element)
{
ElementRenderer elementRenderer;
elementIdToRenderer.TryGetValue(element.Id, out elementRenderer);
if (elementRenderer == null)
{
// try to get the renderer from the user registered class factory
var currentType = element.GetType();
while (elementRenderer == null && currentType != null)
{
if (typesToUserFactories.ContainsKey(currentType))
elementRenderer = typesToUserFactories[currentType].TryCreateRenderer(element);
currentType = currentType.GetTypeInfo().BaseType;
}
// try to get the renderer from the default renderer factory.
if (elementRenderer == null && defaultFactory != null)
elementRenderer = defaultFactory.TryCreateRenderer(element);
if (elementRenderer == null)
throw new InvalidOperationException($"No renderer found for element {element}");
// cache the renderer for future uses.
elementIdToRenderer[element.Id] = elementRenderer;
}
return elementRenderer;
}
示例2: SetMouseHandlersForElement
/// <summary>
/// Sets the mouse handlers for element. Mouse hover handler is added to change the helpful text, and click handler is
/// added to open the color picker.
/// When the color is saved, it updates the theme, and applies it.
/// </summary>
/// <param name="themeKey">The theme key (as per the json theme).</param>
/// <param name="hoverText">The hover text.</param>
/// <param name="element">The element on which we add hover and click handlers.</param>
private void SetMouseHandlersForElement(string themeKey, string hoverText, UIElement element)
{
if (element == null) {
return;
}
// change the instruction text to hoverText
element.IsMouseDirectlyOverChanged += (sender, e) =>
{
if (ViewModel.Editable && (bool) e.NewValue) {
// mouse is now directly over this element, show the helpful text to the user so they know what they are hovering
HoveredElementInfo.Text = hoverText;
return;
}
// mouse is no longer directly over this element
HoveredElementInfo.Text = "";
};
// handle onclick
element.PreviewMouseDown += (sender, e) =>
{
// the rhs of the OR is a hack because TextBox elements have child element of TextBoxView (internal), its ugly, needs improvement
var isCorrectElement = e.OriginalSource.Equals(element) ||
(element.GetType() == typeof (TextBox) &&
e.OriginalSource.GetType().Name == "TextBoxView");
if (ViewModel.Editable && isCorrectElement) {
// mouse is now directly over this element, show the helpful text to the user so they know what they are hovering
ViewModel.ShowColorPicker(Window.GetWindow(this), hoverText, themeKey);
e.Handled = true;
}
};
}
示例3: ForceValidation
public void ForceValidation(UIElement element)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
{
var child = (UIElement)VisualTreeHelper.GetChild(element, i);
ForceValidation(child);
}
BindingExpression bindingExpression = null;
string uiElementType = element.GetType().ToString();
switch (uiElementType)
{
case "System.Windows.Controls.TextBox":
bindingExpression = ((TextBox)element).GetBindingExpression(TextBox.TextProperty);
break;
case "System.Windows.Controls.RadioButton":
bindingExpression = ((RadioButton)element).GetBindingExpression(RadioButton.IsCheckedProperty);
break;
//case "SIC.Presentation.UI.ComboBoxEx":
// bindingExpression = ((ComboBoxEx)element).GetBindingExpression(ComboBoxEx.SelectedValueProperProperty);
// break;
//case "SIC.Presentation.UI.DateTimePicker.Views.PDatePicker":
// bindingExpression = ((PDatePicker)element).GetBindingExpression(PDatePicker.SelectedDateProperty);
// break;
}
if (bindingExpression == null || bindingExpression.ParentBinding == null) return;
//if (!bindingExpression.ParentBinding.ValidatesOnExceptions) return;
bindingExpression.UpdateSource();
}
示例4: PageNavigator
public PageNavigator(Application app, UIElement defaultPage)
{
application = app;
defaultPageName = defaultPage.GetType().FullName;
CreateRootVisual();
UIElement element = null;
if (HtmlPage.IsEnabled)
{
DispatcherTimer timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) };
timer.Tick += (sender, e) =>
{
string hash = GetAnchor();
if (hash != currentHash &&
(pageGrid.Children.Count == 0 || pageGrid.Children[0].GetType().FullName != hash))
{
ShowElement(LoadElement(hash));
}
currentHash = hash;
};
currentHash = GetAnchor();
element = LoadElement(currentHash);
timer.Start();
}
ShowElement(element ?? defaultPage);
}
示例5: TryCreateRenderer
public ElementRenderer TryCreateRenderer(UIElement element)
{
// try to get the renderer from the registered default renderer
var currentType = element.GetType();
while (currentType != null)
{
if (typeToRenderers.ContainsKey(currentType))
return typeToRenderers[currentType];
currentType = currentType.GetTypeInfo().BaseType;
}
return defaultRenderer;
}
示例6: GetPeer
public static AutomationPeer GetPeer(UIElement element)
{
if (element == null)
return null;
Func<UIElement, AutomationPeer> func;
lock (Lookups)
{
if (!Lookups.TryGetValue(element.GetType(), out func))
return null;
}
if (func == null)
return null;
return func(element);
}
示例7: scene_PreviewMouseLeftButtonDown
void scene_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (selected)
{
selected = false;
if (selectedElement != null)
{
a.Remove(a.GetAdorners(selectedElement)[0]);
selectedElement = null;
}
}
if (e.Source != scene)
{
IsMouseDown = true;
startPoint = e.GetPosition(scene);
selectedElement = e.Source as UIElement;
Console.WriteLine(selectedElement);
oLeft = Canvas.GetLeft(selectedElement);
oTop = Canvas.GetTop(selectedElement);
a = AdornerLayer.GetAdornerLayer(selectedElement);
a.Add(new Adorners(selectedElement, this));
selected = true;
if (selectedElement.GetType().Equals(typeof(Image)))
{
DraggableImage = (Image)selectedElement;
curType = (int)TYPE.IMAGE;
}
if (selectedElement.GetType().Equals(typeof(MediaElement)))
{
DraggableVideo = (MediaElement)selectedElement;
curType = (int)TYPE.VIDEO;
}
if (selectedElement.GetType().Equals(typeof(TextBlock)))
{
DraggableText = (TextBlock)selectedElement;
curType = (int)TYPE.TEXT;
}
if (selectedElement.GetType().Equals(typeof(Rectangle)) || selectedElement.GetType().Equals(typeof(Ellipse)))
{
DraggableShape = (Shape)selectedElement;
curType = (int)TYPE.SHAPE;
}
e.Handled = true;
}
}
示例8: translateRecursively
private static void translateRecursively(UIElement obj) {
if (obj is FrameworkElement) {
FrameworkElement fe = obj as FrameworkElement;
if (fe.ToolTip != null && fe.ToolTip.ToString().StartsWith("$")) {
string tipname = fe.ToolTip.ToString().Substring(1);
fe.ToolTip = Strings.GetToolTipString(tipname);
}
if (fe.ContextMenu != null) {
foreach (MenuItem item in fe.ContextMenu.Items) {
translateMenuItem(item);
}
}
}
if (obj == null ||
obj is ProgressBar ||
obj is ComboBox ||
obj is Image ||
obj is TreeView ||
obj is System.Windows.Shapes.Shape ||
obj is PasswordBox ||
obj is GridSplitter ||
obj is ResizeGrip) {
} else if (objectIsOfType(obj, typeof(TextBox))) {
if (objectIsOfType(obj, typeof(RibbonTextBox))) {
translateLabel(obj as RibbonTextBox);
}
} else if (obj is ItemsControl) {
ItemsControl items = obj as ItemsControl;
foreach (object item in items.Items) {
if (item.GetType().IsSubclassOf(typeof(UIElement)))
translateRecursively(item as UIElement);
}
if (obj is Ribbon) {
Ribbon rib = obj as Ribbon;
if (rib.HelpPaneContent != null && rib.HelpPaneContent is UIElement) {
translateRecursively(rib.HelpPaneContent as UIElement);
}
}
if (obj is HeaderedItemsControl) {
if (obj is MenuItem) {
translateMenuItem(obj as MenuItem);
} else {
translateHeader(obj as HeaderedItemsControl);
}
}
if (obj is ListView) {
ListView list = obj as ListView;
if (list.View != null) {
GridView view = list.View as GridView;
if (view.Columns != null) {
foreach (GridViewColumn col in view.Columns) {
translateColumnHeader(col);
}
}
}
}
if (obj is RibbonMenuButton) {
translateLabel(obj as RibbonMenuButton);
}
} else if (obj is Panel) {
Panel grid = obj as Panel;
foreach (UIElement elem in grid.Children) {
translateRecursively(elem);
}
} else if (obj is StatusBar) {
StatusBar bar = obj as StatusBar;
foreach (UIElement element in bar.Items) {
translateRecursively(element);
}
} else if (obj is TabControl) {
TabControl tabs = obj as TabControl;
foreach (TabItem item in tabs.Items) {
translateRecursively(item);
}
} else if (obj is StatusBarItem) {
StatusBarItem item = obj as StatusBarItem;
translateRecursively(item.Content as UIElement);
} else if (obj is RibbonCheckBox) {
translateLabel(obj as RibbonCheckBox);
} else if (obj is ContentControl) {
if (obj is HeaderedContentControl) {
HeaderedContentControl head = obj as HeaderedContentControl;
translateHeader(head);
translateRecursively(head.Content as UIElement);
} else if (obj is RibbonButton) {
translateLabel(obj as RibbonButton);
} else if (obj is RibbonToggleButton) {
translateLabel(obj as RibbonToggleButton);
} else if (obj is Button) {
translateButton(obj as Button);
} else {
translateContent(obj as ContentControl);
}
} else if (objectIsOfType(obj, typeof(TextBlock))) {
translateText(obj as TextBlock);
//.........这里部分代码省略.........
示例9: translate
public static void translate(UIElement obj, string name, params string[] variables) {
name = "$" + name;
if (obj == null ||
obj is ProgressBar ||
obj is ComboBox ||
obj is Image ||
obj is TreeView ||
obj is PasswordBox) {
} else if (obj is TextBox) {
if (obj is RibbonTextBox || obj.GetType().IsSubclassOf(typeof(RibbonTextBox))) {
translateLabel(obj as RibbonTextBox, name, variables);
}
} else if (obj is TextBlock) {
translateText(obj as TextBlock, name, variables);
} else if (obj is ContentControl) {
if (obj is Window) {
translateTitle(obj as Window, name, variables);
} else if (obj is HeaderedContentControl) {
translateHeader(obj as HeaderedContentControl, name, variables);
} else if (obj is RibbonButton) {
translateLabel(obj as RibbonButton, name, variables);
} else {
translateContent(obj as ContentControl, name, variables);
}
} else {
throw new Exception("Can't translate object " + obj.GetType().ToString());
}
}
示例10: DumpUIElement
// ------------------------------------------------------------------
// Dump content of UIElement.
// ------------------------------------------------------------------
private static void DumpUIElement(XmlTextWriter writer, UIElement element, Visual parent, bool uiElementsOnly)
{
writer.WriteStartElement(element.GetType().Name);
// Dump layout information
DumpSize(writer, "DesiredSize", element.DesiredSize);
DumpSize(writer, "ComputedSize", element.RenderSize);
Geometry clip = VisualTreeHelper.GetClip(element);
if (clip != null)
{
DumpRect(writer, "Clip.Bounds", clip.Bounds);
}
// Dump transform relative to its parent
GeneralTransform g = element.TransformToAncestor(parent);
Point point = new Point(0, 0);
g.TryTransform(point, out point);
if (point.X != 0 || point.Y != 0)
{
DumpPoint(writer, "Position", point);
}
// Dump element specific information
bool childrenHandled = false;
Type t = element.GetType();
DumpCustomUIElement dumpElement = null;
while(dumpElement==null && t!=null)
{
dumpElement = _elementToDumpHandler[t] as DumpCustomUIElement;
t = t.BaseType;
}
if (dumpElement != null)
{
childrenHandled = dumpElement(writer, element, uiElementsOnly);
}
if (!childrenHandled)
{
if (uiElementsOnly)
{
DumpUIElementChildren(writer, "Children", element);
}
else
{
DumpVisualChildren(writer, "Children", element);
}
}
writer.WriteEndElement();
}
示例11: GetQuickAccessItem
public static FrameworkElement GetQuickAccessItem(UIElement element)
{
FrameworkElement result = null;
// If control supports the interface just return what it provides
IQuickAccessItemProvider provider = (element as IQuickAccessItemProvider);
if ((provider != null) && (provider.CanAddToQuickAccessToolBar))
result = ((IQuickAccessItemProvider)element).CreateQuickAccessItem();
// The control isn't supported
if (result == null) throw new ArgumentException("The contol " + element.GetType().Name + " is not able to provide a quick access toolbar item");
return result;
}
示例12: LocateForView
/// <summary>
/// Locates the view model for the specified view instance.
/// </summary>
/// <param name="view">The view instance.</param>
/// <returns>The view model.</returns>
public object LocateForView(UIElement view)
{
if (view == null)
throw new ArgumentNullException(nameof(view));
var frameworkElement = view as FrameworkElement;
if (frameworkElement != null && frameworkElement.DataContext != null)
{
Log.Info("Using current data context for {0}.", view);
return frameworkElement.DataContext;
}
var viewType = view.GetType();
var modelType = _typeResolver.GetModelType(viewType);
if (modelType == null)
{
Log.Error("Cannot find model for {0}.", viewType);
return null;
}
var model = IoC.GetInstance(modelType);
if (model == null)
{
Log.Error("Cannot locate {0}.", modelType);
return null;
}
return model;
}
示例13: dirtyThisElement
private void dirtyThisElement(UIElement element)
{
var thisImage = (System.Windows.Controls.Image)element;
var dirtyElement = new TargettedDirtyElement(currentSlide, Globals.me, target,thisImage.tag().privacy, thisImage.tag().id );
switch (element.GetType().ToString())
{
case "System.Windows.Controls.Image":
var image = (System.Windows.Controls.Image)element;
ApplyPrivacyStylingToElement(image, image.tag().privacy);
Commands.SendDirtyImage.Execute(dirtyElement);
break;
case "MeTLLib.DataTypes.Video":
Commands.MirrorVideo.ExecuteAsync(new VideoMirror.VideoMirrorInformation(dirtyElement.identifier, null));
Commands.SendDirtyVideo.ExecuteAsync(dirtyElement);
break;
}
}
示例14: sendThisElement
private void sendThisElement(UIElement element)
{
switch (element.GetType().ToString())
{
case "System.Windows.Controls.Image":
var newImage = (System.Windows.Controls.Image)element;
newImage.UpdateLayout();
Commands.SendImage.Execute(new TargettedImage(currentSlide, Globals.me, target, newImage.tag().privacy, newImage));
break;
case "MeTLLib.DataTypes.Video":
var srVideo = (Video)element;
srVideo.UpdateLayout();
srVideo.X = GetLeft(srVideo);
srVideo.Y = GetTop(srVideo);
Commands.SendVideo.Execute(new TargettedVideo(currentSlide, Globals.me, target, srVideo.tag().privacy, srVideo));
break;
}
}
示例15: ShortcutAdornerControl
public ShortcutAdornerControl(UIElement adornedElement)
{
this.Focusable = false;
this.AdornedElementType = adornedElement.GetType();
this.transform = new TranslateTransform();
this.RenderTransform = transform;
}