如何与QUOT;填写"与组合框(WPF)一GridViewColumn? [英] How to "Fill" a GridViewColumn with ComboBox (WPF)?

查看:131
本文介绍了如何与QUOT;填写"与组合框(WPF)一GridViewColumn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方式来填满一个 GridViewColumn 与组合框。我能够创建组合框细胞模板,它工作正常。但宽度和组合框的高度不与 GridViewColumn 对齐。
即使我尝试设置相同的高度/宽度 GridViewColumn 隐藏组合框的某些部分。

必须有一些设置或样式指示WPF填补了组合框完全 GridViewColumn 的可用空间

这是我的XAML。

 <窗​​口x:类=WPFStarter.ComboInsideListView.ComboBoxInsideListViewUsingObject
        X:名称=用户控件
        的xmlns =htt​​p://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
        的xmlns:X =htt​​p://schemas.microsoft.com/winfx/2006/xaml
        标题=ComboBoxInsideListViewUsingObjectHEIGHT =300WIDTH =400>
    <网格和GT;
        < ListView的X:名称=ListView控件的ItemsSource ={绑定的ElementName =用户控件,
            路径= DataContext.Items}的SelectedItem ={绑定的ElementName =用户控件,路径= DataContext.SelectedItem,模式=双向}>
            < ListView.View>
                <&GridView的GT;
                   < GridViewColumn标题=名DisplayMemberBinding ={绑定路径=第一}/>
                   < GridViewColumn标题=性别>
                        < GridViewColumn.CellTemplate>
                            <&DataTemplate的GT;
                                <组合框X:​​NAME =cmb_GenderWIDTH =75的SelectedValue ={绑定路径=性别}
                  的ItemsSource ={绑定的ElementName =用户控件,路径= DataContext.Genders}的GotFocus =ComboBox_GotFocus/>
                            < / DataTemplate中>
                        < /GridViewColumn.CellTemplate>
                    < / GridViewColumn>
                < / GridView的>            < /ListView.View>        < /&的ListView GT;
    < /网格和GT;
< /窗GT;


解决方案

包括以下内容风格融入列表视图资源。然后你就可以ComboBox的的Horizo​​ntalAlignment属性设置为的Horizo​​ntalAlignment =拉伸,它会做如你所愿:

 < ListView.Resources>
          <风格的TargetType =ListViewItem的>
                < setter属性=Horizo​​ntalContentAlignmentVALUE =弹力/>
          < /样式和GT;
 < /ListView.Resources>

I am looking for a way to "completely fill" a GridViewColumn with a combo box. I am able to create a cell template with ComboBox and it is working fine. But the width and height of ComboBox is not aligned with the GridViewColumn. Even if I try to set the same height/width GridViewColumn hides some part of the comboBox.

There must be some setting or style to instruct WPF to fill the ComboBox completely in the available space of GridViewColumn

This is my XAML.

<Window x:Class="WPFStarter.ComboInsideListView.ComboBoxInsideListViewUsingObject"
        x:Name="userControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="ComboBoxInsideListViewUsingObject" Height="300" Width="400">
    <Grid>
        <ListView x:Name="listView" ItemsSource="{Binding ElementName=userControl, 
            Path=DataContext.Items}" SelectedItem="{Binding ElementName=userControl, Path=DataContext.SelectedItem, Mode=TwoWay}">                   
            <ListView.View>
                <GridView>
                   <GridViewColumn Header="First Name"  DisplayMemberBinding="{Binding Path=First}"/>
                   <GridViewColumn Header="Gender">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <ComboBox x:Name="cmb_Gender" Width="75" SelectedValue="{Binding Path=Gender}"                    
                  ItemsSource="{Binding ElementName=userControl, Path=DataContext.Genders}" GotFocus="ComboBox_GotFocus"         />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>

            </ListView.View>

        </ListView>
    </Grid>
</Window>

解决方案

Include the following style into the ListViews-resources. Then you can set the HorizontalAlignment-property of the ComboBox to HorizontalAlignment="Stretch" and it will do as you wish:

 <ListView.Resources>
          <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
          </Style>
 </ListView.Resources>

这篇关于如何与QUOT;填写&QUOT;与组合框(WPF)一GridViewColumn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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