Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何在XAML中添加ListView CornerRadius_Wpf_Xaml_Listview_Styles - Fatal编程技术网

Wpf 如何在XAML中添加ListView CornerRadius

Wpf 如何在XAML中添加ListView CornerRadius,wpf,xaml,listview,styles,Wpf,Xaml,Listview,Styles,我想在XAML中为CornerRadius添加ListView样式,我有一种方法,但在我的情况下,这不起作用。 像这样 <ListView.Style> <Style TargetType="{x:Type ListView}"> <Setter Property="BorderBrush" Value="White"/>

我想在XAML中为CornerRadius添加ListView样式,我有一种方法,但在我的情况下,这不起作用。 像这样

                    <ListView.Style>
                    <Style TargetType="{x:Type ListView}">
                        <Setter Property="BorderBrush" Value="White"/>
                        <Setter Property="BorderThickness" Value="0"/>
                        <Setter Property="Margin" Value="0"/>
                        <Setter Property="OverridesDefaultStyle" Value="true"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListView}">
                                    <Border CornerRadius="5">
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>

                        <!-- here we go -->
                        <Style.Resources>
                            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Pink"/>
                            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Pink"/>
                        </Style.Resources>
                    </Style>

                </ListView.Style>

这不会显示ItemsSource的数据,因此我的Listview如下所示

                <ListView x:Name="MenuBarList" 
                ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                Height="{Binding MainMenuHeight}"  
                Width="{Binding MainMenuWidth}" 
                ItemsSource="{Binding}" 
                      Foreground="White"
                Background="#FF3D61D0"
                SelectionMode="Single">

那么我如何添加这种风格。
谢谢你

您的模板应该包含一个
ItemsPresenter
,以便
列表视图知道在哪里显示项目。ItemsPresenter通常位于
ScrollViewer
中,以使其可滚动:

                    ...
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListView}">
                                <Border CornerRadius="5">
                                    <ScrollViewer>
                                        <ItemsPresenter />
                                    </ScrollViewer>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    ...
。。。
...
更简单的解决方案是编辑以下内容的副本:


            <ControlTemplate TargetType="{x:Type ListView}">
                <Border Name="Bd"
                        CornerRadius="5"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        SnapsToDevicePixels="true">
                    <ScrollViewer Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}"
                                  Padding="{TemplateBinding Padding}">
                        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </ScrollViewer>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsGrouping"
                             Value="true">
                        <Setter Property="ScrollViewer.CanContentScroll"
                                Value="false"/>
                    </Trigger>
                    <Trigger Property="IsEnabled"
                             Value="false">
                        <Setter TargetName="Bd"
                                Property="Background"
                                Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>