ravi kumar
ravi kumar

Reputation: 1620

How to wrap controls in StackPanel?

My problem is similar to this question but the solutions require the use of DockPanel which is not available in UWP.

I have a CheckBox on the left and a StackPanel on the right. This StackPanel has two TextBlocks and a Hyperlink. I want to wrap the text in this StackPanel. I have also tried replacing this StackPanel with Grid but I can't figure it out. Here's the XAML:

<Grid Grid.Row="22"
    Grid.ColumnSpan="2">

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto"/>
    <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<CheckBox Grid.Column="0"/>
    <StackPanel Orientation="Horizontal"
                Grid.Column="1">

        <TextBlock Text="{x:Bind TermsViewModel.Terms1}"
                   TextWrapping="Wrap"/>
        <HyperlinkButton Content="{x:Bind Link}"
                         NavigateUri="someRandomUri"/>
        <TextBlock Text="{x:Bind TermsViewModel.Terms2}"
                   TextWrapping="Wrap"/>
    </StackPanel>
</Grid>

Upvotes: 0

Views: 763

Answers (1)

Vijay Nirmal
Vijay Nirmal

Reputation: 5837

To use Hyperlink in middle of a paragraph you don't want to use StackPanel.You just need TextBlock. Here is the code sample

<TextBlock TextWrapping="Wrap">
    <Run Text=""/>
    <Hyperlink NavigateUri="someRandomUri">
        <Run Text=""/>
    </Hyperlink>
    <Run Text=""/>
</TextBlock>

To learn more about Create a Hyperlink text element

Upvotes: 2

Related Questions