WPF Popup焦点在数据网格中

编程入门 行业动态 更新时间:2024-10-26 21:36:36
本文介绍了WPF Popup焦点在数据网格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个在DataGrid编辑模板中使用的自定义UserControl。 它看起来像这样:

I'm creating a custom UserControl to be used inside a DataGrid editing template. It looks like this:

<UserControl x:Class="HR.Controls.UserPicker" xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:tk="schemas.microsoft/wpf/2008/toolkit" xmlns:x="schemas.microsoft/winfx/2006/xaml"> <Grid> <TextBlock x:Name="PART_TextBox" Text="Hello WOrld" /> <Popup Width="234" Height="175" IsOpen="True" StaysOpen="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" > <TextBox x:Name="searchTextBox" Text="&gt;Enter Name&lt;"/> </Popup> </Grid> </UserControl>

编辑: 我缩小了代码位。 似乎如果我将一个Popup与文本框直接在CellEditingTemplate内直接文本框获得焦点没有问题。当我将该代码移动到UserControl中时,编辑单元格时,我无法再选择文本框。

edit: I've narrowed down the code a bit. It seems that if I put a Popup with textbox inside the CellEditingTemplate directly the textbox gets focus no problem. When I move that code into a UserControl I can no longer select the textbox when editing the cell.

UserControl是否与焦点有趣?

Is the UserControl doing something funny with the focus ?

问题是当我编辑datagrid中的单元格时,我看到用户控件显示,但是我无法点击TextBox searchTextBox。当我点击它,弹出窗口关闭,单元格恢复到默认状态。

The problem is when i edit the cell in the datagrid I get the user control showing up but I can't click in the TextBox searchTextBox. When I click on it the popup closes and the cell goes back to default.

我已经尝试复制并粘贴用户控件中的所有代码,并将其直接粘贴到CellEditingTemplate,并且它的交互方式应该。

I have tried copying and pasting all the code inside the user control and pasting it directly into the CellEditingTemplate and that interacts the way it should.

我只是想知道UserControl是否有一些奇怪的事情,阻止弹出窗口获得焦点,因为它直接放在CellEditingTemplate?

I was just wondering if the UserControl did something weird that prevents a popup from gaining focus because it works as expected when directly placed in the CellEditingTemplate ?

谢谢, Raul

Thanks, Raul

推荐答案

不知道这是否会帮助任何人,但是如果您在datagrid中有一个弹出窗口的自定义控件,这有助于此修复我的问题,而且是xaml的一行。我花了一整天重新阅读这个论坛,然后查看DataGridCell的来源。希望这有帮助。

Not sure if this will help anyone, but this helps if you have custom controls in the datagrid with a popup..... this fixed my problem, and it was one line of xaml. I spend the whole day re-reading this forum and then looking at the source for DataGridCell. Hope this helps.

<Style TargetType="{x:Type DataGridCell}"> <Setter Property="Focusable" Value="False"></Setter> </Style>

更多推荐

WPF Popup焦点在数据网格中

本文发布于:2023-10-06 19:41:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467630.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   焦点   数据   WPF   Popup

发布评论

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

>www.elefans.com

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