views:

47

answers:

0

Hey all,

I've spent a good portion of my day researching this; I'm curious if it's possible to do simple binding fully in XAML, without the need to implement INotifyPropertyChanged in the code behind.

Ironically, in the amount of time I've spent researching this I could have just done it in the code behind 5 times over.

I've come across a few articles that suggest using DataTriggers (for MenuItems, the DataTrigger must be inside the a Style Trigger). I've tried this, but it doesn't work without error.

I suspect the DataTrigger couldn't find the combobox because of MenuItem scope issues, which I read in a different thread.

Anyone have any suggestions?

Code: (no build or runtime errors, but property not updated)

<ContextMenu>
<MenuItem Header="Do Something Neat" x:Name="MyMenuItem" Click="MyMenuItem_Click">
    <MenuItem.Style>
        <Style TargetType="{x:Type MenuItem}">
            <Style.Triggers>
                <Setter Property="IsEnabled" Value="True" />
                <DataTrigger Binding="{Binding ElementName=MyComboBox, Path=SelectedIndex}" Value="-1">
                    <Setter Property="IsEnabled" Value="False" />
                </DataTrigger>                                        
            </Style.Triggers>
        </Style>
    </MenuItem.Style>
</MenuItem>
</ContextMenu>