Merge pull request #464 from AvaloniaUI/watermark-support

Add watermark support
This commit is contained in:
Benedikt Stebner 2024-11-11 16:01:28 +01:00 коммит произвёл GitHub
Родитель f0db95ea29 64babb981a
Коммит d4a0d382ed
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 44 добавлений и 3 удалений

Просмотреть файл

@ -51,7 +51,8 @@
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Visible"
FontWeight="Light"
FontSize="14" >
FontSize="14"
Watermark="Start typing to bring your ideas to life...">
<AvalonEdit:TextEditor.ContextFlyout>
<MenuFlyout>
<MenuItem Header="Copy" InputGesture="ctrl+C" Command="{Binding CopyMouseCommmand}" CommandParameter="{Binding #Editor.TextArea}"></MenuItem>

Просмотреть файл

@ -142,6 +142,24 @@ namespace AvaloniaEdit.Editing
#endregion
#region Watermark
/// <summary>
/// Defines the <see cref="Watermark"/> property
/// </summary>
public static readonly StyledProperty<string> WatermarkProperty =
AvaloniaProperty.Register<TextArea, string>(nameof(Watermark));
/// <summary>
/// Gets or sets the placeholder or descriptive text that is displayed even if the <see cref="Text"/>
/// property is not yet set.
/// </summary>
public string Watermark
{
get => GetValue(WatermarkProperty);
set => SetValue(WatermarkProperty, value);
}
#endregion
/// <summary>
/// Defines the <see cref="IScrollable.Offset" /> property.
/// </summary>

Просмотреть файл

@ -20,8 +20,20 @@
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ContentPresenter Name="PART_CP" Cursor="IBeam"
Focusable="False" Background="{TemplateBinding Background}" />
<Panel>
<ContentPresenter Name="PART_CP"
Cursor="IBeam"
Focusable="False"
Background="{TemplateBinding Background}" />
<TextBlock Name="PART_Watermark"
Opacity="0.5"
Text="{TemplateBinding Watermark}"
Foreground="{TemplateBinding Foreground}">
<TextBlock.IsVisible>
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Document.Text" Converter="{x:Static StringConverters.IsNullOrEmpty}"/>
</TextBlock.IsVisible>
</TextBlock>
</Panel>
</DockPanel>
</ControlTemplate>
</Setter>

Просмотреть файл

@ -241,6 +241,16 @@ namespace AvaloniaEdit
#endregion
#region Text property
/// <summary>
/// Gets or sets the placeholder or descriptive text that is displayed even if the <see cref="Text"/>
/// property is not yet set.
/// </summary>
public string Watermark
{
get => textArea.Watermark;
set => textArea.Watermark = value;
}
/// <summary>
/// Gets/Sets the text of the current document.
/// </summary>