2014-11-20 39 views
0

我在滾動查看器中有一個itemscontrol,隨着元素靠近屏幕中心,它變得更大。問題是,當它變大時,它的左上角被鎖定到位,它看起來像這樣。WPF-在項目控件中對齊內容

Not what I want

我希望它看起來像這樣,但我不知道如何去這樣做。

What I do want

編輯:新增XAML信息,如有需要,請索要C#(我雖然懷疑)

<TextBlock Name="text2" Text="hello" Margin="0,15,0,-10"/> 
    <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled"   Height="300" Name="Viewr" Canvas.Top="120" ScrollChanged="Viewr_ScrollChanged"> 
     <ItemsControl Name="viewrcontent"> 
      <Canvas Width="100" Height="100" Background="Red"/> 
      <Canvas Width="100" Height="100" Background="Red"/> 
      <Canvas Width="100" Height="100" Background="Red"/> 
      <Canvas Width="100" Height="100" Background="Red"/> 
      <Canvas Width="100" Height="100" Background="Orange" Name="hellobox"/> 
      <Canvas Width="100" Height="100" Background="Green" Name="midbox"/> 
      <Canvas Width="100" Height="100" Background="Black"/> 
      <Canvas Width="100" Height="100" Background="Red"/> 
      <Canvas Width="100" Height="100" Background="Red"/> 
      <Canvas Width="100" Height="100" Background="Red"/> 
      <Canvas Width="100" Height="100" Background="Red"/> 
      <Canvas Width="100" Height="100" Background="Black"/> 
      <ItemsControl.ItemContainerStyle> 
       <Style> 
        <Setter Property="FrameworkElement.Margin" Value="5"/> 
       </Style> 
      </ItemsControl.ItemContainerStyle> 
      <ItemsControl.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel Orientation="Horizontal" CanHorizontallyScroll="True"/> 
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
     </ItemsControl> 
    </ScrollViewer> 
+0

你可以發佈你的xaml嗎? – 2014-11-20 18:40:39

+0

對不起,xaml貼子 – Nivert9 2014-11-20 18:46:05

+0

Viewr_ScrollChanged做什麼?我認爲這是改變綠色項目?您爲我提供的滾動條的xaml很好,但是中心項目不會增加大小或其他任何內容,您正在嘗試執行哪項操作? – 2014-11-20 18:49:19

回答

1

如果應用ScaleTransformRenderTransform規模的項目,可以設置RenderTransformOrigin0.5,0.5,這將迫使項目規模在他們中間。

0

我認爲你可以在編輯保證金代碼隱藏,以獲得所需行爲。像這樣的東西可以工作:

midbox.Width += 10; 
midbox.Height += 10; 
midbox.Margin = new Thickness(midbox.Margin.Left - 5, midbox.Margin.Top, midbox.Margin.Right - 5, midbox.Margin.Bottom);