本文整理汇总了C#中Windows.UI.Xaml.UIElement类的典型用法代码示例。如果您正苦于以下问题:C# UIElement类的具体用法?C# UIElement怎么用?C# UIElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UIElement类属于Windows.UI.Xaml命名空间,在下文中一共展示了UIElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LostFocusHandler
private void LostFocusHandler(object sender, RoutedEventArgs e)
{
if (lastFocusedElement == (UIElement)sender)
{
lastFocusedElement = null;
}
}
示例2: OnApplyTemplate
/// <summary>
/// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate.
/// In simplest terms, this means the method is called just before a UI element displays in your app.
/// Override this method to influence the default post-template logic of a class.
/// </summary>
protected override void OnApplyTemplate()
{
// Border
this.border = this.GetTemplateChild(BorderPartName) as Border;
if (this.border != null)
{
this.border.ManipulationStarted += Border_ManipulationStarted;
this.border.ManipulationDelta += Border_ManipulationDelta;
this.border.ManipulationCompleted += Border_ManipulationCompleted;
this.border.Tapped += Border_Tapped;
this.border.PointerEntered += Border_PointerEntered;
// Move Canvas properties from control to border.
Canvas.SetLeft(this.border, Canvas.GetLeft(this));
Canvas.SetLeft(this, 0);
Canvas.SetTop(this.border, Canvas.GetTop(this));
Canvas.SetTop(this, 0);
// Move Margin to border.
this.border.Padding = this.Margin;
this.Margin = new Thickness(0);
}
else
{
// Exception
throw new Exception("Floating Control Style has no Border.");
}
// Overlay
this.overlay = GetTemplateChild(OverlayPartName) as UIElement;
this.Loaded += Floating_Loaded;
}
示例3: ShowFlyout
/// <summary>
/// Shows a popup dialog for the specified model relative to the <paramref name="placementTarget"/>.
/// </summary>
/// <param name="rootModel">The root model.</param>
/// <param name="placementTarget">The placement target.</param>
/// <param name="viewSettings">The optional dialog settings.</param>
public void ShowFlyout(object rootModel, UIElement placementTarget, IDictionary<string, object> viewSettings = null) {
var view = ViewLocator.LocateForModel(rootModel, null, null);
ViewModelBinder.Bind(rootModel, view, null);
var flyout = new Flyout
{
Content = view,
PlacementTarget = placementTarget,
};
ApplySettings(flyout, viewSettings);
flyout.IsOpen = true;
var deactivator = rootModel as IDeactivate;
if (deactivator != null) {
EventHandler<object> closed = null;
closed = (s, e) => {
deactivator.Deactivate(true);
flyout.Closed -= closed;
};
flyout.Closed += closed;
}
var activator = rootModel as IActivate;
if (activator != null) {
activator.Activate();
}
}
示例4: ManipulationInputProcessor
public ManipulationInputProcessor(Windows.UI.Input.GestureRecognizer gr, Windows.UI.Xaml.UIElement target, Windows.UI.Xaml.UIElement referenceframe)
{
this.gestureRecognizer = gr;
this.element = target;
this.reference = referenceframe;
this.gestureRecognizer.GestureSettings =
Windows.UI.Input.GestureSettings.Tap |
Windows.UI.Input.GestureSettings.Hold | //hold must be set in order to recognize the press & hold gesture
Windows.UI.Input.GestureSettings.RightTap |
Windows.UI.Input.GestureSettings.ManipulationTranslateX |
Windows.UI.Input.GestureSettings.ManipulationTranslateY |
Windows.UI.Input.GestureSettings.ManipulationRotate |
Windows.UI.Input.GestureSettings.ManipulationScale |
Windows.UI.Input.GestureSettings.ManipulationTranslateInertia |
Windows.UI.Input.GestureSettings.ManipulationRotateInertia |
Windows.UI.Input.GestureSettings.ManipulationMultipleFingerPanning | //reduces zoom jitter when panning with multiple fingers
Windows.UI.Input.GestureSettings.ManipulationScaleInertia;
// Set up pointer event handlers. These receive input events that are used by the gesture recognizer.
this.element.PointerCanceled += OnPointerCanceled;
this.element.PointerPressed += OnPointerPressed;
this.element.PointerReleased += OnPointerReleased;
this.element.PointerMoved += OnPointerMoved;
// Set up event handlers to respond to gesture recognizer output
this.gestureRecognizer.Tapped += OnTapped;
this.gestureRecognizer.RightTapped += OnRightTapped;
this.gestureRecognizer.ManipulationStarted += OnManipulationStarted;
this.gestureRecognizer.ManipulationUpdated += OnManipulationUpdated;
this.gestureRecognizer.ManipulationCompleted += OnManipulationCompleted;
InitializeTransforms();
}
示例5: CaptureAndSave
async System.Threading.Tasks.Task<Windows.Storage.StorageFile> CaptureAndSave(UIElement element)
{
// capture
var bitmap = new Windows.UI.Xaml.Media.Imaging.RenderTargetBitmap();
await bitmap.RenderAsync(element);
var picker = new Windows.Storage.Pickers.FileSavePicker
{
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary,
FileTypeChoices = { { "JPEG", new[] { ".jpg" } } },
SuggestedFileName = "Image",
DefaultFileExtension = ".jpg",
CommitButtonText = "Save",
};
// save
var file = await picker.PickSaveFileAsync();
using (var stream = await file.OpenStreamForWriteAsync())
{
var pixel = await bitmap.GetPixelsAsync();
var dpi = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi;
var random = stream.AsRandomAccessStream();
var jpg = Windows.Graphics.Imaging.BitmapEncoder.JpegEncoderId;
var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(jpg, random);
var format = Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8;
var alpha = Windows.Graphics.Imaging.BitmapAlphaMode.Ignore;
var width = (uint)bitmap.PixelWidth;
var height = (uint)bitmap.PixelHeight;
encoder.SetPixelData(format, alpha, width, height, dpi, dpi, pixel.ToArray());
await encoder.FlushAsync();
}
return file;
}
示例6: RenderToBase64
public async Task<string> RenderToBase64(UIElement element)
{
RenderTargetBitmap rtb = new RenderTargetBitmap();
await rtb.RenderAsync(element);
var pixelBuffer = await rtb.GetPixelsAsync();
var pixels = pixelBuffer.ToArray();
// Useful for rendering in the correct DPI
var displayInformation = DisplayInformation.GetForCurrentView();
var stream = new InMemoryRandomAccessStream();
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
encoder.SetPixelData(BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied,
(uint)rtb.PixelWidth,
(uint)rtb.PixelHeight,
displayInformation.RawDpiX,
displayInformation.RawDpiY,
pixels);
await encoder.FlushAsync();
stream.Seek(0);
// read bytes
var bytes = new byte[stream.Size];
await stream.AsStream().ReadAsync(bytes, 0, bytes.Length);
// create base64
return Convert.ToBase64String(bytes);
}
示例7: RunIfSelected
private void RunIfSelected(UIElement element, Action action)
{
if (ChartsList.SelectedItem == element)
{
action.Invoke();
}
}
示例8: AdnGestureManager
public AdnGestureManager(
UIElement window,
AdnRenderer renderer)
{
_window = window;
_renderer = renderer;
_pointerMode = PointerMode.kIdleMode;
_accumulator = new ValueAccumulator(
-30.0 * 1000.0 / 5.0,
-100.0 * 1000.0 / 5.0,
-5.0 * 1000.0 / 5.0);
_pointers = new Dictionary<uint, PointerPoint>();
window.PointerMoved += OnPointerMoved;
window.PointerPressed += OnPointerPressed;
window.PointerReleased += OnPointerReleased;
window.PointerWheelChanged += OnPointerWheelChanged;
_gr = new GestureRecognizer();
_gr.GestureSettings =
GestureSettings.Tap |
GestureSettings.Drag |
GestureSettings.DoubleTap |
GestureSettings.ManipulationScale;
_gr.Tapped += OnTapped;
_gr.ManipulationStarted += OnManipulationStarted;
_gr.ManipulationUpdated += OnManipulationUpdated;
_gr.ManipulationCompleted += OnManipulationCompleted;
}
示例9: ShowMessage
// Unused and untested
public static void ShowMessage(string message, UIElement placementTarget, PlacementMode placementMode=PlacementMode.Top)
{
var f = new Callisto.Controls.Flyout();
var b = new Border()
{
Width = 300,
Height = 125
};
TextBlock tb = new TextBlock();
tb.HorizontalAlignment = HorizontalAlignment.Center;
tb.VerticalAlignment = VerticalAlignment.Center;
tb.TextWrapping = TextWrapping.Wrap;
tb.FontSize = 12f;
tb.Text = message;
b.Child = tb;
f.Content = b;
f.Placement = placementMode;
f.PlacementTarget = placementTarget;
f.IsOpen = true;
}
示例10: Initialize
public void Initialize(UIElement host, CompositionImage sourceElement, object payload)
{
_host = host;
_parent = host;
_payload = payload;
// Make a copy of the sourceElement's sprite so we can hand it off to the next page
SpriteVisual sourceSprite = sourceElement.SpriteVisual;
Compositor compositor = sourceSprite.Compositor;
_sprite = compositor.CreateSpriteVisual();
_sprite.Size = sourceSprite.Size;
_sprite.Brush = sourceElement.SurfaceBrush;
// We're going to use the backing surface, make sure it doesn't get released
sourceElement.SharedSurface = true;
// Determine the offset from the host to the source element used in the transition
GeneralTransform coordinate = sourceElement.TransformToVisual(_parent);
Point position = coordinate.TransformPoint(new Point(0, 0));
// Set the sprite to that offset relative to the host
_sprite.Offset = new Vector3((float)position.X, (float)position.Y, 0);
// Set the sprite as the content under the host
ElementCompositionPreview.SetElementChildVisual(_parent, _sprite);
}
示例11: SetPrintContent
public virtual void SetPrintContent(UIElement content)
{
if (content == null)
return;
PrintContent = content;
}
示例12: GetVisual
public static ContainerVisual GetVisual(UIElement element)
{
var hostVisual = ElementCompositionPreview.GetElementVisual(element);
ContainerVisual root = hostVisual.Compositor.CreateContainerVisual();
ElementCompositionPreview.SetElementChildVisual(element, root);
return root;
}
示例13: SetUpDeviceScenarios
/// <summary>
/// Displays the compatible scenarios and hides the non-compatible ones.
/// If there are no supported devices, the scenarioContainer will be hidden and an error message
/// will be displayed.
/// </summary>
/// <param name="scenarios">The key is the device type that the value, scenario, supports.</param>
/// <param name="scenarioContainer">The container that encompasses all the scenarios that are specific to devices</param>
public static void SetUpDeviceScenarios(Dictionary<DeviceType, UIElement> scenarios, UIElement scenarioContainer)
{
UIElement supportedScenario = null;
if (EventHandlerForDevice.Current.IsDeviceConnected)
{
foreach (KeyValuePair<DeviceType, UIElement> deviceScenario in scenarios)
{
// Enable the scenario if it's generic or the device type matches
if ((deviceScenario.Key == DeviceType.All)
|| (deviceScenario.Key == Utilities.GetDeviceType(EventHandlerForDevice.Current.Device)))
{
// Make the scenario visible in case other devices use the same scenario and collapsed it.
deviceScenario.Value.Visibility = Visibility.Visible;
supportedScenario = deviceScenario.Value;
}
else if (deviceScenario.Value != supportedScenario)
{
// Don't hide the scenario if it is supported by the current device and is shared by other devices
deviceScenario.Value.Visibility = Visibility.Collapsed;
}
}
}
if (supportedScenario == null)
{
// Hide the container so that common elements shared across scenarios are also hidden
scenarioContainer.Visibility = Visibility.Collapsed;
NotifyDeviceNotConnected();
}
}
示例14: Add
public virtual void Add(UIElement control)
{
int rows = _grid.RowDefinitions.Count;
_grid.RowDefinitions.Add(new RowDefinition());
var textBlock = new TextBlock
{
Text = ListItemPrefix,
Margin = new Thickness(0, 5, 0, 5),
HorizontalAlignment = HorizontalAlignment.Center
};
Grid.SetColumn(textBlock, 0);
Grid.SetRow(textBlock, rows);
_grid.Children.Add(textBlock);
if ((control is FrameworkElement) == false)
{
// UIElement can set column and row,
// so use a border.
var border = new Border
{
Child = control
};
control = border;
}
Grid.SetColumn((FrameworkElement)control, 1);
Grid.SetRow((FrameworkElement)control, rows);
_grid.Children.Add(control);
}
示例15: InputEvents
public InputEvents(CoreWindow window, UIElement inputElement, TouchQueue touchQueue)
{
_touchQueue = touchQueue;
// The key events are always tied to the window as those will
// only arrive here if some other control hasn't gotten it.
window.KeyDown += CoreWindow_KeyDown;
window.KeyUp += CoreWindow_KeyUp;
window.VisibilityChanged += CoreWindow_VisibilityChanged;
if (inputElement != null)
{
// If we have an input UIElement then we bind input events
// to it else we'll get events for overlapping XAML controls.
inputElement.PointerPressed += UIElement_PointerPressed;
inputElement.PointerReleased += UIElement_PointerReleased;
inputElement.PointerCanceled += UIElement_PointerReleased;
inputElement.PointerMoved += UIElement_PointerMoved;
inputElement.PointerWheelChanged += UIElement_PointerWheelChanged;
}
else
{
// If we only have a CoreWindow then use it for input events.
window.PointerPressed += CoreWindow_PointerPressed;
window.PointerReleased += CoreWindow_PointerReleased;
window.PointerMoved += CoreWindow_PointerMoved;
window.PointerWheelChanged += CoreWindow_PointerWheelChanged;
}
}