我正在创建一个在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=">Enter Name<"/> </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焦点在数据网格中
发布评论