我有以下樣式和列表框:WP7列表框ItemContainerStyle XAML禁用不工作
<Style x:Key="LwHListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Padding" Value="24, 0, 24, 0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="LayoutRoot" BorderBrush="#FFCCCCCC" BorderThickness="0, 0, 0, 1" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="LayoutRoot">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ContentContainer"/>
<DoubleAnimation Duration="0" To="0.6" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LayoutRoot" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ListBox x:Name="lbxContainer" Height="Auto" Width="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalAlignment="Top" ItemContainerStyle="{StaticResource LwHListBoxItemStyle}" />
我使用Expression Blend中創建的風格。我想讓ListBoxItem在禁用時具有60%的不透明度。我使用ListBoxItems以編程方式填充ListBox,並根據特定條件設置其IsEnabled屬性。我已經通過調試器,並確認ListBoxItems確實有IsEnabled = false,所以我的結論是,我的xaml一定有問題。有什麼我失蹤或做錯了,導致項目禁用時不會變得不透明?
列表框是一個白色背景,並有黑色文本的內容。不透明度應該使它變灰。如果我將不透明度添加到正常視覺狀態,它會按照預期的正常狀態顯示,但也會顯示爲禁用狀態。我知道禁用的項目實際上已被禁用,因爲我無法點擊它們。我認爲下面的代碼會顯示正常狀態爲不透明,但禁用了不透明的項目。
<VisualState x:Name="Normal">
<Storyboard>
<DoubleAnimation Duration="0" To="0.6" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LayoutRoot" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
更新:我很確定我的禁用狀態有問題。即使我將背景更改爲藍色,我在禁用狀態下添加的任何東西都會佔據上風。我以編程方式創建ListBoxItems並將content屬性設置爲我創建的用戶控件。這可能導致問題嗎?這對我來說沒有任何意義,因爲我可以用60%的不透明度設置正常狀態,它可以工作,那麼爲什麼不能禁用狀態?
謝謝,但是這並不完全是我要找的。列表框位於白色背景上,並具有黑色文字作爲內容。不透明度應該使它變灰。如果我將不透明度添加到正常視覺狀態,它會按預期顯示。我不知道爲什麼它不適用於殘疾人士。<的VisualState X:名稱= 「正常」> \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t的VisualState> –
CACuzcatlan