Hi,
I'm binding some ComboEditorTool controls to lists containing a Id (type Guid) and a Name (String). When the selection is null, it displays an empty Guid (00000000-0000-0000-0000-000000000000). So far in code I've been checking for this condition and manually setting the SelectedIndex to -1, which in turns displays a blank in the ComboEditorTool instead - much more user-friendly than a string of zeros! :)
I'd like to get this out of the code (to avoid repeating, and eliminate chances of forgetting to do this in some weird condition.) I've been trying to use a DataTrigger, but so far no luck - the string of zeros (empty Guid) is always displayed. Here's my latest attempt:
<igRibbon:ComboEditorTool x:Name="ClassificationVersionComboBox" Grid.Row="2" Grid.Column="1" DisplayMemberPath="Name" ValuePath="Id" ValueType="{x:Type sys:Guid}" HorizontalContentAlignment="Stretch" SelectedItemChanged="ClassificationVersionComboBox_SelectedItemChanged" > <igRibbon:ComboEditorTool.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Path=Value}"> <DataTrigger.Value> <sys:Guid>00000000-0000-0000-0000-000000000000</sys:Guid> </DataTrigger.Value> <Setter Property="SelectedIndex" Value="-1"></Setter> </DataTrigger> <DataTrigger Binding="{Binding ElementName=ClassificationComboBox, Path=SelectedIndex}" Value="-1"> <Setter Property="igRibbon:ComboEditorTool.IsEnabled" Value="False"></Setter> </DataTrigger> </Style.Triggers> </Style> </igRibbon:ComboEditorTool.Style></igRibbon:ComboEditorTool>
The second DataTrigger works fine, I just left it there so that all the XAML related to this ComboEditorTool is here. I've also tried this: <sys:Guid>{00000000-0000-0000-0000-000000000000}</sys:Guid> (note curly brackets) with no luck.
I've run out of ideas so I figured I'd post this here to see if anyone sees what I'm doing wrong, or maybe this just isn't possible in XAML?
Thanks,Michel
Makes sense - I hadn't thought of that. Through some re-working of the logic I was able to centralize the code that takes care of that, so that'll do as an alternative - my first iteration had this kind of "index reset" in several locations and I was afraid it could get out of control, but it's more contained now.
Thanks!
You won't be able to control the SelectedIndex via a TemplateTrigger. This really has to do with dependency property precedence - a local value (which is what is going to get set on things like the Value/SelectedIndex when you manipulate the control) is going to take precedence over a templatetrigger value. If you can post a sample that shows the problem you are having I can see if there is an alternative approach.