1

選択状態に基づいて、リストボックス項目の背景を切り替えたいです。

最初に、ItemTemplate の背景を次のようにハードコーディングしました。

   <StackPanel.Background>
        <ImageBrush ImageSource="PodImages\podstate-Clip.png" />
   </StackPanel.Background>

視覚的な状態 (選択されているか選択されていないか) に基づいて背景を設定するために Blend に入ろうとしましたが、Blend を理解できず、スタイリング マークアップをまだ理解していません。誰かがスタイル マークアップを手伝ってくれたり、Blend でこれを設定できる場所を教えてくれたりできますか?

編集:わかりました、リスト項目をリスト ボックスに追加し、ブレンドの視覚状態に基づいて背景を設定する方法を見つけましたが、データ テンプレート項目に対してこれを行う方法がわかりません

編集:
わかりました、私がスタイルでやりたいことはこのようなものになると思います(しかし、これは私のアプリをクラッシュさせます)

修正しました

<Storyboard>
     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ImageSource" Storyboard.TargetName="ContentBackground">
            <DiscreteObjectKeyFrame KeyTime="0" Value="PodImages/podstate-Clipped.png"/>
     </ObjectAnimationUsingKeyFrames>
</Storyboard>

全体のスタイルは次のとおりです。

<Style x:Key="ListBoxItemStyle2" 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="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" 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"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="SelectionStates">
                                <VisualState x:Name="Unselected">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ImageSource" Storyboard.TargetName="ContentBackground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="PodImages/podstate-Clip.png"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                    <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ImageSource" Storyboard.TargetName="ContentBackground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="PodImages/podstate-Clipped.png"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </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}">
                            <ContentControl.Background>
                                <ImageBrush Stretch="Fill" x:Name="ContentBackground" ImageSource="PodImages/podstate-Clip.png"/>
                            </ContentControl.Background>
                        </ContentControl>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
4

1 に答える 1

0

リストボックスのバックグラウンドで {Binding ResourceName} を使用します。その他のヒントについては、こちらをご覧ください http://www.silverlight.net/learn/data-networking/binding/silverlight-data-binding

または、大量の情報を提供する「Silverlight でのデータバインディング」を検索することをお勧めします。

于 2012-08-14T14:22:43.870 に答える