0

OneNote 2010 - Backstage Menu - New tab
This is an Office 2010 list view, with their items styled... both hovered and pressed/selected.
How can I use the items style in WPF list view items?
I use the Fluent Ribbon Control Suite for my UI, and there are the right colors for this.
I just don't have any clue how to apply them to ListViewItems.
Please, how do I make the style?

Edit: I know how to style elements... It's just that I don't know how to apply this style, as it is a little more complex. For example, there are 2 borders.
I tried putting styles in each border in the template, but I cannot find (through the individual styles) whether the item is selected.
I also tried putting TargetNames in the items' style, but an error said I cannot.

4

3 回答 3

0

所以我在 a中设置了Template属性,并尝试绑定到其中的非属性,它起作用了!SetterStyleListViewItem

<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="ListViewItem">
            <Border Background="{DynamicResource TransparentBrush}" BorderBrush="{DynamicResource TransparentBrush}" BorderThickness="1" CornerRadius="2" Height="Auto" HorizontalAlignment="Stretch" Name="border" VerticalAlignment="Stretch">
                <Border Background="{DynamicResource TransparentBrush}" BorderBrush="{DynamicResource TransparentBrush}" BorderThickness="1" CornerRadius="2" Height="Auto" Name="border1">
                    <TextBlock Text="{Binding Path=FileName}" TextAlignment="Center" TextTrimming="CharacterEllipsis" Width="Auto" />
                </Border>
            </Border>

            <ControlTemplate.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Border.BorderBrush" TargetName="border" Value="{DynamicResource ButtonPressedOuterBorderBrush}" />
                    <Setter Property="Border.Background" TargetName="border" Value="{DynamicResource ButtonPressedOuterBackgroundBrush}" />
                    <Setter Property="Border.Background" TargetName="border1" Value="{DynamicResource ButtonPressedInnerBackgroundBrush}" />
                    <Setter Property="Border.BorderBrush" TargetName="border1" Value="{DynamicResource ButtonPressedInnerBorderBrush}" />
                </Trigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="UIElement.IsMouseOver" Value="True" />
                        <Condition Property="IsSelected" Value="False" />
                        <Condition Property="UIElement.IsEnabled" Value="True" />
                    </MultiTrigger.Conditions>
                    <Setter Property="Border.BorderBrush" TargetName="border1" Value="{DynamicResource ButtonHoverInnerBorderBrush}" />
                    <Setter Property="Border.Background" TargetName="border1" Value="{DynamicResource ButtonHoverInnerBackgroundBrush}" />
                    <Setter Property="Border.Background" TargetName="border" Value="{DynamicResource ButtonHoverOuterBackgroundBrush}" />
                    <Setter Property="Border.BorderBrush" TargetName="border" Value="{DynamicResource ButtonHoverOuterBorderBrush}" />
                </MultiTrigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="UIElement.IsKeyboardFocusWithin" Value="True" />
                        <Condition Property="IsSelected" Value="False" />
                    </MultiTrigger.Conditions>
                    <Setter Property="Border.BorderBrush" TargetName="border1" Value="{DynamicResource ButtonHoverInnerBorderBrush}" />
                    <Setter Property="Border.Background" TargetName="border1" Value="{DynamicResource ButtonHoverInnerBackgroundBrush}" />
                    <Setter Property="Border.Background" TargetName="border" Value="{DynamicResource ButtonHoverOuterBackgroundBrush}" />
                    <Setter Property="Border.BorderBrush" TargetName="border" Value="{DynamicResource ButtonHoverOuterBorderBrush}" />
                </MultiTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Setter.Value>
</Setter>

在这里,该属性FileName(显然)不是 ListViewItem 的一部分,它是我放入ListView. 它在第 6 行。

对于那些想要这个主题的人,它就在那里,在ControlTemplate.Triggers
对于我使用的资源(画笔),您需要Fluent。我从Fluent.Button.

只需用您的数据模板替换 TextBlock 就可以了!:)

于 2011-08-11T12:13:09.060 回答
0

也许你不想重新发明轮子? http://www.devcomponents.com/blog/?p=581

我使用这些组件,它们很漂亮。

真正的重点是,这不是一项微不足道的任务。

查看真正的按钮是如何制作的:http: //msdn.microsoft.com/en-us/library/ms753328.aspx,你就会明白我的意思。

于 2011-08-11T00:26:33.630 回答
0

使用ItemsControl.ItemContainerStyle为您的项目定义样式,更改可以使用Triggers该触发器的状态的外观,IsSelected以及IsMouseOver最终如何实现此特定结果取决于您...

于 2011-08-10T21:24:35.840 回答