Reputation: 303
I have viewModel
public class Measurement : INotifyPropertyChanged
{
private bool _processed;
public bool Processed
{
get
{
if ( .... ) return true;
return false;
}
set
{
_processed = value;
OnPropertyChanged(new PropertyChangedEventArgs("Processed"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChanged?.Invoke(this, e);
}
}
XAML:
<DataGrid
ItemsSource="{Binding CurrentSeries.MeasurementsSeries,
ElementName=AppMainWindow,Mode=TwoWay,NotifyOnSourceUpdated=True,
UpdateSourceTrigger=PropertyChanged}">
<DataGrid.Columns>
<DataGridTemplateColumn Width="45" Header="Status">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock x:Name="PhotosStatusToolTip"
ToolTip="Радиусы всех капель должны быть расчитаны, чтобы построить график."
Height="25" Width="25" />
<ContentControl x:Name="PhotosStatus"
ToolTip="Радиусы всех капель должны быть расчитаны, чтобы построить график."
Content="{StaticResource Warning}"
Height="25" Width="25"
HorizontalAlignment="Center" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Processed}" Value="true">
<Setter Property="Content"
Value="{StaticResource Ok}"
TargetName="PhotosStatus" />
<Setter Property="ToolTip"
Value="Радиус капли расчитан успешно."
TargetName="PhotosStatusToolTip" />
<Setter Property="ToolTip"
Value="Радиус капли расчитан успешно."
TargetName="PhotosStatus" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
I have two problems:
I've already tried to add second data trigger for case when Processed is false, but this doesn't seems to help.
Upvotes: 0
Views: 32
Reputation: 12007
Having a property value calculated as you indicated and providing a setter does not fit together. The expectation for a property is that whenever you set the value, the getter will return the set value which is not the case if you calculate the value in the getter.
So either the Processed
getter should always return the value of _processed.
Or you should remove the setter and add a OnPropertyChanged(new PropertyChangedEventArgs("Processed"));
wherever you change anything influcencing the calculated value.
E.g.
public bool Processed
{
get
{
if (X > 0 && Y > 0) return true;
return false;
}
}
public int X
{
get { return _x; }
set
{
_x = value;
OnPropertyChanged(new PropertyChangedEventArgs(namepf(X)));
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Processed)));
}
}
public int Y
{
get { return _y; }
set
{
_y = value;
OnPropertyChanged(new PropertyChangedEventArgs(namepf(Y)));
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Processed)));
}
}
Upvotes: 1