I bind the PageMediaSizecollection PrintQueueto ItemSourcefrom ComboBox(this works fine). Then I tie SelectedItemto ComboBoxk DefaultPrintTicket.PageMediaSize PrintQueue. Although this will set the selected value to DefaultPrintTicket.PageMediaSizejust fine, it does not set the original selected value ComboBoxto the initial value. DefaultPrintTicket.PageMediaSizeThis is because the link DefaultPrintTicket.PageMediaSizedoes not match any of the links in the collection. However, I do not want it to compare objects by reference, but instead by value, but it PageMediaSizedoes not override Equals (and I do not control it). I would really like to install IComparablefor ComboBox, but I see no way to do this. I tried to use Converter, but I would need more than the value, and I could not figure out how to pass the collection toConverterProperty. Any ideas on how to deal with this problem.
Here is my xaml
<ComboBox x:Name="PaperSizeComboBox"
ItemsSource="{Binding ElementName=PrintersComboBox, Path=SelectedItem,
Converter={StaticResource printQueueToPageSizesConverter}}"
SelectedItem="{Binding ElementName=PrintersComboBox,
Path=SelectedItem.DefaultPrintTicket.PageMediaSize}"
DisplayMemberPath="PageMediaSizeName"
Height="22"
Margin="120,76,15,0"
VerticalAlignment="Top"/>
And the code of the converter that gets the collection PageMediaSize
public class PrintQueueToPageSizesConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
return value == null ? null :
((PrintQueue)value).GetPrintCapabilities().PageMediaSizeCapability;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Edit
I tried to set the DefaultPrintTicket.PageMediaSizeappropriate link in the collection before InitializeComponent, but that didn't work. It definitely sets the value when I choose something from ComboBox, but it doesn't seem to go the other way.
source
share