guorg / gu.wpf.adorners Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hello,
I'm currently using v2.1.1 installed via NuGet using Visual Studio Community 2019 (v16.9.3) in a WPF C# MVVM project (.NET Framework 4.7.2).
Project compiles as expected, but IntelliSense complains all the time about attachable properties not being found ("Text"
and "VisibleWhen"
).
XAML code:
<UserControl x:Class="ardacam.Views.EditorSQL"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:adorners="http://gu.se/Adorners"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<GroupBox x:Name="GrupoBDs" Header="Bancos de Dados" HorizontalAlignment="Left" Height="55" Margin="0,10,0,0" VerticalAlignment="Top" Width="143">
<ComboBox x:Name="comboBDs" HorizontalAlignment="Left" Height="23" Margin="7,7,0,0" VerticalAlignment="Top" Width="120" adorners:Watermark.Text="Selecione" adorners:Watermark.VisibleWhen="Empty">
</ComboBox>
</GroupBox>
<GroupBox x:Name="GrupoQuery" Header="Consulta SQL" HorizontalAlignment="Left" Height="181" Margin="0,70,0,0" VerticalAlignment="Top" Width="790">
<TextBox x:Name="InstrucaoSQL" HorizontalAlignment="Left" Margin="0,0,-2,7" TextWrapping="Wrap" AcceptsReturn="True" Text="" Width="780" Height="141" VerticalAlignment="Bottom"
adorners:Watermark.Text="It was a dark and stormy night. Watch your words..." adorners:Watermark.VisibleWhen="Empty" FontFamily="Courier New"/>
</GroupBox>
<GroupBox x:Name="GrupoConexaoManual" Header="Conexão Manual" HorizontalAlignment="Left" Height="55" Margin="148,10,0,0" VerticalAlignment="Top" Width="642">
<Grid HorizontalAlignment="Left" Height="29" Margin="0,5,-2,-2" VerticalAlignment="Top" Width="632">
<ComboBox x:Name="comboDriver" HorizontalAlignment="Left" Height="23" Margin="0,2,0,0" VerticalAlignment="Top" Width="62"
adorners:Watermark.Text="Driver" adorners:Watermark.VisibleWhen="Empty">
<ComboBoxItem Content="Oracle" HorizontalAlignment="Left" Width="123"/>
<ComboBoxItem Content="SQL Server" HorizontalAlignment="Left" Width="123"/>
<ComboBoxItem Content="PostgreSQL" HorizontalAlignment="Left" Width="123"/>
<ComboBoxItem Content="MySQL" HorizontalAlignment="Left" Width="123"/>
<ComboBoxItem Content="Firebird" HorizontalAlignment="Left" Width="123"/>
<ComboBoxItem Content="InterSystems Caché" HorizontalAlignment="Left" Width="123"/>
</ComboBox>
<TextBox x:Name="Host" HorizontalAlignment="Left" Height="24" Margin="65,1,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="101"
adorners:Watermark.Text="Host" adorners:Watermark.VisibleWhen="Empty"/>
<TextBox x:Name="Porta" HorizontalAlignment="Left" Height="24" Margin="169,1,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="42" MaxLength="5"
adorners:Watermark.Text="Porta" adorners:Watermark.VisibleWhen="Empty" PreviewTextInput="ValidacaoInteiroTextBox" DataObject.Pasting="PastingHandler"/>
<TextBox x:Name="Instancia" HorizontalAlignment="Left" Height="24" Margin="214,1,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="94"
adorners:Watermark.Text="Instância" adorners:Watermark.VisibleWhen="Empty"/>
<TextBox x:Name="Usuario" HorizontalAlignment="Left" Height="24" Margin="311,1,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="80"
adorners:Watermark.Text="Usuário" adorners:Watermark.VisibleWhen="Empty"/>
<PasswordBox x:Name="Senha" HorizontalAlignment="Left" Height="24" Margin="396,1,0,0" VerticalAlignment="Top" Width="80"
adorners:Watermark.Text="Senha" adorners:Watermark.VisibleWhen="Empty"/>
</Grid>
</GroupBox>
<GroupBox x:Name="GrupoResult" Header="Resultset" HorizontalAlignment="Left" Height="184" Margin="0,256,0,0" VerticalAlignment="Top" Width="790"/>
</Grid>
</UserControl>
Error Code: XLS0415
, 16 error occurrences in the aforementioned XAML code.
What I've tried to do to no avail:
Is there anything else that can be done?
Thanks.
plz how i can control the zindex of the adorners, placeholder
Looks off, no time to check now.
I downloaded the latest version, and inserted into a user control
<UserControl x:Class="Helen.Controls.PasswordBoxControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:adorners="http://gu.se/Adorners"
xmlns:local="clr-namespace:Helen.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<PasswordBox x:Name="passwordBox" PasswordChanged="PasswordBox_PasswordChanged" adorners:Watermark.Text="Password"/>
</UserControl>
And the Watermark does not appears in intellisense and it's mark like wrong.
This application it's write in .net core 3.1
It would be great if there was a way to set the Watermark to hidden if the control has InEnabled=False
.
A couple options would be to enable a public setter on Watermark.IsVisible
so it could be bound separately. Or add options to the VisibleWhen
enum.
Thanks
First of all: Great work, simple to use, does what it should. 👍
However I have a problem using a frame in a tabcontrol. On the second tab the adorner is only set if you focus the textbox.
Here is the sample:
Sample Repo:
https://github.com/Eun/GuWpfAdornersBug
Due to this we can't use àdornedElementPlaceHolder as it assumes it is in a TemplatedAdorner
which is internal.
This leaves us with a couple of options:
1 Use reflection to new up a TemplatedAdorner
.
2 Implement our own TemplatedAdorner
and AdornedElementPlaceholder
3 Something clever.
4 An entirely new API.
I wrote 2 to see how it looks:
<Button>
<adorners:Info.Template>
<ControlTemplate>
<Border Margin="-1"
BorderBrush="Red"
BorderThickness="1">
<adorners:AdornedElementPlaceholder />
</Border>
</ControlTemplate>
</adorners:Info.Template>
</Button>
I don't like that the caller must know that adorners:AdornedElementPlaceholder
must be used, pit of failure.
Rewrote to use reflection now, not sure if it should be included.
Can this be made to work with on a PasswordBox?
It looks like the events used in the overlay keep the UIElements referenced even once they are unloaded. Suggest something like this to fix:
private static void OnUnLoaded(object sender, RoutedEventArgs e)
{
UpdateIsShowing(sender as DependencyObject);
var element = sender as UIElement;
if (element != null)
{
element.RemoveHandler(FrameworkElement.SizeChangedEvent, new RoutedEventHandler(OnSizeChanged));
element.RemoveHandler(FrameworkElement.LoadedEvent, new RoutedEventHandler(OnLoaded));
element.RemoveHandler(FrameworkElement.UnloadedEvent, new RoutedEventHandler(OnUnLoaded));
element.RemoveHandler(Visible.IsVisibleChangedEvent, new RoutedEventHandler(OnIsVisibleChanged));
}
}
The crash log is below:
System.NullReferenceException: 未将对象引用设置到对象的实例。
在 MS.Internal.Controls.TemplatedAdorner.MeasureOverride(Size constraint)
在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在 System.Windows.UIElement.Measure(Size availableSize)
在 System.Windows.Documents.AdornerLayer.MeasureOverride(Size constraint)
在 System.Windows.FrameworkElement.MeasureCore(Size availableSize)
在 System.Windows.UIElement.Measure(Size availableSize)
在 System.Windows.ContextLayoutManager.UpdateLayout()
在 System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
在 System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
在 System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
在 System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
在 System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(Object resizedCompositionTarget)
在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
And I use adorners:Info for DataGridRow like below :
<DataGrid.RowStyle>
<Style BasedOn="{StaticResource DataGridRowDefault}" TargetType="DataGridRow">
<Setter Property="adorners:Info.IsVisible">
<Setter.Value>
<MultiBinding Converter="{StaticResource Equal2BoolConverter}">
<Binding
Mode="OneWay"
Path="DataContext"
RelativeSource="{RelativeSource Self}" />
<Binding
ElementName="PageRoot"
FallbackValue="{x:Null}"
Mode="OneWay"
Path="DataContext.CurrentLowestPriceSellOrder" />
</MultiBinding>
</Setter.Value>
</Setter>
<Setter Property="adorners:Info.Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border
HorizontalAlignment="Stretch"
BorderBrush="{DynamicResource PrimaryBrush3}"
BorderThickness="0,0,0,1">
<AdornedElementPlaceholder />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.RowStyle>
The DataGridRow Info.IsVisible is based on the equility of the row's DataContext and an ParentView's DataContext property(named CurrentLowestPriceSellOrder).
Because It doesn't happen very often, I wonder if there was a memory leak. Looking forward to your reply!
If i drag an element outside of the window of my WPF app, the adorner disappears. I've noticed some other apps are capable of maintaining the adorner.
Possible enhancement? This is relevant when you are dragging items between windows.
Could you implement support for the RichTextBox control?
The gray foreground works for me, but I need the text not to be italicized. How can I do this without declaring a new style, color and font?
Use Template & selector from style instead.
The adorner shows through slide-in panels - any way to stop this - have played around with a few things but the adorner still show through?
Perhaps you could shed some light on this or a work-around?
Thanks
Daniel
Having the following minimal code sample in a plain WPF window.
xmlns:adorn="http://gu.se/Adorners"
xmlns:geo="http://gu.se/Geometry"
...
<geo:Zoombox>
<Rectangle
Width="50"
Height="50"
Fill="Red">
<adorn:Overlay.Content>
<Border BorderBrush="Green" BorderThickness="10" />
</adorn:Overlay.Content>
</Rectangle>
</geo:Zoombox>
IsHitTestVisible="False"
solves that problem, but in some scenarios I cannot do that (for I need to handle some mouse events). Is there a way to have IsHitTestVisible="True"
and still forward the UI-events to the Zoombox so that I can do it's job?Reproduce:
Tab/shift Tab does work however.
Targetframework: 4.5
OS: Win 10 Pro, V1709 (Build 16299.309
VS2017
Improvement suggestion:
The watermark adorner looks great, however it seems like there is a limitation in terms of what it can display. I have a use-case where I want to show a magnifier glass symbol before the text "Search". In order to display the magnifier glass I need to be able to set the font family to Segoe MDL2 Assets. This does not appear possible in the current implementation. Do you like the idea of having a TextBlock property type here?
Here's how I do it with the current buggy watermark implementation I use:
<TextBox Text="{Binding Path=Foo}">
<uc:WatermarkService.Watermark>
<TextBlock>
<Run FontFamily="Segoe MDL2 Assets" Text="" />
<TextBlock Text="Search">
<TextBlock.RenderTransform>
<TranslateTransform Y="-1" />
</TextBlock.RenderTransform>
</TextBlock>
</TextBlock>
</uc:WatermarkService.Watermark>
</TextBox>
I downloaded this source code into Visual Studio 2019 and when compiling the source code hundreds of warning errors appeared and alot of compile errors
Is there something special I have to do to get this to compile
Watermark does not bind transparency with TextBox or PasswordBox
Maybe they need longer timeouts. Ideally we should find a way to make Gu.Wpf.UiAutomation solve this automatically.
Not sure is it correct behaviour, TextBox
is not visible itself
<TextBox Name="MyTextBox" adorners:Info.IsVisible="{Binding ElementName=MyTextBox, Path=IsFocused}">
<adorners:Info.Template>
<ControlTemplate>
<Border Padding="5" BorderThickness="1"
Background="Gray"
BorderBrush="LightGreen">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<AdornedElementPlaceholder />
<TextBlock Grid.Row="1" Text="Sample" />
</Grid>
</Border>
</ControlTemplate>
</adorners:Info.Template>
</TextBox>
Screen:
See #15
Nicest if we can just use Watermark
Hi, I've added addorner for TextBlock but it doesn't render. Do I have to use TextBox? I wasn't sure from the usage guide whether only TextBox, PasswordBox and ComboBox are supported, or whether it should work for any control. Thanks.
public Vector OffsetTo(Visual target)
And
public void SnapTo(Visual target)
I cannot bind .IsVisible
as described by the samples shown by Overlay and Info since IsVisible
is read-only.
<Rectangle
adorners:Info.IsVisible="True"
Results in the error message: Error MC3065 'Info.IsVisible' property is read-only and cannot be set from markup.
I believe they should be changed to .Visibility
as mentioned by the 2.0 breaking change.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.