Applying style to Autosuggest box crashes the App: Cannot apply a Style with TargetType 'FormsCustomizableTextBox' to an object of type 'TextBox'

1

I have recently started developing an UWP application.

I have defined a style in my page resources like this:

<Style TargetType="AutoSuggestBox" x:Name="AutoSuggestBoxStyle">
            <Setter Property="FontFamily" Value="Segoe UI"/>
            <Setter Property="FontSize" Value="17"/>
            <Setter Property="FontWeight" Value="SemiLight"/>
            <Setter Property="BorderBrush" Value="Gray"/>
            <Setter Property="BorderThickness" Value="0.5"/>
            <Setter Property="PlaceholderText" Value="Type Here"/>
            <Setter Property="Margin" Value="0,10,0,0"/>
</Style>

Then I am using this style in the same page like:

<AutoSuggestBox Style="{StaticResource AutoSuggestBoxStyle}"
                Name="SchemeSuggestBox"
                QuerySubmitted="SchemeSuggestBox_QuerySubmitted"
                SuggestionChosen="SchemeSuggestBox_SuggestionChosen"
                TextChanged="SchemeSuggestBox_TextChanged"/>

Doing this however crashes the app with exception:

Exception = {"No installed components were detected. (Exception from HRESULT: 0x800F1000)"}

And message:

Message = "Cannot apply a Style with TargetType 'Xamarin.Forms.Platform.UWP.FormsCustomizableTextBox' to an object of type 'Windows.UI.Xaml.Controls.TextBox'."

If I remove the style from my AutoSuggestBox (The following line) the App works as expected:

Style="{StaticResource AutoSuggestBoxStyle}"

What gives? I am not applying this style to any TextBox at all.

I have already read the Official Docs on Autosuggest box (Turns out it isn't even inherited from TextBox class It does have a property as Siva Gopal described and BugFinder hinted. Apparently I was kind of an idiot to miss it).

Relevant discussion on Xamarin forum can be seen here.

c#
xaml
uwp
asked on Stack Overflow Dec 30, 2016 by NSNoob • edited Dec 30, 2016 by NSNoob

1 Answer

1

I think your style's TargetType should be: TextBox but not: AutoSuggestBox and need to apply it for TextBoxStyle on AutoSuggestBox:

Style:

<Style TargetType="TextBox" x:Name="AutoSuggestBoxStyle">
   ...
</Style>

Style Application:

<AutoSuggestBox TextBoxStyle={StaticResource AutoSuggestBoxStyle}>
   ...
</AutoSuggestBox>
answered on Stack Overflow Dec 30, 2016 by Siva Gopal

User contributions licensed under CC BY-SA 3.0