首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

Silverlight怎么修改ListBox的模版样式,小弟我能修改,但是无法修改选择,浮动的样式,怎么在XAML里面写,不是写在cs里面,最好有例子

2013-01-11 
Silverlight如何修改ListBox的模版样式,我能修改,但是无法修改选择,浮动的样式,如何在XAML里面写,不是写在

Silverlight如何修改ListBox的模版样式,我能修改,但是无法修改选择,浮动的样式,如何在XAML里面写,不是写在cs里面,最好有例子。
下面这个是我写的,能够在Item里面显示出来,但是鼠标移动上去之后,和离开,还有选择之后就没有效果了,
如何修改呢,比如鼠标移动上去一个样式,离开就恢复原来的,然后选择又是,就只能在XAML里面写,不是在CS里面动态注册,谁知道啊,新手求带啊!!!!!!!!!!

Silverlight怎么修改ListBox的模版样式,小弟我能修改,但是无法修改选择,浮动的样式,怎么在XAML里面写,不是写在cs里面,最好有例子做出来了,不知道是不是你想要的样式
  <UserControl.Resources> 



    <Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
    <Setter Property="Padding" Value="3"/>
    <Setter Property="HorizontalContentAlignment" Value="Left"/>
    <Setter Property="VerticalContentAlignment" Value="Top"/>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="TabNavigation" Value="Local"/>
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="ListBoxItem">
    <Grid Background="{TemplateBinding Background}">
    <VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="CommonStates">
    <VisualState x:Name="Normal"/>
    <VisualState x:Name="MouseOver">
    <Storyboard>
    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="rectangle">
    <EasingColorKeyFrame KeyTime="0" Value="#FF90322A"/>
    <EasingColorKeyFrame KeyTime="0:0:0.4" Value="White"/>
    </ColorAnimationUsingKeyFrames>
    </Storyboard>
    </VisualState>
    <VisualState x:Name="Disabled"/>
    </VisualStateGroup>
    <VisualStateGroup x:Name="SelectionStates">
    <VisualState x:Name="Unselected"/>
    <VisualState x:Name="Selected"/>
    </VisualStateGroup>
    <VisualStateGroup x:Name="FocusStates">
    <VisualState x:Name="Focused"/>
    <VisualState x:Name="Unfocused"/>
    </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Rectangle x:Name="rectangle" Width="75" Height="25" RadiusX="5" RadiusY="5" Stroke="Black" Margin="52,0,69,0">
    <Rectangle.Fill>
    <LinearGradientBrush StartPoint="1,0">
    <GradientStop Color="#BD5E54" Offset="0.0"/>
    <GradientStop Color="#90322A" Offset="0.9"/>
    </LinearGradientBrush>
    </Rectangle.Fill>
    </Rectangle>
    <TextBlock Text="{Binding FunctionName}" HorizontalAlignment="Center"/>
    </Grid>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>

    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">


        <ListBox HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="200" ItemContainerStyle="{StaticResource ListBoxItemStyle1}"  >
            <ListBoxItem Content="ListBoxItem"/>
            <ListBoxItem Content="ListBoxItem"/>
            <ListBoxItem Content="ListBoxItem"/>
            <ListBoxItem Content="ListBoxItem"/>
        </ListBox>
        <Button Content="Button" HorizontalAlignment="Center" VerticalAlignment="Center" Width="75"  Visibility="Collapsed"/>

    </Grid>
</UserControl>



[解决办法]

<UserControl.Resources>
<Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
<Setter Property="Padding" Value="3"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="TabNavigation" Value="Local"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Duration="0" To=".35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation Duration="0" To=".75" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor2"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="FocusVisualElement">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>


</VisualState>
<VisualState x:Name="Unfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<!--以下两句是关键!!-->
<Rectangle x:Name="fillColor" Fill="#FFff0000" IsHitTestVisible="False" Opacity="0" RadiusY="1" RadiusX="1"/>
<Rectangle x:Name="fillColor2" Fill="#FF00ff00" IsHitTestVisible="False" Opacity="0" RadiusY="1" RadiusX="1"/>
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/>
<Rectangle x:Name="FocusVisualElement" RadiusY="1" RadiusX="1" Stroke="#FF6DBDD1" StrokeThickness="1" Visibility="Collapsed"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>



我这个是,鼠标移动上去是红色,离开时白色:
Silverlight怎么修改ListBox的模版样式,小弟我能修改,但是无法修改选择,浮动的样式,怎么在XAML里面写,不是写在cs里面,最好有例子

点中后是绿色:
Silverlight怎么修改ListBox的模版样式,小弟我能修改,但是无法修改选择,浮动的样式,怎么在XAML里面写,不是写在cs里面,最好有例子

热点排行