ItemsControl
이 있는데, 이는 뷰 모델의 속성에 바인딩 된 CollectionViewSource
에 바인딩되어 있습니다.컬렉션 변경시 GroupStyle 헤더의 바인딩이 업데이트되지 않습니다.
<GroupStyle HeaderTemplate="{StaticResource TotalDurationTemplate}" />
TotalDurationTemplate
이다 :
<DataTemplate x:Key="TotalDurationTemplate">
<Border BorderBrush="Black" BorderThickness="0 1" Background="#EEE">
<Grid>
<TextBlock HorizontalAlignment="Center"
FontSize="18" FontWeight="Bold"
Text="{Binding Path=Items[0].Start, Converter={StaticResource DateTimeFormatConverter}, ConverterParameter='ddd dd/MM'}" />
<TextBlock Margin="10 0" HorizontalAlignment="Right" VerticalAlignment="Center"
FontSize="16" Foreground="#9000"
Text="{Binding Items, Converter={StaticResource TotalDurationConverter}}" />
</Grid>
</Border>
</DataTemplate>
문제는 제 TextBlock
(Items
에 결합 된 하나) 인 것을 다시되지
ItemsControl
이 닮은 GroupStyle
세트를 갖는다 - 새 항목이보기 모델의 컬렉션 (ObservableCollection<>
)에 추가되면 평가됩니다. 항목이 ListView
에 올바른 그룹으로 추가되었지만 총 지속 시간 값은 업데이트되지 않습니다.
총 비행 시간에 대한 변환기는 다음과 같습니다
public class TotalDurationConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return
((IEnumerable<object>)value)
.Select(x => ((RecentTimingViewModel)x).Duration)
.Aggregate((v1, v2) => v1 + v2)
.TotalHours
.ToString("F2") + "h";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new InvalidOperationException();
}
}
가 어떻게 결합 새로 고침보기 모델의 항목이 변경되었는지 확인 할 때 올바르게?
편집 : 솔루션
내가 수락 답변에서 솔루션이 가져다 내 코드에 넣어.
<DataTemplate x:Key="TotalDurationTemplate">
<Border BorderBrush="Black" BorderThickness="0 1" Background="#EEE">
<Grid>
<TextBlock HorizontalAlignment="Center"
FontSize="18" FontWeight="Bold"
Text="{Binding Path=Items[0].Start, Converter={StaticResource FormatDateIntelligentConverter}}" />
<TextBlock Margin="10 0" HorizontalAlignment="Right" VerticalAlignment="Center"
FontSize="16" Foreground="#9000">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TotalDurationConverter}">
<MultiBinding.Bindings>
<Binding Path="Items" />
<Binding Path="Items.Count" />
</MultiBinding.Bindings>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
</Border>
</DataTemplate>
그리고 IMultiValueConverter
에 TotalDurationConverter
변경 :이 작업까지 끝난 것입니다. 그냥 의 두 번째 항목을 무시합니다.
그래 나는 MultiBinding의 소스 목록의 List.Count에 결합하는 생각 작업을 떠난 후. 내일 시도하고 그것이 어떻게되는지 보게 될 것입니다. –
쿨, 그것은 시나리오 중 하나에서 나를 위해 일해 왔습니다 ... 그것이 작동하는지 알려주세요. 모든 최선 :) –