-2
저는 wpf에서 새로운데 종속성 속성을 배우려고합니다. 다른 텍스트 상자의 텍스트를 사용하여 텍스트 상자의 배경색을 변경하려고합니다. 나는 변환기를 사용하여 그것을 할 수 있지만 종속 속성을 사용하여 구현 싶어요. 여기이 작동하고 좋은 일 뿐이이 사용하는 실행 종속 속성을 구현하고자하는 XAML 코드종속성 속성을 사용하여 배경색을 변경하는 방법
<TextBox Name="setbox" Width="150" Height="50" FontWeight="DemiBold" FontSize="25" Canvas.Top="50" Canvas.Left="10"
Background="{Binding ElementName=statusbar,Path=Text,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource converter1}}"/>
이 내 변환 코드
public class backgroundColourConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo
culture)
{
var backColor = Brushes.Transparent;
//changes the colour of font to White if the input to the statusbar is "state1"
if (value != null && value.ToString().Equals("state1"))
{
backColor = Brushes.White;
}
//changes the colour of font to Lavender if the input to the statusbar is "state2"
else if (value != null && value.ToString().Equals("state2"))
{
backColor = Brushes.Lavender;
}
//changes the colour of font to Ivory if the input to the statusbar is "state3"
else if (value != null && value.ToString().Equals("state3"))
{
backColor = Brushes.Ivory;
}
//changes the colour of font to Green if the input to the statusbar is "state4"
else if (value != null && value.ToString().Equals("state4"))
{
backColor = Brushes.Green;
}
return backColor;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
입니다. 미리 감사드립니다.
텍스트는 종속성 속성입니다. 너 정확히 뭘 하려구? – mm8
사용자 지정 만든 종속성 속성을 사용하여 텍스트 상자의 배경색을 변경하려고합니다. – jithin
사용자 정의 만든 종속성 등록 정보를 게시하십시오. – mm8