Reputation: 3731
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 :)
Upvotes: 0
Views: 1118
Reputation: 34240
You can use a Popup
to avoid increasing the size of the cell when the completions are visible. Here's a tutorial:
Upvotes: 2