【问题标题】:ListBox with Rounded Corners (Windows Store App)带圆角的列表框(Windows 应用商店应用程序)
【发布时间】:2015-10-21 11:05:04
【问题描述】:

我在Flyout 中有一个ListBox。有什么方法可以让我的ListBox 圆角?我已经搜索过,我找不到任何东西。有没有你推荐的 style/Xaml 模板?

这是我的代码:

    <Flyout>
        <Flyout.FlyoutPresenterStyle>
          <Style TargetType="FlyoutPresenter">
             <Setter Property="Margin" Value="30,30,0,0"/>
             <Setter Property="Background" Value="Transparent"/>
             <Setter Property="BorderBrush" Value="Transparent"/>
             <Setter Property="BorderThickness" Value="0"/>
             <Setter Property="MinHeight" Value="300"/>
             <Setter Property="MinWidth" Value="200"/>
           </Style>
        </Flyout.FlyoutPresenterStyle>


        <ListBox x:Name="AllItemsView" Width="200" Height="auto" BorderThickness="0" VerticalAlignment="Top" Foreground="Black" Background="White" Grid.RowSpan="2" ItemsSource="{Binding}" SelectionMode="Single" SelectionChanged="AllItemsView_SelectionChanged">
           <ListBox.Resources>
              <Style TargetType="Border">

                 <Setter Property="CornerRadius" Value="20,20,20,20"/>
                 <Setter Property="BorderBrush" Value="BlueViolet"/>
                 <Setter Property="BorderThickness" Value="7"/>
                 <Setter Property="Padding" Value="5"/>
               </Style>

            </ListBox.Resources>
            <ListBox.ItemContainerStyle>
               <Style TargetType="ListBoxItem">
                   <Setter Property="Padding" Value="0"/>
                   <Setter Property="BorderThickness" Value="1"/>
               </Style>

          </ListBox.ItemContainerStyle>

           <ListBox.ItemTemplate>
              <DataTemplate>

               <Grid Width="200" Height="40" Margin="0,0,0,0" Name="colorGrid">
               <Grid.Background>
                   <SolidColorBrush Color="{Binding ItemType, Mode=OneWay, Converter={StaticResource ItemTypeToColorConverter1}}" />


               </Grid.Background>
               <StackPanel x:Name="StackItem">
                  <TextBlock Text="{Binding ItemTitle}" FontWeight="{Binding ItemType, Converter={StaticResource itemTypeToBoldConverter1}}" Margin="{Binding ItemType, Converter={StaticResource itemTypeToMarginConverter1}}" />
                  <TextBlock Text="{Binding ItemPage}" Visibility="Collapsed"/>
               </StackPanel>

               </Grid>

            </DataTemplate>

          </ListBox.ItemTemplate>

      </ListBox>

 </Flyout>

【问题讨论】:

    标签: c# xaml listbox windows-store-apps styles


    【解决方案1】:

    如果你想为 ListBox 设置 CornerRadius,你可以做同样的事情,但在 Resources 中

     <ListBox ...>
            <ListBox.Resources>
                <Style TargetType="Border">
                    <Setter Property="CornerRadius" Value="10"/>
                </Style>
            </ListBox.Resources>
        <!--...-->
    </ListBox>
    

    【讨论】:

    • 我忘了提到我的 ListBox 在 Flyout 中(我刚刚更新了我的问题)。当我添加你的代码时,边框会变圆但有一定的边距,即使我将边框设置为透明也不好看。
    • 我编辑并提供了一个新代码,你说的是这个吗?
    • 我尝试了您的 ,但没有成功。请检查我的代码!
    猜你喜欢
    • 2015-11-22
    • 1970-01-01
    • 2013-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多