如何从XAML列表框中删除“聚焦”边框?

时间:2014-01-29 14:15:34

标签: xaml listbox microsoft-metro

这个问题与列表框本身有关,而不是它的单元格。如果我将列表框放入视图框并单击某个项目,则整个列表框将以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>

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

enter image description here

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

1 个答案:

答案 0 :(得分:0)

我认为您正在寻找ListBoxItem模板中的内容,其中Rectangle充当了Focus Visual,如果您查看了default template,您会看到它归因于它的默认画笔(FocusVisualWhiteStrokeThemeBrush),您可以在模板中更改,或者在它到达默认词典之前提供您自己的资源以供查找;

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

希望这有帮助。

修改

抱歉,我按照你的照片去了,认为这是项目。在任何情况下,由于您的ViewBox是罪魁祸首,您只需要与其中的Border控件进行互动&gt; like you showed in a previous post of your own&lt;你是那个制作边界的人。喜欢的东西;

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

...

</ViewBox>