Skip to content

Commit

Permalink
Fixing so the hack is no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Keboo committed Jan 10, 2025
1 parent 8de7db7 commit 31e3840
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
16 changes: 1 addition & 15 deletions src/MainDemo.Wpf/SmartHint.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,6 @@
Opacity="{TemplateBinding wpf:HintAssist.HintOpacity}"
Visibility="{TemplateBinding wpf:TextFieldAssist.HasLeadingIcon, Converter={x:Static converters:BooleanToVisibilityConverter.CollapsedInstance}}" />

<TextBlock x:Name="PrefixTextBlock"
Grid.Column="1"
Margin="0,0,2,0"
VerticalAlignment="Center"
FontSize="{TemplateBinding FontSize}"
Opacity="{TemplateBinding wpf:HintAssist.HintOpacity}"
Text="{TemplateBinding wpf:TextFieldAssist.PrefixText}">
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource PrefixSuffixTextVisibilityConverter}">
<Binding ElementName="Hint" Path="IsHintInFloatingPosition" />
<Binding Path="(wpf:TextFieldAssist.PrefixText)" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="(wpf:TextFieldAssist.PrefixTextVisibility)" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="IsKeyboardFocusWithin" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="IsReadOnly" RelativeSource="{RelativeSource TemplatedParent}" Converter="{x:Static converters:InvertBooleanConverter.Instance}" />
</MultiBinding>
</TextBlock.Visibility>
</TextBlock>

<ScrollViewer x:Name="PART_ContentHost"
Grid.Column="2"
HorizontalAlignment="Stretch"
Expand Down Expand Up @@ -237,6 +219,24 @@
</wpf:SmartHint.Hint>
</wpf:SmartHint>

<TextBlock x:Name="PrefixTextBlock"
Grid.Column="1"
Margin="0,0,2,0"
VerticalAlignment="Center"
FontSize="{TemplateBinding FontSize}"
Opacity="{TemplateBinding wpf:HintAssist.HintOpacity}"
Text="{TemplateBinding wpf:TextFieldAssist.PrefixText}">
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource PrefixSuffixTextVisibilityConverter}">
<Binding ElementName="Hint" Path="IsHintInFloatingPosition" />
<Binding Path="(wpf:TextFieldAssist.PrefixText)" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="(wpf:TextFieldAssist.PrefixTextVisibility)" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="IsKeyboardFocusWithin" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="IsReadOnly" RelativeSource="{RelativeSource TemplatedParent}" Converter="{x:Static converters:InvertBooleanConverter.Instance}" />
</MultiBinding>
</TextBlock.Visibility>
</TextBlock>

<TextBlock x:Name="SuffixTextBlock"
Grid.Column="3"
Margin="2,0,0,0"
Expand Down

0 comments on commit 31e3840

Please sign in to comment.