Datagrid标头中的WPF自动完成文本框

编程入门 行业动态 更新时间:2024-10-25 08:18:08
本文介绍了Datagrid标头中的WPF自动完成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好

我有一个要求,我应该在Datagrid标头中有一个文本框,该文本框充当自动完成文本框.任何人都可以提供示例代码的帮助.

I got a requirement where I should have a textBox in Datagrid header which acts as a AutoComplete TextBox. Could anyone help with sample code.

此致

Padma

推荐答案

WPF中没有标准的自动填充文本框,您必须使用WPF工具包中的文本框,第三方供应商(例如Telerik),社区版本或您自己建立. www.codeproject/Articles/293954/AutoSuggest-and-AutoComplete-control-in-WPF

There is not a standard autocomplete textbox in WPF, you will have to use the one in the WPF Toolkit, a third party supplier like Telerik, a community version or build your own. www.codeproject/Articles/293954/AutoSuggest-and-AutoComplete-control-in-WPF

下面显示了如何将所有这些连接起来,在这种情况下使用标准TextBox.然后,您只需要弄清楚如何将其从DataGridColumnHeader这样的远程位置绑定回源.如果您使用代码隐藏的textchanged事件,则 只需为您的文本框指定名称,例如TextBoxColumn_1,TextBoxColumn_2,即可从事件发送者的名称中获取列号.

Below shows HOW you wire it all up, using in this case a standard TextBox. You then just need to work out how you're going to bind it from such a remote place as the DataGridColumnHeader, back to your source. If you use code-behind textchanged event, then simply give your textboxes names like TextBoxColumn_1, TextBoxColumn_2, so you can get the column number out of the event sender's name.

<Window.Resources> <Style x:Key="DataGridColumnHeaderStyle1" TargetType="{x:Type DataGridColumnHeader}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGridColumnHeader}"> <Grid VerticalAlignment="Center" HorizontalAlignment="Stretch"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="" HorizontalAlignment="Stretch"/> <Grid Grid.Row="1"> <TextBox Text="" HorizontalAlignment="Stretch" BorderThickness="1" /> </Grid> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid x:Name="LayoutRoot"> <DataGrid x:Name="dataGrid" Height="157" Width="600" Margin="8,8,24,0" VerticalAlignment="Top" AutoGenerateColumns="False" ColumnHeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}" ItemsSource="{Binding}" CanUserAddRows="False" > <DataGrid.Columns> <DataGridTextColumn Header="Header1" Binding="{Binding Id}" Width="100" /> <DataGridTextColumn Header="Header2" Binding="{Binding Name}" Width="100"/> </DataGrid.Columns> </DataGrid> </Grid> </Window>

祝你好运!

Pedro

更多推荐

Datagrid标头中的WPF自动完成文本框

本文发布于:2023-11-09 15:56:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572794.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   自动完成   Datagrid   标头中   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!