我正在尋找一種方法來「完全填充」一個組合框GridViewColumn
。我可以用ComboBox
創建一個單元格模板,它工作正常。但是ComboBox
的寬度和高度與GridViewColumn
不一致。 即使我試圖設置相同的高度/寬度GridViewColumn
隱藏組合框的某些部分。如何用ComboBox(WPF)「填充」一個GridViewColumn?
必須有一些設置或樣式指示WPF完全充滿ComboBox
在GridViewColumn
可用空間這是我的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>
謝謝。這工作正常,但它仍然留下組合和細胞邊界之間的一些餘地。有沒有辦法消除這種情況? – 2010-08-19 13:18:19
您可以嘗試更改ControlTemplate: http://msdn.microsoft.com/en-us/library/ms788717.aspx – HCL 2010-08-19 14:10:39
謝謝,此鏈接有幫助。將您的答案標記爲解決方案。 – 2010-08-20 07:05:59