Might be a bug : embedded X set does not work in constructor

Gauge for WPF Forum

Posted 13 years ago by 7Alpha7
When you want to dynamically set the positioning of an embedded TextBlock in a Gauge, it does not work if you do it on the constructor.

Step to reproduce :

create a control like this :

<UserControl x:Class="Gauge.DigitalGauge"
    Height="170" Width="348" xmlns:gauge="http://schemas.actiprosoftware.com/winfx/xaml/gauge" Background="Transparent">
    <gauge:DigitalGauge x:Name="gauge" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Value="200"
                            CharacterCount="10" Foreground="Cyan" Background="Black" CharacterPadding="10,0" BackgroundType="RoundedRectangleLightGradient"
                        RimType="RoundedRectangleLightGradient" CharacterType="DotMatrix5By7Rectangle">
            <TextBlock x:Name="textBlock" gauge:DigitalGauge.X="0" gauge:DigitalGauge.Y="0" Text="Hello !"
                                    FontFamily="Courier New" Foreground="WhiteSmoke" FontSize="20" />

Add a code behind this way :

namespace Gauge {
    /// <summary>
    /// Logique d'interaction pour DigitalGauge.xaml
    /// </summary>
    public partial class DigitalGauge : UserControl {
        public DigitalGauge() {

        public void setTextX(){
            textBlock.SetValue(ActiproSoftware.Windows.Controls.Gauge.DigitalGauge.XProperty, ActiproSoftware.Windows.Unit.Percentage(-50));
insert the control in a windows form this way :

namespace Gauge {
    public class MainForm : Form {

        public MainForm() {
            //need to resize the form to see positioning

        ElementHost elementHost1 = new ElementHost();
        DigitalGauge digitalGauge1 = new DigitalGauge();

        protected override void OnCreateControl() {
            //here it works immediately

        private void InitializeComponent() {
            this.elementHost1 = new System.Windows.Forms.Integration.ElementHost();
            this.digitalGauge1 = new Gauge.DigitalGauge();
            // elementHost1
            this.elementHost1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.elementHost1.Location = new System.Drawing.Point(0, 0);
            this.elementHost1.Name = "elementHost1";
            this.elementHost1.Size = new System.Drawing.Size(275, 200);
            this.elementHost1.TabIndex = 0;
            this.elementHost1.Text = "elementHost";
            this.elementHost1.Child = this.digitalGauge1;
            // MainForm
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(275, 200);
            this.Name = "MainForm";
            this.Text = "Form1";

You need to resize the Form to see the textBlock positioning correctly.
If the setTextX() metho is called in OnCreateControl() for example, it works immedialtely.

This is ennoying because I need to set the X dependency property of the embedded textBlock before the Gauge control display, say in the moment of its creation (because it's a property set at design time)

I don't know if the same thing occur in WPF window.

[Modified at 01/18/2011 08:30 AM]

Comments (2)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
This appears to be a timing issue. When our DigitGauge is measured/arrange the basis for the percentage values is still "0,0". Since -50% of 0 is 0, it appears as if the value wasn't set. I've updated the code to correct this issue. This will be included in the next maintenance release, but in the meantime you can add the following code to your WPF UserControl (just after InitializeComponent):
this.gauge.SizeChanged += (s, e) => { this.gauge.InvalidateArrange(); };

Actipro Software Support

Posted 13 years ago by 7Alpha7
Ok thank you for your reply. I tried your piece of code and it works.
The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.