2010-08-11 126 views
0

我已經爲單詞「Width」沖刷了我的XAML文件,並且它僅在根元素處顯示一個數字作爲值,並設置了整個控件的寬度。 「高度」一詞只在根元素處有一個數字值,兩個文本框與下面的複選框不在同一個網格單元格中。WPF無法調整控件的大小

不幸的是,無論我在高度和寬度的用戶控件元素設置的值,下面的複選框沒有得到更大:

在WPF元素
<Style x:Key="CheckBoxStyle1" TargetType="CheckBox"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="CheckBox"> 
         <Grid ToolTipService.ToolTip=""> 
          <VisualStateManager.VisualStateGroups> 
           <VisualStateGroup x:Name="CheckStates"> 
            <VisualState x:Name="Checked"> 
             <Storyboard> 
              <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="path" d:IsOptimized="True"/> 
             </Storyboard> 
            </VisualState> 
            <VisualState x:Name="Unchecked"/> 
            <VisualState x:Name="Indeterminate"/> 
           </VisualStateGroup> 
          </VisualStateManager.VisualStateGroups> 
          <Image x:Name="lightbulb" Source="BestLogin_Images/lightbulb.png" ToolTipService.ToolTip=""/> 
          <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="140,0,0,0" Content="" ToolTipService.ToolTip=""/> 
          <Path x:Name="path" Data="M41.75,5.5 L53.75,2.25 L58.5,0.75 L65.75,1.5 L73,3.75 L83.25,8.25 L88.5,13.25 L95.5,21 L102,33.75 L102.5,44.5 L97.5,59.25 L90.25,74.75 L86.5,82.5 L84.25,91.5 L83.75,96.5 L79.5,104.25 L79.75,108.75 L78.5,113.25 L80,114.5 L79.75,119.75 L79,126 L76.75,132 L74.5,134.5 L68.75,140.5 L65,142 L64.53125,143.125 L62.75,144.75 L61.4375,145.59375 L57.71875,145.90601 L55.15625,143.46875 L53.4375,142.40625 L50.625,141.46875 L47.15625,137.34375 L43.5,135 L40.375,129.84375 L39.5,128.53125 L40.4375,127.375 L41.25,126.09375 L41.15625,124.78125 L39.15625,123.65625 L39.343998,121.5625 L39.343998,116.15625 L39.406498,111.3125 L38.750252,104.90625 L35.583599,99.791664 L35.292271,91.125 L33.375278,80.75 L31.54195,77.583336 L26.791613,69.75 L21.332918,59.541668 L19.874918,56.25 L19.08325,37.708332 L19.37525,36.75 L21.750242,27.333334 L27.041893,18.416666 L31.79188,11.833333 L37.416862,7.0833335 L38.791859,6.5833335 z" HorizontalAlignment="Left" Margin="19.083,0.75,0,18.094" Stretch="Fill" Fill="#B2FFF500" Opacity="0" ToolTipService.ToolTip="Click me to light up your day."/> 
         </Grid> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
...snip...(Grid layout)  
<CheckBox Content="CheckBox" Style="{StaticResource CheckBoxStyle1}" HorizontalAlignment="Left" VerticalAlignment="Stretch" Grid.Row="2" Name="CheckBox1" /> 
+0

嗯,說實話,我不明白爲什麼它應該變大。 – 2010-08-11 01:26:31

+0

我都沒有,但是試着把它放在ViewBox中 – Carlo 2010-08-11 02:04:33

回答

1

尺寸由不僅僅是寬度和確定高度。您還需要考慮所有對齊設置:Horizo​​ntalAlignment,VerticalAlignment,有時還有Horizo​​ntalContentAlignment和VerticalContentAlignment,以及用於排列元素的佈局面板。在這裏你已經將CheckBox左對齊,所以它不會得到比它所需的最小寬度更大的寬度。您沒有包含Grid XAML,但我懷疑CheckBox的Row可能被設置爲Height =「Auto」,但是我不能確定沒有看到佈局的其餘部分。

+0

對於稍後在這個線程中絆倒的人,有兩個部分參與: 1.閱讀你的佈局中水平/垂直對齊的工作方式。 2.通過並確保應該增長的內容使用星號(*)單位而不是數字。 – 2010-08-11 19:44:10