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

  • Home
  • SEARCH
  • 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 8762053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:25:58+00:00 2026-06-13T15:25:58+00:00

Currently, I have the following XAML code which is able to achieve the following

  • 0

Currently, I have the following XAML code which is able to achieve the following effect.

enter image description here

<UserControl
    x:Class="FacionMetro.Gui.HealthIndicatorView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FacionMetro.Gui"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <StackPanel>
        <Grid>
            <TextBlock Name="message" FontSize="22" Text="120 is good" Margin="250,0,-250,0"/>
        </Grid>
        <Grid>
            <TextBlock Name="arrow" FontSize="22" Text="▼" Margin="350,0,-350,0" />
        </Grid>
        <Grid Height="200">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="8*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="1">
                    <Grid.Background >
                        <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                            <GradientStop Color="#ff00ff00"/>
                            <GradientStop Color="#ffffff00" Offset="0.25" />
                            <GradientStop Color="#ffffa500" Offset="0.75" />
                            <GradientStop Color="#ffff0000" Offset="1" />
                        </LinearGradientBrush>
                    </Grid.Background>
                </Grid>
            </Grid>
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0" FontSize="22" HorizontalAlignment="Center">40</TextBlock>
                <TextBlock Grid.Column="1" FontSize="22" HorizontalAlignment="Center">60</TextBlock>
                <TextBlock Grid.Column="3" FontSize="22" HorizontalAlignment="Center">100</TextBlock>
                <TextBlock Grid.Column="4" FontSize="22" HorizontalAlignment="Center">120</TextBlock>
            </Grid>
        </Grid>
    </StackPanel>
</UserControl>

I wish to move the x-position of the triangle arrow and message (?? is good) around dynamically, according to color bar current value.

enter image description here

My current code snippet is as below. It is not workable yet.

public sealed partial class HealthIndicatorView : UserControl
{
    public HealthIndicatorView()
    {
        this.InitializeComponent();
    }

    public void setValue(int value)
    {
        // Margin X. For both left and right sides.
        double offsetX = this.ActualWidth / 10;

        if (value < 40) {
            // I wish to move the message and arrow the left most. How?
            // The below code is having error :
            // Cannot modify the return value of 'Windows.UI.Xaml.FrameworkElement.Margin' because it is not a variable
            message.Margin.Left = offsetX;
            arrow.Margin.Left = offsetX;
            return;
        }

        if (value > 120) {
            // messageSize and arrowSize are incorrect. As the TextBlock isn't fit to the string content.
            double messageSize = message.Width;
            double arrowSize = arrow.Width;

            double rightMostPosForMessage = this.ActualWidth - offsetX - messageSize;
            double rightMostPosForArrow = this.ActualWidth - offsetX - arrowSize;

            // I wish to move the message and arrow the right most. How?
            // The below code is having error :
            // Cannot modify the return value of 'Windows.UI.Xaml.FrameworkElement.Margin' because it is not a variable
            message.Margin.Left = offsetX;
            arrow.Margin.Left = offsetX;
        }

    }
}
  1. How I can move the TextBlock around according to color bar value? (To know what does move around means, see the 2 different screenshot, when the color bar value is 40 and 120 respectively)
  2. How I can make TextBlock, to exactly fit to the string content? I need this, as I need to know the space occupied by string content, so that I will not move them out of bound. (As you can see in “120 is good” screenshot, TextBlock is occupying too much space although the string content is just a short message)
  • 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-13T15:25:59+00:00Added an answer on June 13, 2026 at 3:25 pm

    Move TextBlock around

    To move the TextBlock around, you need to define

    <StackPanel>
        <Grid>
            <TextBlock Name="message" FontSize="22" Text="120 is good">
                <TextBlock.RenderTransform>
                    <TranslateTransform x:Name="messageTransform" />
                </TextBlock.RenderTransform>
            </TextBlock>
        </Grid>
        ...
    

    Then in your C# code.

    messageTransform.X = offsetX;

    Fit to The String Content

    <Grid>
        <TextBlock Name="arrow" FontSize="22" Text="▼" HorizontalAlignment="Left">
            <TextBlock.RenderTransform>
                <TranslateTransform x:Name="arrowTransform" />
            </TextBlock.RenderTransform>                
        </TextBlock>
    </Grid>
    

    Use HorizontalAlignment="Left"

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

Sidebar

Related Questions

I currently have the following code which delays showing a fixed bar after a
I currently have the following CSS for my 4 columns which might grow to
I currently have a Combobox like the following: //XAML <ComboBox> <ComboBoxItem> Awake & Alive</ComboBoxItem>
I'm currently using the following XAML code to add my xml file as a
I have a custom UserControl that is defined by the following XAML: <Grid HorizontalAlignment=Left
I have the following test case xaml. <Window.Resources> <XmlDataProvider x:Key=testDS1> <x:XData> <root xmlns=> <item>1</item>
Why isn't my XAML following the TabOrder I specified? I currently have: <DockPanel> <Grid
I currently have the following: (defun my-hide-code () (interactive) (set-selective-display 2)) (defvar my-keys-minor-mode-map (make-keymap)
Currently I have following XML: <Rowsets> <Rowset> <Row> <DrilldownDepth>0</DrilldownDepth> <ScheduleWeek>---</ScheduleWeek> <ABC>---</ABC> <PQR>1500</PQR> <XYZ>15000</XYZ> <Quant>285</Quant>
I currently have the following controller method in a Rails app: def index @entries

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.