WPF 프로젝트에서 작업 중이며 두 개의 특정 RadioButton이 지정된 다른 Component의 속성을 변경하려고합니다. 하지만 지금은 RadioButton 안에 String을 저장하려고합니다. 이 속성으로WPF - 종속성 속성 오류
public class AdjustBehavior : Behavior<RadioButton>
{
: 그 내용은
, 나는 행동 클래스를 생성 한 XAML 측면에서
public static String GetLabelContent(RadioButton tb)
{
return (String)tb.GetValue(AdjustLabelContentProperty);
}
public static void SetLabelContent(RadioButton tb, String value)
{
tb.SetValue(AdjustLabelContentProperty, value);
}
:
public static DependencyProperty AdjustLabelContentProperty =
DependencyProperty.RegisterAttached("LabelContent", typeof(String), typeof(AdjustBehavior),
new FrameworkPropertyMetadata(null,
FrameworkPropertyMetadataOptions.Inherits));
그리고 이러한 getter 및 setter , 나는 이것을했다 :
<RadioButton Content="Banana" Height="16" HorizontalAlignment="Left" Margin="30,216,0,0" Name="radioButton1" VerticalAlignment="Top" GroupName="a" IsThreeState="False" IsChecked="True" Checked="radioButton1_Checked" >
<int:Interaction.Behaviors>
<i:AdjustBehavior LabelContent="Apple" />
</int:Interaction.Behaviors>
</RadioButton>
여기서 int는 Interaction.Behaviors의 네임 스페이스이고 i :는 AdjustBehavior 클래스의 네임 스페이스입니다. 그러나 응용 프로그램을 시작할 때마다 LabelContent는 null로 설정됩니다. 왜?
나는 Behavior 클래스의 나머지 부분을 게시하지 않았다. 문제가되지 않을 것이라고 생각했기 때문에, 필자는 필요할 경우 할 것이다.
미리 감사드립니다.
클라크
많은 감사드립니다. 이제 작동 중입니다. –