Programmatically setting X and Y of an embedded TextBlock

Gauge for WPF Forum

Posted 13 years ago by 7Alpha7
Avatar
Hi,

sorry for this stupid question but I am a neewbie on WPF and I cannot figure out how to set the X and Y dependency properties of an embedded TextBloc in a Gauge.

For example if I have something like :

<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">
        <gauge:DigitalGauge.Items>
            <TextBlock x:Name="textBlock" gauge:DigitalGauge.X="0" gauge:DigitalGauge.Y="0" Text="Hello"
                                    FontFamily="Courier New" Foreground="WhiteSmoke" FontSize="20" />
        </gauge:DigitalGauge.Items>

    </gauge:DigitalGauge>
How can I set the TextBlock DigitalGauge.X and DigitalGauge.Y properties in the code behind ?

I tried something like
textBlock.GetValue(gauge.X)
but it said that gauge.X is not a dependency property, and something static like DigitalGauge.X does not exists...

Thank you.

[Modified at 01/16/2011 11:59 AM]

Comments (5)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

gauge.X is a CLR property wrapper for a DependencyProperty named XProperty. When referring to DependencyProperty(s), you need to use the class name that has the property, not the instance name. The syntax should read something like this:

textBlock.SetValue(DigitalGauge.XProperty, new Unit(100));

Please let us know if you have further questions.


Actipro Software Support

Posted 13 years ago by 7Alpha7
Avatar
Thank you for your reply,

unfortunately I have tried already this piece of code and the compiler says something like : "DigitalGauge has no definition for XProperty"

ActiproSoftware.Gauge.Wpf351.dll version 10.2.531.0
Posted 13 years ago by 7Alpha7
Avatar
ok, sorry, I have called my UserControl DigitalGauge also and I was trying to find the XProperty on it. I just have to qualifiate the rigth type... ActiproSoftware.Windows.Controls.Gauge.DigitalGauge
Posted 13 years ago by 7Alpha7
Avatar
Well, I have still troubles with that. In design mode it works; I have a DigitalGauge that I use in a application hosting the Form designer. Once I change the X and Y properties in my app design mode, calling behind the Set / GetValue stuff, it works and I can see the label moving. But at runtime, when I instantiate the DigitalGauge with the specific X and Y such designed, the label remains centered.

I have to say that I have already seen troubles with the label positionning, even though it was only set in the xml file (before I wanted to add the X and Y design abilities). Its works well in Visual Studio design mode but as soon as I run the code, the textBlock does not remains at the expected place.

(I must add that I use the gauge through windows form interop for visualization, but I cannot see why it would make any difference)
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I see you posted a separate questionon this issue, so I'll address it there.


Actipro Software Support

The latest build of this product (v24.1.1) 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.