Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1585
Binding to Dependency Property of UserControl
posted

I have a UserControl that has a XamNumericEditor as a part of the Tree.

I am trying to set its binding value at runtime and add it dynamically to the children of a control.

This pattern works with TextBox, Button, ComboBox and some other controls. But I can't seem to get it to work with an Infragistic control. Nothing binds to it...but on all the other controls it works.

Please help!

Here is my simplified UserControl XAML

<UserControl x:Class="SilverlightApplication1.XText"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:ig="http://schemas.infragistics.com/xaml"         
    d:DesignHeight="300" d:DesignWidth="400">
    
    <Grid x:Name="LayoutRoot" Background="White">
        <ig:XamNumericEditor Name="MyNumericEditor"/>
        

    </Grid>
</UserControl>


Here is my code behind

public partial class XText : UserControl
    {
        public XText()
        {
            InitializeComponent();
            MyNumericEditor.SetBinding(XamNumericEditor.ValueProperty,
                new Binding()
                {
                    Source = this,
                    Path = new PropertyPath("MyText"),
                    Mode = BindingMode.TwoWay
                });
        }

        public double MyText
        {
            get { return (double)GetValue(MyTextProperty); }
            set { SetValue(MyTextProperty, value); }
        }

        public static readonly DependencyProperty MyTextProperty =
            DependencyProperty.Register(
            "MyText"typeof(double), typeof(XText),
new PropertyMetadata(null));
}

And when I want to use it

string s = 
@"<uc:XText MyText=""{Binding Path="
 + path + @", Mode=TwoWay}""/>";






 

Parents Reply Children