Reputation: 1126
Is it possible, in Silverlight 4.0, to disable some ListBoxItems with XAML binding?
I have found some solutions in the web, but nothing that works with Silvelight 4.0
Thank you!
Pileggi
Upvotes: 0
Views: 605
Reputation: 1126
Pant, pant! ... At least I have found the solution but it was hard!
My solution is:
<Style x:Key="modItemMainParts" TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid x:Name="g" Background="{TemplateBinding Background}">
...
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding abilitato}" Value="False">
<ei:ChangePropertyAction TargetObject="{Binding ElementName=g}" TargetName="IsHitTestVisible" Value="False" PropertyName="IsHitTestVisible"/>
<ei:ChangePropertyAction TargetObject="{Binding ElementName=g}" TargetName="Opacity" Value="0.5" PropertyName="Opacity"/>
</ei:DataTrigger>
</i:Interaction.Triggers>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The conclusions are presonal and certainly some problems can be worked around, but...
In contrast to WPF, in Silverlight a DataTrigger (with its ChangePropertyAction) can't stay elsewhere then inside a control inside the Template. And the property TargetObject of the ChangePropertyAction object, can be binded only linking the name of a control inside the template (TargetObject="{Binding ElementName=g}" )
For this reason it's impossible to bind the DataTrigger with the entire Item and to set it's property IsEnabled but we need to work with every single control, and we need to reproduce the behaviour of the Item when it's disabled. Particularly we can set the property IsHitTestVisible of the main Grid, that contains every other controls, to False, to avoid that it were responsible for the mouse inputs.
Finally in WPF it was quite more easy, but the important is to know what to do.
Upvotes: 1