如何获得XAML列表视图与全行选择和正确的主题 [英] How to get XAML Listview with full-row selection and correct theme

查看:148
本文介绍了如何获得XAML列表视图与全行选择和正确的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我接手一些code,在它有一个XAML列表视图。我注意到有当前列表视图并不全行选择;也就是说,你不能在行中的任意位置单击选择一个项目,但必须按照文本所占用的区域中单击。展望这件事,我尝试添加一个Horizo​​ntalContentAlignment =拉伸到ItemContainerStyle,但现在的项目不再使用相同的主题,对话的其余部分(前pressionDark)。

I'm taking over some code that has a XAML Listview in it. I noticed the current Listview does not have full-row selection; that is, you cannot click anywhere in the row to select an item, but must click in the area occupied by the text. Looking this up, I tried adding a HorizontalContentAlignment="stretch" to the ItemContainerStyle, but now the items are no longer using the same theme as the rest of the dialog (ExpressionDark).

最初的XAML code:

The original XAML code:

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是这样的:

But when I added the ItemContainerStyle like this:

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,所以我不知道我在做什么错在这里。难道我莫名其妙地需要防爆pressionDark主题应用到ListView项目?任何帮助将大大AP preciated。

I'm new to XAML, so I'm not sure what I'm doing wrong here. Do I somehow need to apply the ExpressionDark theme to the Listview items? Any help would be greatly appreciated.

推荐答案

我有同样的问题。我所有的控件使用防爆pressionDark主题。

I've had the same problem. All of my controls uses ExpressionDark theme.

这是我如何解决这个问题:

This is how I solved this issue:

<ListBox HorizontalContentAlignment="Stretch">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid Background="Transparent">
                <!-- here is my custom content -->
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

这一切开始于Grid元素中加入背景=透明属性后,正常工作。

这篇关于如何获得XAML列表视图与全行选择和正确的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆