【问题标题】:How to remove "focused" border from XAML listbox?如何从 XAML 列表框中删除“聚焦”边框?
【发布时间】:2014-01-29 23:53:17
【问题描述】:

这个问题是关于列表框本身而不是单元格。如果我将列表框放入视图框中,然后单击一个项目,则整个列表框将被 1px 边框包围。我不想要那个,因为它很丑。这个边框怎么去掉?

详情:

  <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Viewbox Grid.Row="1" Stretch="Uniform">
      <StackPanel Orientation="Horizontal" Margin="0,20,0,20">
        <Grid Width="200">
          <ListBox ItemsSource="{Binding Rajzelemek}" Background="{x:Null}">
            <ListBox.ItemTemplate>
              <DataTemplate>
                <StackPanel Orientation="Horizontal">
                  <ContentControl Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Content="{Binding Ikonja}" Width="25" Height="25" VerticalAlignment="Center" />
                  <TextBlock Text="{Binding}" VerticalAlignment="Center" Foreground="{ThemeResource ApplicationForegroundThemeBrush}" />
                </StackPanel>
              </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBox.ItemsPanel>
              <ItemsPanelTemplate>
                <StackPanel Orientation="Vertical" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
              </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
          </ListBox>
        </Grid>
      </StackPanel>
    </Viewbox>
  </Grid>

如果我评论 &lt;Viewbox Grid.Row.... 部分,一切都很好,但没有缩放。我想要缩放东西,这就是我使用视图框的原因,但我不想要这个边框:

上面的代码也被放在了一个地铁 BlankPage1 上,并且做了同样的事情。

【问题讨论】:

    标签: xaml listbox microsoft-metro


    【解决方案1】:

    我认为您正在寻找ListBoxItem 模板中的内容,其中Rectangle 充当焦点视觉,如果您查看default template,您会看到它带有归因于它的默认画笔( FocusVisualWhiteStrokeThemeBrush),您可以在模板中进行更改,也可以提供您自己的资源供它在它访问默认字典之前找到;

       <SolidColorBrush x:Key="FocusVisualWhiteStrokeThemeBrush" Color="Transparent" />
    

    希望这会有所帮助。

    编辑

    对不起,我是按照你的照片看的,以为是物品。在任何情况下,因为您的ViewBox 是罪魁祸首,您只需要与其中的Border 控件进行交互 >like you showed in a previous post of your own

    <Viewbox>
                  <Viewbox.Resources>
                    <Style TargetType="Border">
                      <Setter Property="BorderBrush" Value="Transparent" />
                      <Setter Property="BorderThickness" Value="0" />
                    </Style>
                  </Viewbox.Resources>
    
    ...
    
    </ViewBox>
    

    【讨论】:

    • 不是列表框项,而是列表框本身有边框(围绕所有项,项没有边框)。我无法用这些信息解决我的问题;我可以问你更详细一点吗?
    • @Zéiksz 看到编辑后的答案,抱歉只是看你的截图,没有阅读关于ViewBox的部分
    • 答案是完全合乎逻辑的,“应该工作”,但没有。我不知道它是否可以在 WPF 下正常工作,但是对于 Metro,列表框内仍然有一个边框 - 仅当列表框或其列表项之一被聚焦时。我什至在列表框资源下尝试了这个“targettype-border”的东西——到目前为止还没有运气。
    • 是的,但我需要它来进行 UI 缩放。我刚刚检查了 GridView,什么没有边框。我的猜测是,如果那东西真的是一个边界,那也会扩展。
    猜你喜欢
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 2011-02-19
    • 2016-08-04
    • 1970-01-01
    相关资源
    最近更新 更多