【问题标题】:Silverlight 4.0 disable some ListBoxItems with XAML bindingSilverlight 4.0 通过 XAML 绑定禁用某些 ListBoxItems
【发布时间】:2011-11-23 11:02:44
【问题描述】:

是否可以在 Silverlight 4.0 中通过 XAML 绑定禁用某些 ListBoxItem?

我在网上找到了一些解决方案,但没有一个适用于 Silvelight 4.0

谢谢!

皮莱吉

【问题讨论】:

  • 你说的是动态列表框还是硬编码?

标签: silverlight data-binding silverlight-4.0 listbox


【解决方案1】:

喘气,喘气! ...至少我找到了解决方案,但很难!

我的解决办法是:

<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>

结论是个人的,当然有些问题可以解决,但是......

  • 与 WPF 相比,在 Silverlight 中,DataTrigger(及其 ChangePropertyAction)不能停留在模板内的控件内的其他位置。而ChangePropertyAction对象的属性TargetObject,只能绑定模板内的控件名称(TargetObject="{Binding ElementName=g}" )

  • 因此,无法将 DataTrigger 与整个 Item 绑定并设置其属性 IsEnabled,但我们需要使用每个控件,并且我们需要重现 Item 在禁用时的行为。特别是我们可以将包含所有其他控件的主网格的属性 IsHitTestVisible 设置为 False,以避免它负责鼠标输入。

最后,在 WPF 中这要容易得多,但重要的是要知道该做什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-14
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    相关资源
    最近更新 更多