Posted 14 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 :Add a code behind this way :
insert the control in a windows form this way :
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]
Step to reproduce :
create a control like this :
<UserControl x:Class="Gauge.DigitalGauge"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
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">
<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>
</UserControl>
namespace Gauge {
/// <summary>
/// Logique d'interaction pour DigitalGauge.xaml
/// </summary>
public partial class DigitalGauge : UserControl {
public DigitalGauge() {
InitializeComponent();
}
public void setTextX(){
textBlock.SetValue(ActiproSoftware.Windows.Controls.Gauge.DigitalGauge.XProperty, ActiproSoftware.Windows.Unit.Percentage(-50));
}
}
}
namespace Gauge {
public class MainForm : Form {
public MainForm() {
InitializeComponent();
//need to resize the form to see positioning
((DigitalGauge)elementHost1.Child).setTextX();
}
ElementHost elementHost1 = new ElementHost();
DigitalGauge digitalGauge1 = new DigitalGauge();
protected override void OnCreateControl() {
base.OnCreateControl();
//here it works immediately
//((DigitalGauge)elementHost1.Child).setTextX();
}
private void InitializeComponent() {
this.elementHost1 = new System.Windows.Forms.Integration.ElementHost();
this.digitalGauge1 = new Gauge.DigitalGauge();
this.SuspendLayout();
//
// 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.Controls.Add(this.elementHost1);
this.Name = "MainForm";
this.Text = "Form1";
this.ResumeLayout(false);
}
}
}
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]