0

我为列表框创建了一个用户控件。用户将通过选择按钮内的文本框转到不同的页面。我必须使用文本框,因为比赛需要结束。我想在单击期间更改背景颜色。但是,按钮样式不起作用。有人可以向我展示解决我的问题的示例或链接或提示吗?

以下是我的风格:

<UserControl.Resources>
    <Style x:Key="btnCall" TargetType="Button" >
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">

                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal">
                                    <Storyboard>
                                        <DoubleAnimation To="1" Duration="0:00:00.5" Storyboard.TargetName="NormalBackground" Storyboard.TargetProperty="Opacity"/>
                                        <DoubleAnimation To="0" Duration="0:00:00.5" Storyboard.TargetName="HoverBackground" Storyboard.TargetProperty="Opacity"/>
                                        <DoubleAnimation To="0" Duration="0:00:00.1" Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Opacity"/>
                                    </Storyboard>
                                </VisualState>

                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <DoubleAnimation To="0" Duration="0:00:00.5" Storyboard.TargetName="NormalBackground" Storyboard.TargetProperty="Opacity"/>
                                        <DoubleAnimation To="0" Duration="0:00:00.5" Storyboard.TargetName="HoverBackground" Storyboard.TargetProperty="Opacity"/>
                                        <DoubleAnimation To="1" Duration="0:00:00.1" Storyboard.TargetName="PressedBackground" Storyboard.TargetProperty="Opacity"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <!--<Border Name="NormalBackground" CornerRadius="3" BorderBrush="Fuchsia" BorderThickness="1" />-->
                        <Border x:Name="NormalBackground" BorderThickness="0" />
                        <Border x:Name="HoverBackground"  Opacity="0" CornerRadius="3" BorderBrush="Yellow" BorderThickness="3" Background="Gray" />
                        <Border x:Name="PressedBackground" Opacity="0" CornerRadius="8" BorderBrush="Black" BorderThickness="1" Background="LightSteelBlue" />

                        <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" />

                    </Grid>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
 </UserControl.Resources>

我将列表框放在网格中,如下所示:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

        <ScrollViewer Style="{StaticResource ScrollViewerStyle1}" Background="#00E23162">
            <ListBox x:Name="lstCall" HorizontalAlignment="Left" Margin="6,6,0,0"   VerticalAlignment="Top" Width="360"     >
                <ListBox.ItemTemplate>
                    <DataTemplate>                          

                        <Button  Width="460" Height="70" Style="{StaticResource btnCall}"  ClickMode="Press" Click="Detail_Click" >
                            <Button.Content >

                                <StackPanel Orientation="Horizontal" Height="65" Width="400">
                                    <Image Source="{Binding Type}" Width="35" Height="35"/>

                                    <TextBlock  Width="240" Height="65" Text="{Binding summary}" TextWrapping="Wrap"
                                             Style="{StaticResource PhoneTextAccentStyle}"   />


                                    <Button Width="135" Height="65" ClickMode="Press" Click="Action_Click" Style="{StaticResource btnCall}"
                                            Visibility="{Binding isVisibility, Converter={StaticResource VisibilityConverter}}">
                                        <Button.Content>                                               
                                            <TextBlock Width="200" Height="65" Text="{Binding ActionCaption}" 
                                                       Style="{StaticResource LabelStyle_20}"     />
                                        </Button.Content>
                                    </Button>


                                </StackPanel>
                            </Button.Content>
                        </Button>

                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </ScrollViewer>
    </Grid>
4

0 回答 0