I want to make the Foreground property of a WPF Textbox red as long as its Text property does not match the Text property of another Textbox on the form. I can accomplish this in the code behind and through a binding with a converter. But is there a way to do it in XAML only? (I was thinking of a Trigger of some kind).
WPF:如何根据XAML中另一个文本财产改变文本箱的原色?
原标题:WPF: How to change the Foreground color of a Textbox depending on the Text property of another in XAML?
最佳回答
页: 1 该法典可以改写:
<TextBox x:Name="_textBox1"/>
<TextBox Foreground="{Binding Text, ElementName=_textBox1, Converter={StaticResource ForegroundConverter}}"/>
或者从某种角度看,模式:
public string FirstText
{
//get/set omitted
}
public string SecondText
{
get { return _secondText; }
set
{
if (_secondText != value)
{
_secondText = value;
OnPropertyChanged("SecondText");
OnPropertyChanged("SecondTextForeground");
}
}
}
public Brush SecondTextForeground
{
get { return FirstText == SecondText ? Brushes.Red : Brushes.Black; }
}
问题回答
暂无回答
相关问题
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding