WPF 動態數據綁定 橫向佈局 豎向佈局

一、豎向佈局

<ItemsControl ItemsSource="{Binding MenuList}" x:Name="itemsControl">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Button Margin="0" Command="{Binding DataContext.AddTabItemCommand,ElementName=frmWorkstation}" CommandParameter="{Binding Param}" Padding="0" BorderThickness="0" Height="80" 
                                    HorizontalContentAlignment="Center" BorderBrush="Transparent" Cursor="Hand" >
                                        <StackPanel Height="80" Width="80" Orientation="Vertical">
                                            <Image Margin="0,10,0,0" Width="40" Height="40" Source="{Binding Icons}"/>
                                            <TextBlock Margin="0,10,0,10" FontSize="13" Text="{Binding Title}" HorizontalAlignment="Center"/>
                                        </StackPanel>
                                    </Button>
                                    
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

二、橫向佈局

<ListBox ItemsSource="{Binding FileList}" x:Name="fjList" BorderThickness="0">
                                                    <ListBox.ItemsPanel>
                                                        <ItemsPanelTemplate>
                                                            <VirtualizingStackPanel Orientation="Horizontal"/>
                                                        </ItemsPanelTemplate>
                                                    </ListBox.ItemsPanel>
                                                    <ListBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <Button Margin="0" Foreground="Blue" Command="{Binding DataContext.FilePreviewCommand,ElementName=fjList}" CommandParameter="{Binding Fjid}" Padding="0" 
                                                                   HorizontalContentAlignment="Center" BorderBrush="Transparent" Cursor="Hand" Content="{Binding Wjm}"/>
                                                           
                                                        </DataTemplate>
                                                    </ListBox.ItemTemplate>
                                                </ListBox>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章