Search code examples
uwpresponsivetogglebuttonword-wrap

How to wrap the text in the Header field of a ToggleSwitch in UWP


I have a ToggleSwitch on the settings page of a UWP app, and I noticed that the Header text for the ToggleSwitch does not have a way to wrap it. When I test the app in the phone emulator, the Header goes right off the page. Any idea how I could make the text wrap like you can with a TextBlock?

<StackPanel Margin="10,0">
    <ToggleSwitch Name="toggleOne" Header="Check this on if you want the app to automatically trigger the zombie apocalypse" Margin="10" />
    <ToggleSwitch Name="toggleTwo" Header="Short Sample Text" Margin="10" />
</StackPanel>

Solution

  • You can add a HeaderTemplate for the ToggleSwitch like this:

            <ToggleSwitch
                Name="toggleOne"
                Margin="10"
                Header="Check this on if you want the app to automatically trigger the zombie apocalypse">
                <ToggleSwitch.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" TextWrapping="Wrap" />
                    </DataTemplate>
                </ToggleSwitch.HeaderTemplate>
            </ToggleSwitch>