Skip to content

Commit 8361fb8

Browse files
Cursor fix (#2832)
Respects a cursor set from outside, otherwise falls back to the desired defaults
1 parent df940a8 commit 8361fb8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Globalization;
2+
using System.Windows.Data;
3+
using Cursor = System.Windows.Input.Cursor;
4+
5+
namespace MaterialDesignThemes.Wpf.Converters;
6+
7+
/// <summary>
8+
/// Value converter that uses the Cursor from the bound property if set, otherwise it returns the <see cref="FallbackCursor"/>.
9+
/// </summary>
10+
public sealed class CursorConverter : IValueConverter
11+
{
12+
public Cursor FallbackCursor { get; set; } = Cursors.Arrow;
13+
14+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value as Cursor ?? FallbackCursor;
15+
16+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
17+
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<converters:NotConverter x:Key="NotConverter" />
1717
<converters:MathConverter x:Key="MathMultiplyConverter" Operation="Multiply" />
1818
<converters:FloatingHintOffsetCalculationConverter x:Key="FloatingHintOffsetCalculationConverter" />
19+
<converters:CursorConverter x:Key="ArrowCursorConverter" FallbackCursor="Arrow" />
20+
<converters:CursorConverter x:Key="IBeamCursorConverter" FallbackCursor="IBeam" />
1921

2022
<Style
2123
x:Key="MaterialDesignCharacterCounterTextBlock"
@@ -57,7 +59,6 @@
5759
<Setter Property="VerticalContentAlignment" Value="Stretch" />
5860
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
5961
<Setter Property="AllowDrop" Value="true" />
60-
<Setter Property="Cursor" Value="Arrow" />
6162
<Setter Property="Padding" Value="{x:Static wpf:Constants.TextBoxDefaultPadding}" />
6263
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
6364
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
@@ -74,7 +75,7 @@
7475
<Setter Property="Template">
7576
<Setter.Value>
7677
<ControlTemplate TargetType="{x:Type TextBoxBase}">
77-
<Grid>
78+
<Grid Cursor="{TemplateBinding Cursor, Converter={StaticResource ArrowCursorConverter}}">
7879
<Border
7980
HorizontalAlignment="Stretch"
8081
VerticalAlignment="Stretch"
@@ -148,7 +149,7 @@
148149
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
149150
Panel.ZIndex="1"
150151
wpf:ScrollViewerAssist.IgnorePadding="True"
151-
Cursor="IBeam"
152+
Cursor="{TemplateBinding Cursor, Converter={StaticResource IBeamCursorConverter}}"
152153
Focusable="false"
153154
HorizontalScrollBarVisibility="Hidden"
154155
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"

0 commit comments

Comments
 (0)