在项目中,我想改变每当一个新的买入价是在一个DataGrid单元格的背景,而我把它用
public class Notifier : INotifyPropertyChanged
{
public bool BidUp
{
get { return _bidUp; }
set
{
_bidUp = value;
OnPropertyChanged("BidUp");
}
}
public double Bid
{
get { return _bid; }
set
{
BidUp = (value > this.Bid);
_bid = value;
OnPropertyChanged("Bid");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
而我的DataGridCell XAML代码:
<DataTemplate>
<Border x:Name="BidBoder" Background="AliceBlue" BorderThickness="0">
<TextBlock Text="{Binding Bid}" x:Name="BidTextBlock" HorizontalAlignment="Right"></TextBlock>
</Border>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding BidUp}" Value="True">
<DataTrigger.EnterActions>
<StopStoryboard BeginStoryboardName="bidUpStoryboard"/>
<StopStoryboard BeginStoryboardName="bidDownStoryboard"/>
<BeginStoryboard Name="bidUpStoryboard">
<Storyboard BeginTime="00:00:00">
<ColorAnimation
BeginTime="00:00:00"
Duration="0:0:0.1"
To="LimeGreen"
AutoReverse="True"
Storyboard.TargetName="BidBoder"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
</ColorAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
<DataTrigger Binding="{Binding BidUp}" Value="False">
<DataTrigger.EnterActions>
<StopStoryboard BeginStoryboardName="bidUpStoryboard"/>
<StopStoryboard BeginStoryboardName="bidDownStoryboard"/>
<BeginStoryboard Name="bidDownStoryboard">
<Storyboard BeginTime="00:00:00">
<ColorAnimation
BeginTime="00:00:00"
Duration="0:0:0.1"
To="Red"
AutoReverse="True"
Storyboard.TargetName="BidBoder"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
</ColorAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</DataTemplate.Triggers>
现在发生的事情是,如果价格上涨,其次是一上来, BidUp = true--->true
的的PropertyChanged不会触发。 有没有一种方法来trigeer改变甚至_bidUp = value
不会改变?
我想一般问,如果Property A = somevalue
被调用时,为什么OnPropertyChanged
如果相同的值适用不叫?