Linking the "Text-Property" of a derived text field to another text field does not work

I have a MyTextBox class that comes from the default text field in Silverlight. This class does not currently contain additional code.

I set the binding in xaml to bind the Text-Property of MyTextbox to another text box to reflect the input made in the text box. The effect is that MyTextBox does not update or display the text of another text field.

Additionally, I made equal binding for a regular text field. And it works.

Here is the XAML for bindings.

<UserControl x:Class="Silverlight.Sample.Dummy"
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"
xmlns:my="clr-namespace:Sample"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<StackPanel x:Name="LayoutRoot" Background="White">
    <TextBox Height="23" x:Name="textBox2"  Width="120" />
    <TextBox Text="{Binding ElementName=textBox2, Path=Text, Mode=TwoWay}" Width="120" />
    <my:NumberTextBox Width="120" Text="{Binding ElementName=textBox2, Path=Text, Mode=OneWay}" />
</StackPanel>

Is there anything special to bind when I get the control.

PS: INotifyPropertyChanged DataContext . , , .

+3
2

, , .

, Silverlight User Control (MyTextBox) UserControl TextBox ( Xaml ). .

, TextBox, - .

0

Jehof,

, TwoWay Text my: NumberTextBox.

, ...

my: NumberTextBox TextBox? , . Text : NumberTextBox, DependencyProperty, TwoWay. :

    // The Text dependency property
    #region The Text dependency property
    public static readonly DependencyProperty TextProperty =
        DependencyProperty.Register("Text", typeof(string), typeof(NumberTextBox),
        null);

    public string Text
    {
        get { return (string)GetValue(TextProperty); }
        set { SetValue(TextProperty, value); }
    }
    #endregion

, Face To Face YinYangMoney

+1

Source: https://habr.com/ru/post/1737347/


All Articles