2013-05-05 49 views
0

我正在用XAML和C#编写商店应用程序。我想使用Border和ViewBox。我有边框样式,所以我不必多次设置属性。我将BorderThickness设置为2,并将颜色设置为白色,但这会在我的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> 

这样做的结果是:

enter image description here

的问题是围绕着字母 “T” 缩放边框。

我不想删除Grid.Resources中Border的上述样式。我只找到一个解决方案至今...

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

...你会给出正确的结果:

enter image description here

,但我不希望把每个ViewBoxes后这些行,因为会有很多。 我也尝试过创建一个组件,这个默认的“资源”是零厚边框,但是缩放比例不好。

所以我的问题是如何删除该边框?

回答

0

您对BorderThickness使用零值是正确的。可视化树层次结构中可能还有另一个元素,它也包含导致这种情况的默认值。通过拖动上面正在运行的调试应用十字 http://blois.us/Snoop/

你可以利用这个检查可视化树:

我现在不能测试此权利,但我可以推荐这个工具给你。每当我偶然发现这样的问题时,我发现查看哪些控件真正出现在运行时非常有用,因为使用xaml知道这一切真的很难。希望你能找到它!

+0

该程序没有适用于商店应用程序。 :( – 2013-05-07 10:30:27