From 30b8a6998d3514ea5f887312deb9f568aff4790e Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Thu, 9 Jan 2025 22:00:55 -0800 Subject: [PATCH] Fixing so the hack is no longer needed --- src/MainDemo.Wpf/SmartHint.xaml.cs | 16 +-------- .../Themes/MaterialDesignTheme.TextBox.xaml | 36 +++++++++---------- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/MainDemo.Wpf/SmartHint.xaml.cs b/src/MainDemo.Wpf/SmartHint.xaml.cs index 89e38e9643..bc0ead89be 100644 --- a/src/MainDemo.Wpf/SmartHint.xaml.cs +++ b/src/MainDemo.Wpf/SmartHint.xaml.cs @@ -17,24 +17,10 @@ public partial class SmartHint : UserControl internal static void SetRichTextBoxText(DependencyObject element, object value) => element.SetValue(RichTextBoxTextProperty, value); internal static object GetRichTextBoxText(DependencyObject element) => element.GetValue(RichTextBoxTextProperty); - private SmartHintViewModel ViewModel { get; } - public SmartHint() { - DataContext = ViewModel = new SmartHintViewModel(); + DataContext = new SmartHintViewModel(); InitializeComponent(); - - Loaded += SmartHint_Loaded; - } - - private void SmartHint_Loaded(object sender, RoutedEventArgs e) - { - // 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. - // 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. - // 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; - // that will place the hint on top of the prefix text for unknown reasons. - ViewModel.PrefixText = "Pre"; - ViewModel.SuffixText = "Suf"; } private void HasErrors_OnToggled(object sender, RoutedEventArgs e) diff --git a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml index a4503d464f..c48d5c87cc 100644 --- a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml +++ b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml @@ -151,24 +151,6 @@ Opacity="{TemplateBinding wpf:HintAssist.HintOpacity}" Visibility="{TemplateBinding wpf:TextFieldAssist.HasLeadingIcon, Converter={x:Static converters:BooleanToVisibilityConverter.CollapsedInstance}}" /> - - - - - - - - - - - - + + + + + + + + + + + +