我正在接管一些包含 XAML Listview 的代码。我注意到当前的 Listview 没有全行选择;也就是说,您不能单击行中的任何位置来选择项目,而必须单击文本所占据的区域。查找此内容,我尝试将 HorizontalContentAlignment="stretch" 添加到 ItemContainerStyle,但现在这些项目不再使用与对话框其余部分相同的主题 (ExpressionDark)。
原始 XAML 代码:
Title="SelectUser" Height="350" Width="480" WindowStartupLocation="CenterScreen" WindowStyle="None" SizeToContent="Height" ResizeMode="NoResize">
<expressionDark:ExpressionDarkTheme>
<Border BorderBrush="DimGray" BorderThickness="2">
<StackPanel Margin="12,12,12,12">
<TextBlock FontSize="16" FontWeight="Bold" HorizontalAlignment="Center" Margin="0,0,0,12">Select User</TextBlock>
<ListView Name="listViewUsers" Height="200" Width="400" ItemsSource="{Binding}" SelectionChanged="listViewUsers_SelectionChanged">
<ListView.View>
<GridView>
<GridViewColumn Header="User Id" DisplayMemberBinding="{Binding Path=UserID}" Width="150"/>
<GridViewColumn Header="User Name" DisplayMemberBinding="{Binding Path=UserName}" Width="250"/>
</GridView>
</ListView.View>
</ListView>
<UniformGrid Height="23" Rows="1" Columns="2" Margin="0,16,0,12" Width="Auto">
<Button Name="buttonCancel" HorizontalAlignment="Center" Width="75" Height="23" IsCancel="True" Click="buttonCancel_Click">Cancel</Button>
<Button Name="buttonOK" HorizontalAlignment="Center" Width="75" Height="23" IsDefault="True" Click="buttonOK_Click">OK</Button>
</UniformGrid>
</StackPanel>
</Border>
</expressionDark:ExpressionDarkTheme>
但是当我像这样添加 ItemContainerStyle 时:
Title="SelectUser" Height="350" Width="480" WindowStartupLocation="CenterScreen" WindowStyle="None" SizeToContent="Height" ResizeMode="NoResize">
<expressionDark:ExpressionDarkTheme>
<Border BorderBrush="DimGray" BorderThickness="2">
<StackPanel Margin="12,12,12,12">
<TextBlock FontSize="16" FontWeight="Bold" HorizontalAlignment="Center" Margin="0,0,0,12">Select User</TextBlock>
<ListView Name="listViewUsers" Height="200" Width="400" ItemsSource="{Binding}" SelectionChanged="listViewUsers_SelectionChanged">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="User Id" DisplayMemberBinding="{Binding Path=UserID}" Width="150"/>
<GridViewColumn Header="User Name" DisplayMemberBinding="{Binding Path=UserName}" Width="250"/>
</GridView>
</ListView.View>
</ListView>
<UniformGrid Height="23" Rows="1" Columns="2" Margin="0,16,0,12" Width="Auto">
<Button Name="buttonCancel" HorizontalAlignment="Center" Width="75" Height="23" IsCancel="True" Click="buttonCancel_Click">Cancel</Button>
<Button Name="buttonOK" HorizontalAlignment="Center" Width="75" Height="23" IsDefault="True" Click="buttonOK_Click">OK</Button>
</UniformGrid>
</StackPanel>
</Border>
</expressionDark:ExpressionDarkTheme>
我是 XAML 的新手,所以我不确定我在这里做错了什么。我是否需要以某种方式将 ExpressionDark 主题应用于 Listview 项目?任何帮助将不胜感激。