Skip to content

Commit 97d2cb5

Browse files
Demo app workaround/hack for initial miscalculation of hint placement
1 parent aca6b24 commit 97d2cb5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/MainDemo.Wpf/SmartHint.xaml.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,24 @@ public partial class SmartHint : UserControl
1717
internal static void SetRichTextBoxText(DependencyObject element, object value) => element.SetValue(RichTextBoxTextProperty, value);
1818
internal static object GetRichTextBoxText(DependencyObject element) => element.GetValue(RichTextBoxTextProperty);
1919

20+
private SmartHintViewModel ViewModel { get; }
21+
2022
public SmartHint()
2123
{
22-
DataContext = new SmartHintViewModel();
24+
DataContext = ViewModel = new SmartHintViewModel();
2325
InitializeComponent();
26+
27+
Loaded += SmartHint_Loaded;
28+
}
29+
30+
private void SmartHint_Loaded(object sender, RoutedEventArgs e)
31+
{
32+
// HACK! For some strange reason, the calculation of the left margin for the hint is initially wrong if these values are set as default in the view model directly.
33+
// Setting them here is a bit hacky, but it makes the demo page work, and I don't think this would be an issue in a real world application so I can live the hack.
34+
// To see the issue in action: Simply comment out the 2 lines below, open the "Smart Hint" page and toggle the "IsReadOnly" checkbox in the "TextBox styles" section;
35+
// that will place the hint on top of the prefix text for unknown reasons.
36+
ViewModel.PrefixText = "Pre";
37+
ViewModel.SuffixText = "Suf";
2438
}
2539

2640
private void HasErrors_OnToggled(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)