-2
私はwpfで新しく、依存関係プロパティを学習しようとしています。 他のテキストボックスのテキストを使用して、テキストボックスの背景色を変更しようとしています。私はコンバータを使用してそれを行うことができますが、私はそれを依存プロパティを使用して実装したい。 はここにこの作業をされて罰金ブーティは、この使用してdependecyプロパティを実装する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