2011-04-28 43 views
0

我想這是一個相當簡單的問題,但我已經花了相當長的時間弄清楚了。ContentControl及其子項 - 相同大小?

我有一個類,PresentationItem,它是從ContentControl派生的。我在Expression Blend中工作,這會給PresentationItem的高度和寬度帶來問題。

當我插入一個PresentationItem時,它會自動調整太大的網格尺寸(800x600)。然後,當我插入例如一個文本塊時,文本塊的大小變小。我認爲這是正常和預期的行爲。

我想要的是presentationitem和Content子項(例如文本塊)具有相同的大小。當我有幾個這樣的尺寸時,使用兩種不同的尺寸是令人討厭的。因此,無論是presentationitem內的內容應該被拉伸,還是presentationitem都應該調整大小以適合其子女。

(此外,使用ContentControl以外的其他內容不是選項)。

現在我有以下樣式:

<Style TargetType="local:JSLDPresentationItem"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="local:JSLDPresentationItem"> 
       <Border Background="{TemplateBinding Background}" 
         BorderBrush="{TemplateBinding BorderBrush}" 
         BorderThickness="{TemplateBinding BorderThickness}"> 
        <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="PresentationStates"> 
          <VisualStateGroup.Transitions> 
           <VisualTransition GeneratedDuration="0:0:0.3"/> 
          </VisualStateGroup.Transitions> 
          <VisualState x:Name="FocusedPresenting"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="1.2" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="LocalLayoutPanel" /> 
            <DoubleAnimation Duration="0" To="1.2" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="LocalLayoutPanel" /> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="AfterPresenting"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LocalLayoutPanel" /> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="BeforePresenting"> 
           <Storyboard> 
            <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LocalLayoutPanel" /> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="UnfocusedPresenting"/> 
         </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 

        <Grid x:Name="LocalLayoutPanel" Margin="0,0,0,0" VerticalAlignment="Top" > 

         <Grid.RenderTransform> 
          <CompositeTransform/> 
         </Grid.RenderTransform> 
         <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" /> 
        </Grid> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

改變什麼,在哪裏?我想這是一些「*」或「汽車」在正確的地方!

+0

看起來您需要重寫TextBlock的默認水平和垂直對齊。例如,嘗試將作爲內容而不是TextBlock。它是否擴大以填充內容演示者? – 2011-04-28 19:56:34

回答

1

嘗試將派生控件的Horizo​​ntalContentAlignment和VerticalContentAlignment設置爲Stretch。

相關問題