views:

141

answers:

1

I have a button in a ListBoxItem. I want the button to stay enabled even if the list box Item is disabled. Is this possible?

Here is my style code for the listbox, listbox item and the button (called btnPick).

<Window.Resources>
 <Style x:Key="CheckBoxListStyle" TargetType="ListBox">
  <Style.Resources>
   <Style TargetType="ListBoxItem">
    <Setter Property="Template">
     <Setter.Value>
      <ControlTemplate TargetType="ListBoxItem">
       <Grid ScrollViewer.CanContentScroll="True" Margin="2">
        <Grid.ColumnDefinitions>
         <ColumnDefinition Width="20" />
         <ColumnDefinition Width="50" />
         <ColumnDefinition Width="*" />
         <ColumnDefinition Width="30" />
        </Grid.ColumnDefinitions>
        <CheckBox VerticalAlignment="Center" Grid.Column="0" IsChecked="{Binding IsSelected,
           RelativeSource={RelativeSource TemplatedParent},
           Mode=TwoWay}" Name="chkSelectedCheckBox" />
        <TextBlock VerticalAlignment="Center" Grid.Column="1" Margin="5,0,5,0" Text="{Binding Id}" />
        <TextBlock VerticalAlignment="Center" Grid.Column="2" Margin="5,0,5,0" Text="{Binding Title}" />

        <!--This is the one that I want to stay enabled somehow-->
        <Button HorizontalAlignment="Right" x:Name="btnPick" Grid.Column="3" Tag="{Binding Id}" Margin="5,0,5,0"/>                     
       </Grid>                                        
      </ControlTemplate>                              
     </Setter.Value>                                  
    </Setter>                                        
    <Style.Triggers>
        <DataTrigger Value="True">
            <DataTrigger.Binding>
                <MultiBinding Converter="{StaticResource DisableWorkItemConverter}">
                    <Binding ElementName="MainForm" Path="PickedWorkItemID"/>
                    <Binding Path="Id"/>
                    <Binding ElementName="btnCreateLink" Path="IsClicked"></Binding>
                </MultiBinding>
            </DataTrigger.Binding>
            <Setter Property="IsEnabled" Value="False"/>
            <Setter Property="loc:Main.IsCurrentItemEnabledChanged" Value="True"/>
        </DataTrigger>
    </Style.Triggers>
   </Style>                                           
  </Style.Resources>                                  
 </Style>                                             
</Window.Resources>

Right now my Data Trigger sets IsEnabled for the whole line item. Is it possible to somehow access the children of the ListBoxItem?

Something like:

<Setter Property="chkSelectedCheckBox.IsEnabled" Value="False"/>

Is what I am looking for (but that does not work). (I thought that TargetName might help me out, but that only works for DataTemplates.)

Thanks for any help.

+1  A: 

Instead of saying IsEnabled="false" for ListBoxItem, set IsEnabled property of the inner elements to false like CheckBox and all. This will keep your Button enabled anyway.

viky
Thanks for the suggestion, but how can I do that? I have updated my code to show my DataTrigger. If you know a way to modify it to allow me to just disable specific parts of the ListBoxItem's children, I would love to hear it.
Vaccano
I figured out how to do that (I moved the DataTrigger to be in the ControlTemplate.Trigger section). It disabled the checkbox, but clicking on it still makes it check
Vaccano
this is happening due to the Binding set on the IsChecked property of CheckBox with the IsSelected property. you can either remove the Binding and update IsChecked property manually or you can use UpdateSourceTrigger="Explicit" in Binding and call the UpdateTarget method
viky