2つのクラスRadial.xaml.csとToothDimension.xaml.csがあり、クラスRadial.xaml.csのテキストボックスコントロールの値をToothDimension.xaml.csの別のクラスの依存関係プロパティは正常に動作します。テキストボックスコントロールに縛られることはありません。 Radial.xaml.csでDataContextを変更する必要がありますか?私はこれを試みた:1つのクラスの依存関係プロパティを持つ値をwpfの別のクラスのテキストボックスコントロールにバインドします
Radial.xaml.csは
public Radial()
{
InitializeComponent();
DataContext = new ToothDimension();
}
(ToothHeightが宣言されている)Radial.xaml
<TextBlock x:Name="Length" Text="{Binding DataContext.ToothHeight}" HorizontalAlignment="Left" Height="35"/>
ToothDimension.xaml.cs
はpublic Double ToothHeight
{
get { return (double)GetValue(ToothHeightProperty); }
set { SetValue(ToothHeightProperty, value); }
}
public static readonly DependencyProperty ToothHeightProperty
DependencyProperty.RegisterAttached("ToothHeight",
typeof(double), typeof(ToothDimensions),
new PropertyMetadata(new PropertyChangedCallback(ToothHeightChanged)));
private static void ToothHeightChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
double value = (double)e.NewValue;
ToothMeasurements thisControl = d as ToothMeasurements;
}
私が提供したコードでアプリケーションを構築しました。これは動作します。別のデフォルト値を依存関係プロパティに設定して、バインディングの問題があるかどうかを調べるか、Tooth-Heightプロパティの更新に苦労しているかどうかを確認してください。あなたの依存関係プロパティは以下のようになります: 'public static readonly DependencyProperty ToothHeightProperty = DependencyProperty.RegisterAttached(" ToothHeight "、typeof(double)、typeof(ToothDimension)、新しいPropertyMetadata(10.0、ToothHeightChanged));' – ManDani
ToothHeightはTooth Dimensionクラスのテキストボックスでは正常ですが、このToothHeightを再利用し、Radialクラスの別のテキストボックスコントロールにバインドします。 ToothHeightを使って同じクラスをバインドすると、DataContext = thisがコンストラクタにあります。 Radialクラスでバインドできません。ローカル変数を持つToothDimensionにコンストラクタがあります。それはこのように見えます。 public ToothDimension(int toothid) { InitializeComponent(); ToothId = toothid; } – user6850427
iamが別のクラスのToothHeightを更新できませんToothHeightを同じクラスの別のテキストボックスに更新できます – user6850427