WPF - 调整 Column/Row 对齐方式
WPF - Resizing Column/Row aligment
我想在 WPF (2) 中创建一个列表视图,它在调整大小时不会更改列和行之间的间距,但会自动更改列数以适应。
我有:
我想要什么
代码:
<Window x:Class="WPFApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test1" Height="800" Width="1000" Loaded="Window_Loaded" Closing="Window_Closing">
<Window.Resources>
<DataTemplate x:Key="ItemTemplate">
<WrapPanel>
<Grid>
<Border BorderThickness="3" BorderBrush="#FF000000" VerticalAlignment="Top">
<Image Width="200" Height="300" Stretch="Fill" DataContext="{DynamicResource Image}" Source="{Binding Image}"/>
</Border>
<Image HorizontalAlignment="Right" VerticalAlignment="Top" DataContext="{DynamicResource Data}" Source="{Binding Status}" Height="100"/>
</Grid>
</WrapPanel>
</DataTemplate>
</Window.Resources>
<Grid x:Name="mainGrid" Margin="0,81,0,0">
<ListView HorizontalContentAlignment="Left" VerticalContentAlignment="Top" Name="View" ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Path = DataList}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Margin" Value="5"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</Grid>
我找到了一个解决方案,我改变了这个:
<ItemsPanelTemplate>
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
对此:
<ItemsPanelTemplate>
<UniformGrid VerticalAlignment="Top" HorizontalAlignment="Left" Columns="3"/>
</ItemsPanelTemplate>
我想在 WPF (2) 中创建一个列表视图,它在调整大小时不会更改列和行之间的间距,但会自动更改列数以适应。
我有:
我想要什么
代码:
<Window x:Class="WPFApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test1" Height="800" Width="1000" Loaded="Window_Loaded" Closing="Window_Closing">
<Window.Resources>
<DataTemplate x:Key="ItemTemplate">
<WrapPanel>
<Grid>
<Border BorderThickness="3" BorderBrush="#FF000000" VerticalAlignment="Top">
<Image Width="200" Height="300" Stretch="Fill" DataContext="{DynamicResource Image}" Source="{Binding Image}"/>
</Border>
<Image HorizontalAlignment="Right" VerticalAlignment="Top" DataContext="{DynamicResource Data}" Source="{Binding Status}" Height="100"/>
</Grid>
</WrapPanel>
</DataTemplate>
</Window.Resources>
<Grid x:Name="mainGrid" Margin="0,81,0,0">
<ListView HorizontalContentAlignment="Left" VerticalContentAlignment="Top" Name="View" ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Path = DataList}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Margin" Value="5"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</Grid>
我找到了一个解决方案,我改变了这个:
<ItemsPanelTemplate>
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
对此:
<ItemsPanelTemplate>
<UniformGrid VerticalAlignment="Top" HorizontalAlignment="Left" Columns="3"/>
</ItemsPanelTemplate>