DataTemplate 溢出数据网格单元
我的数据网格有一点问题。我正在尝试实现一个自动完成文本框[如上所述此处]。到目前为止,它工作得很好,唯一的问题是它溢出了分配的列空间,因此它变得更大。我不希望这种情况发生,换句话说,我希望自动完成条目的列表框“浮动”在数据网格上,这样它就不会溢出单元格分配的空间。 [我知道这是可能的,因为我以前见过类似的事情,所以我认为这是可行的]。
XAML:
<Window x:Class="LDary.Compras"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Compras" Height="300" Width="300" Name="WinCompras">
<Window.Resources>
<CollectionViewSource Source="{Binding ElementName=WinCompras, Path=AutoCSource}" x:Key="Source" Filter="CollectionViewSource_Filter" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="Articulos de la compra:" Padding="0,2"/>
<DataGrid Grid.Row="1" AutoGenerateColumns="False" x:Name="Lista" CanUserAddRows="True" ItemsSource="{Binding ElementName=WinCompras, Path=CompraActual}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Nombre" x:Name="Nombre">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Nombre}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<StackPanel>
<TextBox Text="{Binding Nombre}" TextChanged="TextBox_TextChanged" Loaded="TextBox_Loaded" Unloaded="TextBox_Unloaded"/>
<ListBox Visibility="Hidden" ItemsSource="{Binding Source={StaticResource Source}}"
Focusable="False" Loaded="ListBox_Loaded" Unloaded="ListBox_Unloaded">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Nombre}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<Button Name="BtnGuardar" Content="Guardar" Padding="0,5" Grid.Row="2" />
<Button Name="BtnReset" Content="Reiniciar" Padding="0,5" Grid.Row="3" />
</Grid>
</Window >
提前致谢:)
I have a little problem with the Datagrid. I am trying to implement an auto-complete textbox [As described here] in a DataGridCellTemplate. It is working perfectly so far, only problem is it overflows the assigned column space so it is made a lot bigger. I dont want this to happen, in other words, i want the listbox for the auto-complete entries to "float" over the datagrid, so it wont overflow the cell's assigned space. [I know its possible because i seen similar things before, so i think this is do-able].
XAML:
<Window x:Class="LDary.Compras"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Compras" Height="300" Width="300" Name="WinCompras">
<Window.Resources>
<CollectionViewSource Source="{Binding ElementName=WinCompras, Path=AutoCSource}" x:Key="Source" Filter="CollectionViewSource_Filter" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="Articulos de la compra:" Padding="0,2"/>
<DataGrid Grid.Row="1" AutoGenerateColumns="False" x:Name="Lista" CanUserAddRows="True" ItemsSource="{Binding ElementName=WinCompras, Path=CompraActual}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Nombre" x:Name="Nombre">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Nombre}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<StackPanel>
<TextBox Text="{Binding Nombre}" TextChanged="TextBox_TextChanged" Loaded="TextBox_Loaded" Unloaded="TextBox_Unloaded"/>
<ListBox Visibility="Hidden" ItemsSource="{Binding Source={StaticResource Source}}"
Focusable="False" Loaded="ListBox_Loaded" Unloaded="ListBox_Unloaded">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Nombre}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<Button Name="BtnGuardar" Content="Guardar" Padding="0,5" Grid.Row="2" />
<Button Name="BtnReset" Content="Reiniciar" Padding="0,5" Grid.Row="3" />
</Grid>
</Window >
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
Popup
来避免在完成可见时增加单元格的大小。这是一个教程:You can use a
Popup
to avoid increasing the size of the cell when the completions are visible. Here's a tutorial: