Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find resource named 'MaterialDesignCharacterCounterTextBlock'. #3613

Closed
jamesport079 opened this issue Jun 23, 2024 · 7 comments · Fixed by #3618
Closed

Cannot find resource named 'MaterialDesignCharacterCounterTextBlock'. #3613

jamesport079 opened this issue Jun 23, 2024 · 7 comments · Fixed by #3618
Labels
Milestone

Comments

@jamesport079
Copy link

Bug explanation

Application is crashing when I'm trying to use a style based on MaterialDesignCharacterCounterTextBlock. All worked well in 5.0 and below so I don't really know what is changed.

Exception: Cannot find resource named 'MaterialDesignCharacterCounterTextBlock'. Resource names are case sensitive.

I tried merging MaterialDesignTheme.TextBox.xaml but still getting the same error. Error only appeared after I updated to 5.1

This is my style based on MaterialDesignCharacterCounterTextBlock...

<Style
    x:Key="ShowCounterOnKeyboardFocus"
    BasedOn="{StaticResource MaterialDesignCharacterCounterTextBlock}"
    TargetType="{x:Type TextBlock}">
    <Setter Property="Height" Value="0" />
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource FindAncestor, AncestorType=TextBox}}" Value="True">
            <Setter Property="Height" Value="{x:Static sys:Double.NaN}" />
        </DataTrigger>
    </Style.Triggers>
</Style>

Version

5.1.0

@jamesport079 jamesport079 added bug evaluation required Items is pending review or evaluation by the team labels Jun 23, 2024
@MichelMichels
Copy link
Member

The style has been put inside the style MaterialDesignTextBoxBase, which in turn made it unaccessible like a local style. I don't know if this specifically was intended by this PR: #3461

@nicolaihenriksen can maybe answer this question better.

@jamesport079 for this moment, I'd write my own style with following content:

<Style x:Key="MaterialDesignCharacterCounterTextBlock"
             TargetType="TextBlock"
             BasedOn="{StaticResource {x:Type TextBlock}}">
        <Setter Property="FontSize" Value="10" />
        <Setter Property="Opacity" Value="0.56" />
        <Setter Property="Text">
          <Setter.Value>
            <MultiBinding StringFormat="{}{0} / {1}">
              <Binding Converter="{StaticResource StringLengthValueConverter}"
                       Path="Text"
                       RelativeSource="{RelativeSource FindAncestor,
                                                       AncestorType=TextBoxBase}" />
              <Binding Path="MaxLength" RelativeSource="{RelativeSource FindAncestor, AncestorType=TextBoxBase}" />
            </MultiBinding>
          </Setter.Value>
        </Setter>
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="Visibility" Value="{Binding Path=(wpf:TextFieldAssist.CharacterCounterVisibility), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TextBox}}}" />
      </Style>

@MichelMichels MichelMichels removed the evaluation required Items is pending review or evaluation by the team label Jun 24, 2024
@jamesport079
Copy link
Author

Thank you, @MichelMichels. I'll try that.

@nicolaihenriksen
Copy link
Contributor

@jamesport079 @MichelMichels It was actually an intended change to move all TextBox related resources into a resource collection under the TextBox itself, rather than having a ton of resources (e.g. converters, data templates, utility styles, etc.) available via the app-level ResourceDictionary.

So I did not actually consider it a use case that consumers wanted to base a custom style on this one, but I am not against moving that style back out to the outer-most ResourceDictionary which would allow the desired "inhertance". @Keboo thoughts?

@jamesport079
Copy link
Author

I'm using that particular style to make counter appear when the TextBox has Keyboard focus. I don't like it that I have a bunch of TextBoxes having the counters showing when they're not in focus. It just makes the UI unnecessarily cluttered. So yeah, ideally the Style remains accessible unless there is a neater solution.

@MichelMichels
Copy link
Member

A neater solution would be to implement such a setting, like ValidationAssist.OnlyShowOnFocus, but maybe on TextFieldAssist.OnlyShowCounterOnFocus.

@jamesport079
Copy link
Author

@MichelMichels yeah i thought about this way back. But not being able to access some styles in general irks me a little bit.

@MichelMichels
Copy link
Member

@jamesport079 I understand your sentiment, but the style only makes sense in the context of a TextBox control as it binds to several properties of the TextBox. So I also understand why @nicolaihenriksen changed this to a local style.

@nicolaihenriksen we could however revert the change and maybe propose the change for v6 as this seems to be a breaking change for @jamesport079 (and maybe other users)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants