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 993101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:22:01+00:00 2026-05-16T06:22:01+00:00

There is an int property of the ‘CustomControl’ (in Silverlight 4 application), TextBlock is

  • 0

There is an int property of the ‘CustomControl’ (in Silverlight 4 application), TextBlock is displayed inside of the ‘Canvas’ control:

<Canvas Name="canvas" >
    <Ellipse Fill="Yellow" Canvas.Top="8" Canvas.Left="8" Height="16" Width="16">
    </Ellipse>
    <TextBlock Name="TeamNumberTextBlock" Text="9" Canvas.Top="8" Canvas.Left="8" TextAlignment="Center" FontStyle="Italic" />
</Canvas>

As text can be changed It should be centered. Here is a “CodeBehind-solution”:

public partial class FieldItem : UserControl
{
    public FieldItem()
    {
        InitializeComponent();
    }

    public int TeamNumber
    {
        private get
        {
            return _iTeamNumber;
        }
        set
        {
            _iTeamNumber = value;
            TeamNumberTextBlock.Text = _iTeamNumber.ToString();
            TeamNumberTextBlock.SetValue(Canvas.LeftProperty, (TeamNumberTextBlock.Width - TeamNumberTextBlock.Width) / 2);
        }
    }

    private int _iTeamNumber;
}

When somebody will set a new value to the control, its ‘Canvas.Left’ property will be recalculated.

Is it possible to implement similar functionality using binding (or any other mechanism that is workable in design mode)?

Thank you!

  • 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-05-16T06:22:02+00:00Added an answer on May 16, 2026 at 6:22 am

    A Canvas is probably not the ideal container for that kind of thing… you can achieve the same result with a Grid. You won’t have to recalculate the position, you just need to specify the HorizontalAlignment and VerticalAlignment and the TextBlock will remain centered automatically:

    <Grid>
        <Ellipse Fill="Yellow" Height="16" Width="16">
        </Ellipse>
        <TextBlock Name="TeamNumberTextBlock" Text="9"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   FontStyle="Italic" />
    </Grid>
    

    In a Grid, you can specify the row and column where an element is displayed. If there is only one row and one column (which is the default), all elements appear in the same “cell”. The last element added appears on top (unless you specify the Panel.ZIndex property to change the Z-order)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is struct like this. struct Address { int id; int set; char name[MAX_DATA];
Is there any way to set breakpoint on setter/getter in auto-implemented property? int Counter
Is there any way to use global int constants in Objective C that work
Is there any advantage of using int vs varbinary for storing bit masks in
Is there a way to convert an int to a bitmask? example: int i
Is there a way to declare an unsigned int in Java? Or the question
Is there an elegant way in java to check if an int is equal
Is there a function in c# that takes two 32 bit integers (int) and
is there an out-of-box way to spell out an int in C#? For example
Is there a way to improve this: private static int CountNewlines(string s) { int

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.