视图框和边框 [英] Viewbox and border

查看:31
本文介绍了视图框和边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XAML 和 C# 编写商店应用程序.我想使用边框和视图框.我有边框样式,所以我不必多次设置属性.我将 BorderThickness 设置为 2,将颜色设置为白色,但这会导致我的 Viewbox 出现问题.

I am writing a Store app with XAML and C#. I want to use Border and ViewBox. I got border styled, so I do not have to set properties that many times. I set BorderThickness to 2, and color to White, but this causes problems in my Viewbox.

这里是 XAML:

<Viewbox Grid.Row="1" Stretch="Uniform">
  <Grid Width="600" Height="600">
    <Grid.Resources>
      <Style TargetType="Border">
        <Setter Property="BorderBrush" Value="White" />
        <Setter Property="BorderThickness" Value="2" />
      </Style>
      <Style TargetType="Grid">
        <Setter Property="VerticalAlignment" Value="Top" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="Width" Value="150" />
        <Setter Property="Height" Value="150" />
      </Style>
    </Grid.Resources>

    <StackPanel Orientation="Vertical">
      <StackPanel Orientation="Horizontal">
        <Grid>
          <Border>
            <Viewbox>
              <TextBlock Text="T" />
            </Viewbox>
          </Border>
        </Grid>

这样做的结果是:

问题在于字母T"周围的缩放边框.

The problem is the scaled border around the letter "T".

我不想删除 Grid.Resources 中边框的上述样式.到目前为止,我只找到了一种解决方案...

I do not want to remove above styling for Border in Grid.Resources. I found only one solution so far...

            <Viewbox>
              <Viewbox.Resources>
                <Style TargetType="Border">
                  <Setter Property="BorderBrush" Value="White" />
                  <Setter Property="BorderThickness" Value="0" />
                </Style>
              </Viewbox.Resources>
              <TextBlock Text="T" />

...什么会给出正确的结果:

... what would give correct result:

,但我不想把这些行放在每个 ViewBoxes 之后,因为会有很多.我还尝试制作一个组件,该组件具有零粗边框的默认资源",但缩放效果不佳.

, but I do not want to put these lines after each ViewBoxes, because there will be many. I also tried to make a component, what has this default "resource" of zero thick border, but that had bad scaling.

所以我的问题是如何去除那个边框?

推荐答案

BorderThickness 使用零值是正确的.可视化树层次结构中可能还有另一个元素也包含导致这种情况的默认值.

You're right to use the zero value for BorderThickness. There just might be another element in the visual tree hierarchy that also holds a default value that causes this.

我现在无法对此进行测试,但我可以向您推荐此工具:http://blois.us/Snoop/

I can't test this right now, but I can recommend this tool to you: http://blois.us/Snoop/

您可以通过拖动正在运行的调试应用程序上方的十字准线来检查可视化树.每次我偶然发现这样的问题时,我发现查看哪些控件在运行时真正出现非常有用,因为使用 xaml 可能很难了解所有内容.希望你能找到它!

You can inspect the visual tree with this by dragging the crosshair above your running debug application. Every time I stumbled upon a problem like this I found it highly useful to see which controls really appear at runtime, because with xaml it can be really tough to know it all. Hope you can find it!

这篇关于视图框和边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆