开发者

preventing label border from being bold

开发者 https://www.devze.com 2023-03-20 01:08 出处:网络
I am using viewbox to fill the space available, it kind of gives me right result but not exactly. <Viewbox Grid.Row=\"0\"Grid.Column=\"0\">

I am using viewbox to fill the space available, it kind of gives me right result but not exactly.

<Viewbox Grid.Row="0"  Grid.Column="0">
    <StackPanel Name="letters" Orientation="Horizontal">
         <Label ..>...</Label>
               ...
    </StackPanel>
开发者_如何学Python</Viewbox>

When I keep adding labels to the StackPanel when they exceed the container width they get smaller.

It's the behaviour I want, however I don't want labels' border to be 'bold' (because of viewbox).

How should I change my code structure?


I've modified kzen's answer to ensure that you don't have to explicitly define the style in code every time you add a new label to that stack panel. (Warning: coding in-place, but AFAIK, it should compile fine as is)

<Viewbox Grid.Row="0"  Grid.Column="0">
  <StackPanel Name="letters" Orientation="Horizontal">
    <StackPanel.Resources>
      <ResourceDictionary>
        <Style TargetType="{x:Type Label}">
          <Setter Property="BorderThickness" Value="0"/>
          <Setter Property="Margin" Value="0"/> <!-- not sure if this is also something you want -->
          <Setter Property="Padding" Value="0"/> <!-- not sure if this is also something you want -->
        </Style>
      </ResourceDictionary>
    </StackPanel.Resources>

    <Label></Label>
    ...
  </StackPanel>
</Viewbox>


Create a style for your labels with BorderThickeness property set to 0...

<Style x:Key="MyLabelStyle" TargetType="{x:Type Label}">
    <Setter Property="BorderThickness" Value="0"/>
</Style>

<Viewbox Grid.Row="0"  Grid.Column="0">
    <StackPanel Name="letters" Orientation="Horizontal">
         <Label Style="{DynamicResource MyLabelStyle}"></Label>
               ...
    </StackPanel>
</Viewbox>


Anyway.. I should have asked if it's possible to have something constant size inside viewbox, that should have been more clear.

0

精彩评论

暂无评论...
验证码 换一张
取 消