Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8388439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:28:23+00:00 2026-06-09T18:28:23+00:00

I’ve got a button (NOT created by xaml) for which I’m setting the content

  • 0

I’ve got a button (NOT created by xaml) for which I’m setting the content alignment like this:

btn.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;

but if the content is too long then the text is sliding to the right after a point in which you can’t see the text anymore.
the buttons are created inside panorama item 2 in this grid:

<Grid x:Name="LayoutRoot">
    <controls:Panorama Title="Title" SelectionChanged="Panorama_SelectionChanged" FontSize="20">

        <!--Panorama item one-->
        <controls:PanoramaItem Header="Wall" Margin="40,0,0,0" Name="PIWall">

        </controls:PanoramaItem>

        <!--Panorama item two-->
        <controls:PanoramaItem Header="Messages" Margin="30,0,0,0" Name="PIMail">

        </controls:PanoramaItem>

    </controls:Panorama>
</Grid>

The button and it’s settings are as follows:

HyperlinkButton btn = new HyperlinkButton();
        btn.Height = 89;
        btn.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
        btn.VerticalAlignment = System.Windows.VerticalAlignment.Top;
        btn.Margin = new Thickness(60, -70, 0, 0);
        btn.Width = 290;
        btn.Content = message;
        btn.FontSize = 22;
        btn.Visibility = System.Windows.Visibility.Visible;
        btn.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
        panel.Children.Add(btn);
        scrollViewer.Content = panel;
        PIMail.Content = mailscrollViewer;

How can i make the text not slide over the grid margins?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:28:25+00:00Added an answer on June 9, 2026 at 6:28 pm

    OK, to wrap text inside a button, you could use XAML like this:

    <Button Width="200" Height="200">
        <Button.Content>
            <TextBlock TextWrapping="Wrap" Text="This is a long text that fits into button"/>
        </Button.Content>
    </Button>
    

    In order to accomplish this in code, you could do the following:

    Button btn = new Button();
    btn.Height = 200;
    btn.Width = 300;
    TextBlock txt = new TextBlock();
    txt.TextWrapping = TextWrapping.Wrap;
    txt.Text = "A huge amount of text that will fill the button";
    btn.Content = txt;
    ContentPanel.Children.Add(btn);
    

    ContentPanel is a simple grid.

    EDIT: Modified post for HyperlinkButton

    In order to enable text wrapping in hyperlink button you need to edit the style of the hyperlink button. Define it like this in the App.xaml file:

        <Style x:Key="HyperlinkButtonStyle" TargetType="HyperlinkButton">
            <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="HyperlinkButton">
                        <Border Background="Transparent">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver"/>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="TextElement"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="TextElement">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border Background="{TemplateBinding Background}" Margin="{StaticResource PhoneHorizontalMargin}" Padding="{TemplateBinding Padding}">
                                <TextBlock x:Name="TextElement" TextWrapping="Wrap" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Text="{TemplateBinding Content}" TextDecorations="Underline" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </Border>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    

    The important change is that the TextBlock now contains the TextWrapping property set to “Wrap”.

    Then use the button like you normally do, just don’t forget to set the styling:

    var btn = new HyperlinkButton();
    btn.Height = 200;
    btn.Width = 300;
    btn.NavigateUri = new Uri("http://bing.com", UriKind.Absolute);
    btn.TargetName = "_blank";
    btn.Style = Application.Current.Resources["HyperlinkButtonStyle"] as Style;
    btn.Content = "This is a huge amount of text that will be in the hyperlink button";
    ContentPanel.Children.Add(btn);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.