adorner

Hiding validation adornment when hiding a control

好久不见. 提交于 2020-01-03 17:37:28
问题 How, in WPF, do you hide the validation error template adornment (red box by default) when you hide a control? When I hide my controls (to facilitate switching between views) the error adornment sticks around. Even more difficult, how do I do this using MVVM? 回答1: The default ControlTemplate for the Validation.ErrorTemplate has an AdornedElementPlaceholder which in turn has a reference to its AdornedElement . It looks like this <ControlTemplate> <Border BorderBrush="Red" BorderThickness="1">

GetAdornerLayer mysteriously returning null

青春壹個敷衍的年華 提交于 2019-12-30 08:11:51
问题 I've been using the same bit of code for several versions of my app with no problems, but I'm now mysteriously receiving NullRerefenceException s with the following: this.Loaded += delegate { deleteBrush = new DeleteBrushAdorner( background ); AdornerLayer al = AdornerLayer.GetAdornerLayer( background ); al.Add( deleteBrush ); // null ref here?? }; background is just a Border element. My two thoughts on what could be causing it are a) switching to .NET 4.0, and b) placing instances of the

GetAdornerLayer mysteriously returning null

醉酒当歌 提交于 2019-12-30 08:11:36
问题 I've been using the same bit of code for several versions of my app with no problems, but I'm now mysteriously receiving NullRerefenceException s with the following: this.Loaded += delegate { deleteBrush = new DeleteBrushAdorner( background ); AdornerLayer al = AdornerLayer.GetAdornerLayer( background ); al.Add( deleteBrush ); // null ref here?? }; background is just a Border element. My two thoughts on what could be causing it are a) switching to .NET 4.0, and b) placing instances of the

How to bind visibility property

▼魔方 西西 提交于 2019-12-25 18:34:08
问题 The XAML code is as follows: <Helper:BooleanVisibilityValueConverter x:Key="BoolToVisible" /> <Control x:Name="ResizeDecorator" MouseMove="ResizeDecorator_MouseMove" Template=" {StaticResource ResizeDecoratorTemplate}" Visibility="{Binding IsButtonVisible,Converter= {StaticResource ResourceKey=BoolToVisible},RelativeSource={RelativeSource TemplatedParent}}" /> <Helper:BooleanVisibilityValueConverter x:Key="BoolToVisible" /> <Control x:Name="ResizeDecorator" MouseMove="ResizeDecorator

Initial validation on dynamically added control

隐身守侯 提交于 2019-12-24 17:15:31
问题 WPF validation system performs intial validatation of an object (I mean - all fields are validated when a databound item is changed, and results are displayed on the ui). But it doesn't work like this, when I add a control dynamically. In such case inital validation happens, but results aren't shown on the ui. Only after some properties on a databound object change, everything starts working correctly. Here's a crude sample. Suppose we have MyObject class public class MyObject :

ToolTip on Adorner doesn't show up

那年仲夏 提交于 2019-12-23 01:19:42
问题 I have an adorner defined as follows: private class ErrorAdorner : Adorner { private readonly Border _errorBorder; public ErrorAdorner(UIElement adornedElement) : base(adornedElement) { _errorBorder = new Border(); _errorBorder.BorderThickness = new Thickness(2); _errorBorder.BorderBrush = Brushes.Red; Image img = new Image(); img.HorizontalAlignment = HorizontalAlignment.Right; img.VerticalAlignment = VerticalAlignment.Center; img.Stretch = Stretch.None; Binding imgBinding = new Binding {

Why does my adorner not re-render when the element it's applied to changes?

假装没事ソ 提交于 2019-12-20 09:48:43
问题 In a UI I'm building, I want to adorn a panel whenever one of the controls in the panel has the focus. So I handle the IsKeyboardFocusWithinChanged event, and add an adorner to the element when it gains the focus and remove the adorner when it loses focus. This seems to work OK. The problem I'm having is that the adorner isn't getting re-rendered if the bounds of the adorned element changes. For instance, in this simple case: <WrapPanel Orientation="Horizontal" IsKeyboardFocusChanged="Panel

How to refresh / update the wpf window after adorner has been added / enabled

大兔子大兔子 提交于 2019-12-13 17:35:39
问题 I am having some troubles with the Adorner of WPF. My adorner is ok, but I don't get it displayed at the very moment I want to. I like to do something like: public void MyAction() { // property bound to the adorner VisibiltyProperty // I like the happen a refresh now // (code is wired correct, if I finish method here, the adorner is drawn) this.IsAdornerEnabled = true; try { ... doing some long lasting things I cannot do async cause it depends on a lot of objects owned by main thread... }

How do I get the size of the visible part of a WPF usercontrol?

一曲冷凌霜 提交于 2019-12-12 13:13:41
问题 I have a usercontrol that consists of a label and a textbox. It's inside a scrollviewer. I'm drawing an adorner on top of it and I need to adjust the size of the adorner to the visible size of the control. How do I get the visible size of the control? In the image below the green rectangle is the adorner. As you can see it's being drawn over the scrollbar on the right side. Is it possible to get the size of the rendered part or will I have to manually go trough the visual tree and calculate

Copy UI element with adorner

淺唱寂寞╮ 提交于 2019-12-12 11:00:48
问题 I am working on taking screenshot of UI Element (WPF) in various size and i'm able to achieve this using "RenderTargetBitmap. But the UIElement which has an Adorner part is not coming while take copy. What should i do to achieve this. Any reference or code snippet? 回答1: As far as I know, elements don't have direct references to their adorners. Adorners do reference their element through AdornedElement though, so you could search for adorners assigned to your element like this: var layer =