|
| 1 | +--- |
| 2 | +title: Adding Custom Image as Content to SpeechToTextButton in UI for .NET MAUI |
| 3 | +description: Learn how to add a custom image as content to the SpeechToTextButton in UI for .NET MAUI. |
| 4 | +type: how-to |
| 5 | +page_title: Using Custom Image Content for SpeechToTextButton in .NET MAUI |
| 6 | +meta_title: Using Custom Image Content for SpeechToTextButton in .NET MAUI |
| 7 | +slug: custom-image-content-speechtotextbutton-maui |
| 8 | +tags: speechtotextbutton, ui-for-net-maui, content, image, button |
| 9 | +res_type: kb |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +| Version | Product | Author | |
| 15 | +| --- | --- | ---- | |
| 16 | +| 12.0.0 | Telerik UI for .NET MAUI SpeechToTextButton | [Dobrinka Yordanova](https://www.telerik.com/blogs/author/dobrinka-yordanova) | |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +I want to add a custom SVG image, such as a pause icon, as content to the [SpeechToTextButton](https://www.telerik.com/maui-ui/documentation/controls/speechtotextbutton/overview) in UI for .NET MAUI. Adding the image directly to the `Content` property doesn't work, as the property converts strings to labels instead of images. How can I achieve this? |
| 21 | + |
| 22 | +This knowledge base article also answers the following questions: |
| 23 | +- How to set an SVG image as the content of SpeechToTextButton? |
| 24 | +- How to customize the content of SpeechToTextButton using an image? |
| 25 | +- How to use a visual state to display an image in SpeechToTextButton? |
| 26 | + |
| 27 | +## Solution |
| 28 | + |
| 29 | +To set a custom image as the content of the SpeechToTextButton, define an `Image` resource and use it in a style for the button. Follow these steps: |
| 30 | + |
| 31 | +1. Define the image resource in your XAML code. |
| 32 | + |
| 33 | + ```xml |
| 34 | + <Image x:Key="MyContent" Source="pause_icon.svg" /> |
| 35 | + ``` |
| 36 | + |
| 37 | +2. Create a style for the SpeechToTextButton, specifying the `Content` property in the `VisualState.Setters`. |
| 38 | + |
| 39 | + ```xml |
| 40 | + <Style x:Key="SpeechToTextButtonStyle" TargetType="telerik:RadSpeechToTextButton"> |
| 41 | + <Setter Property="Padding" Value="12, 8" /> |
| 42 | + <Setter Property="CornerRadius" Value="12" /> |
| 43 | + <Setter Property="VerticalTextAlignment" Value="Center" /> |
| 44 | + <Setter Property="HorizontalTextAlignment" Value="Center" /> |
| 45 | + <Setter Property="TextColor" Value="#00897B" /> |
| 46 | + <Setter Property="BackgroundColor" Value="Transparent" /> |
| 47 | + <Setter Property="BorderBrush" Value="LightGray" /> |
| 48 | + <Setter Property="BorderThickness" Value="2" /> |
| 49 | + <Setter Property="VisualStateManager.VisualStateGroups"> |
| 50 | + <VisualStateGroupList> |
| 51 | + <VisualStateGroup Name="CommonStates"> |
| 52 | + <VisualState Name="Normal"> |
| 53 | + <VisualState.Setters> |
| 54 | + <Setter Property="telerik:RadSpeechToTextButton.Content" Value="{StaticResource MyContent}" /> |
| 55 | + </VisualState.Setters> |
| 56 | + </VisualState> |
| 57 | + <VisualState Name="Pressed"> |
| 58 | + <VisualState.Setters> |
| 59 | + <Setter Property="telerik:RadSpeechToTextButton.Content" Value="{StaticResource MyContent}" /> |
| 60 | + <Setter Property="telerik:RadSpeechToTextButton.TextColor" Value="#9900897B" /> |
| 61 | + <Setter Property="telerik:RadSpeechToTextButton.BackgroundColor" Value="#E8F5F4" /> |
| 62 | + </VisualState.Setters> |
| 63 | + </VisualState> |
| 64 | + <VisualState Name="Listening"> |
| 65 | + <VisualState.Setters> |
| 66 | + <Setter Property="telerik:RadSpeechToTextButton.Content" Value="{StaticResource MyContent}" /> |
| 67 | + <Setter Property="telerik:RadSpeechToTextButton.TextColor" Value="#000000" /> |
| 68 | + <Setter Property="telerik:RadSpeechToTextButton.BackgroundColor" Value="#00897B" /> |
| 69 | + </VisualState.Setters> |
| 70 | + </VisualState> |
| 71 | + </VisualStateGroup> |
| 72 | + </VisualStateManager.VisualStateGroups> |
| 73 | + </Setter> |
| 74 | + </Style> |
| 75 | + ``` |
| 76 | + |
| 77 | +## See Also |
| 78 | + |
| 79 | +- [SpeechToTextButton Documentation](https://www.telerik.com/maui-ui/documentation/controls/speechtotextbutton/overview) |
| 80 | +- [SpeechToTextButton Styling in .NET MAUI](https://www.telerik.com/maui-ui/documentation/controls/speechtotextbutton/styling) |
0 commit comments