2016-06-15 45 views
1

我不知道如何在運行時在gridview中調整項目大小和textblock的字體大小?我不知道如何改變Item的屬性。我應該在我的「ProductDataTemplate」中使用DependencyProperties嗎?在運行時將gridview的項目大小調整爲窗口大小

<Page x:Name="page" 
x:Class="app.SearchPage" 

...

<Page.Resources> 
    <ResourceDictionary> 
     <DataTemplate x:Key="ProductDataTemplate"> 
      <Grid Background="Gray" Width="480" Height="360"> 
       <Image Source="{Binding LargeThumbnail}"/> 
       <Border Background="#A5000000" Height="120" VerticalAlignment="Top"> 
        <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Title}" VerticalAlignment="Top" Style="{StaticResource SubheaderTextBlockStyle}" Margin="5,0" FontSize="12" Foreground="White"/> 
       </Border> 
      </Grid> 
     </DataTemplate> 
    </ResourceDictionary> 
</Page.Resources> 
<Page.DataContext> 
    <local:DataSource/> 
</Page.DataContext> 

...

<Grid x:Name="grid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" > 
     <ScrollViewer x:Name="scroll" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible"> 
      <GridView x:Name="gridresult" ItemTemplate="{StaticResource ProductDataTemplate}" ItemsSource="{Binding Miniatures}" Margin="0,10,0,0" ItemClick="gridresult_ItemClick" IsItemClickEnabled="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" SizeChanged="gridresult_SizeChanged"> 
       <GridView.ItemsPanel> 
        <ItemsPanelTemplate> 
         <ItemsWrapGrid Orientation="Horizontal"/> 
        </ItemsPanelTemplate> 
       </GridView.ItemsPanel> 
      </GridView> 
     </ScrollViewer> 
    </Grid> 

回答

0

你可以綁定在ItemsWrapGridItemWidthItemHeight到視圖模型的性能。將該視圖模型作爲資源添加到頁面中,並將綁定的Source設置爲StaticResource。事情是這樣的:

<Page.Resources> 
    <ResourceDictionary> 
     <local:PageSizeViewModel 
      x:Key="PageSizeViewModel" /> 

...

<GridView.ItemsPanel> 
    <ItemsPanelTemplate> 
     <ItemsWrapGrid 
      ItemWidth="{Binding ItemWidth, Source={StaticResource PageViewModel}" 
      ItemHeight="{Binding ItemHeight, Source={StaticResource PageViewModel}" 
      Orientation="Horizontal"/> 
    </ItemsPanelTemplate> 
</GridView.ItemsPanel> 

然後你就可以在你的PageSizeViewModel您的網頁被調整更改這些屬性。

這個問題類似:GridView with 2 columns, fill width

+0

好吧,謝謝你,但我怎麼能修改DataTemplate中的控件的屬性,如TextBlock中的字號? – bkdi

+0

「編輯」是什麼意思?你可以在你的'DataTemplate'中的任何文本編輯器中鍵入它們... –

+0

我的意思是在運行時改變FontSize的值?當用戶更改窗口的大小時,我想調整項目和字體大小。 – bkdi

相關問題