2009-07-16 154 views
1

我是新來的WPF。我有一個WPF窗口,上面有一堆標籤以及一個ListBox。WPF/XAML - 將文本大小縮放到窗口大小

調整窗口大小時,我想縮放某些標籤的大小,但不是全部。我不希望ListBox縮放 - 只是一些標籤。

我知道我可以使用一個Viewbox來調整窗口的大小調整大小,但儘管如此,我沒有得到預期的效果。當然,我無法用Viewbox來包圍整個事物,因爲這會調整一切,所以我想我必須在圍繞每個我想要展開的標籤的窗口中放置一堆不同的Viewbox。但是,當然,當我這樣做時,什麼都沒有擴大。

沿着相同的路線,當我擴展標籤時,還有其他標籤需要保留在這些標籤旁邊,因爲它們是標識符。

所以...這裏是我在這一點上的XAML。我甚至不知道我是否在正確的道路上。任何幫助使與他們的數字標籤擴大與窗口,將不勝感激。

<Window x:Class="WpfApplication7.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:WpfApplication7" 
    Title="Window1"> 
    <StackPanel Orientation="Horizontal"> 
     <ListBox Margin="2"> 
      <ListBoxItem>a</ListBoxItem> 
      <ListBoxItem>b</ListBoxItem> 
      <ListBoxItem>c</ListBoxItem> 
     </ListBox> 
     <StackPanel Orientation="Vertical"> 
      <Label>Title</Label> 
      <StackPanel Orientation="Horizontal"> 
       <Grid> 
        <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions> 
        <Label Grid.Row="0">A</Label> 
        <Label Grid.Row="1">B</Label> 
        <Label Grid.Row="2">C</Label> 
        <Label Grid.Row="3">D</Label> 
       </Grid> 
       <Grid> 
        <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions> 
        <Viewbox Grid.Row="0" Stretch="Fill"> 
         <Label>1</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="1" Stretch="Fill"> 
         <Label>2</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="2" Stretch="Fill"> 
         <Label>3</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="3" Stretch="Fill"> 
         <Label>4</Label> 
        </Viewbox> 
       </Grid> 
       <Grid> 
        <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions> 
        <Viewbox Grid.Row="0" Stretch="Fill"> 
         <Label>5</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="1" Stretch="Fill"> 
         <Label>6</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="2" Stretch="Fill"> 
         <Label>7</Label> 
        </Viewbox> 
        <Viewbox Grid.Row="3" Stretch="Fill"> 
         <Label>8</Label> 
        </Viewbox> 
       </Grid> 
       <Grid> 
        <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions> 
        <Label Grid.Row="0">E</Label> 
        <Label Grid.Row="1">F</Label> 
        <Label Grid.Row="2">G</Label> 
        <Label Grid.Row="3">H</Label> 
       </Grid> 
      </StackPanel> 
     </StackPanel> 
    </StackPanel> 
</Window> 

+0

做我修復爲你工作?你還沒有選擇答案。 – Charlie 2009-07-17 23:17:02

回答

2

你是在正確的道路上。但是,您需要使用某些列定義,並且您的行定義有點不可靠。您正在使用大量嵌入對方的不同佈局面板,這會影響Viewbox內置調整大小。您可以用一個簡單的5x5網格(無堆棧面板)完成同樣的佈局。

我在下面的XAML證明了這一點:

<Window x:Class="TestWpfApplication.Window1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="clr-namespace:TestWpfApplication" 
Title="Window1"> 
<Window.Resources> 
    <Style TargetType="{x:Type Label}" x:Key="{x:Type Label}"> 
     <Setter Property="HorizontalAlignment" Value="Center"/> 
     <Setter Property="VerticalAlignment" Value="Center"/> 
    </Style> 
</Window.Resources> 

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition/> 
     <RowDefinition/> 
     <RowDefinition/> 
     <RowDefinition/> 
     <RowDefinition/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
    </Grid.ColumnDefinitions> 

    <ListBox Grid.RowSpan="5" Grid.Column="0"> 
     <ListBoxItem>a</ListBoxItem> 
     <ListBoxItem>b</ListBoxItem> 
     <ListBoxItem>c</ListBoxItem> 
    </ListBox> 

    <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4">Title</Label> 

    <Label Grid.Row="1" Grid.Column="1">A</Label> 
    <Label Grid.Row="2" Grid.Column="1">B</Label> 
    <Label Grid.Row="3" Grid.Column="1">C</Label> 
    <Label Grid.Row="4" Grid.Column="1">D</Label> 

    <Viewbox Grid.Row="1" Grid.Column="2"> 
     <Label>1</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="2" Grid.Column="2"> 
     <Label>2</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="3" Grid.Column="2"> 
     <Label>3</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="4" Grid.Column="2"> 
     <Label>4</Label> 
    </Viewbox> 

    <Viewbox Grid.Row="1" Grid.Column="3"> 
     <Label>5</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="2" Grid.Column="3"> 
     <Label>6</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="3" Grid.Column="3"> 
     <Label>7</Label> 
    </Viewbox> 
    <Viewbox Grid.Row="4" Grid.Column="3"> 
     <Label>8</Label> 
    </Viewbox> 

    <Label Grid.Row="1" Grid.Column="4">E</Label> 
    <Label Grid.Row="2" Grid.Column="4">F</Label> 
    <Label Grid.Row="3" Grid.Column="4">G</Label> 
    <Label Grid.Row="4" Grid.Column="4">H</Label> 
</Grid>