Skip to content

Commit 2f9bc4d

Browse files
committed
Fix PhotoTagger multiselect.
Bug introduced in 0d20a11, due to failure to convert ObservableCollection to ReadOnlyObservableCollection.
1 parent 4cf4bfa commit 2f9bc4d

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

PhotoTagger.Wpf/ValueConverters.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using PhotoTagger.Imaging;
22
using System;
33
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
45
using System.Globalization;
56
using System.Linq;
67
using System.Windows;
@@ -182,4 +183,24 @@ public object ConvertBack(object value, Type targetType,
182183
throw new NotSupportedException();
183184
}
184185
}
186+
187+
[ValueConversion(typeof(ObservableCollection<Photo>),
188+
typeof(ReadOnlyObservableCollection<Photo>))]
189+
public class ObservableCollectionToReadOnlyConverter : IValueConverter {
190+
public object Convert(object value, Type targetType,
191+
object parameter, CultureInfo culture) {
192+
if (value is null) {
193+
return null;
194+
} else if (value is ObservableCollection<Photo> c) {
195+
return new ReadOnlyObservableCollection<Photo>(c);
196+
} else {
197+
throw new NotSupportedException();
198+
}
199+
}
200+
201+
public object ConvertBack(object value, Type targetType,
202+
object parameter, CultureInfo culture) {
203+
throw new NotSupportedException();
204+
}
205+
}
185206
}

PhotoTagger/TaggerWindow.xaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<ptwpf:AnyToEnabledValueConverter x:Key="AnyToEnabledValueConverter"/>
1414
<ptwpf:ElementCountToVisibilityValueConverter x:Key="ElementCountToVisibilityValueConverter"/>
1515
<ptwpf:AnyChangedToEnabledValueConverter x:Key="AnyChangedToEnabledValueConverter"/>
16+
<ptwpf:ObservableCollectionToReadOnlyConverter x:Key="ObservableCollectionToReadOnlyConverter"/>
1617
<Style TargetType="{x:Type Button}">
1718
<Setter Property="Padding" Value="1,1" />
1819
<Setter Property="Margin" Value="1,1" />
@@ -87,9 +88,17 @@
8788
</Binding>
8889
</local:SinglePhotoEdit.Visibility>
8990
</local:SinglePhotoEdit>
90-
<local:MultiPhotoEdit PhotoSet="{Binding SelectedPhotos,
91-
ElementName=window,
92-
Mode=OneWay}">
91+
<local:MultiPhotoEdit>
92+
<local:MultiPhotoEdit.PhotoSet>
93+
<Binding>
94+
<Binding.ElementName>window</Binding.ElementName>
95+
<Binding.Path>SelectedPhotos</Binding.Path>
96+
<Binding.Mode>OneWay</Binding.Mode>
97+
<Binding.Converter>
98+
<StaticResource ResourceKey="ObservableCollectionToReadOnlyConverter"/>
99+
</Binding.Converter>
100+
</Binding>
101+
</local:MultiPhotoEdit.PhotoSet>
93102
<local:MultiPhotoEdit.Visibility>
94103
<Binding Path="SelectedPhotos.Count"
95104
ElementName="window"

0 commit comments

Comments
 (0)