0
我現在面臨的問題標籤與WPF DataGrid
DataGridTemplateColumn
。我需要標籤兩次獲得焦點的控制裝置與DataGridTemplateColumn
。我嘗試以下方式與本網站針對此問題規定。但是我的問題仍然沒有解決。WPF Datagrid的DataGridTemplateColumn標籤焦點問題
<my:DataGrid AutoGenerateColumns="False" Name="dgCB" Margin="8,32,0,0" SelectionMode="Single" GridLinesVisibility="All" FontSize="13" SelectionUnit="Cell"
KeyboardNavigation.TabNavigation="Continue" CanUserAddRows="False" CanUserDeleteRows="False"
EnableColumnVirtualization="True" VerticalAlignment="Top"
RowDetailsVisibilityMode="VisibleWhenSelected"
IsSynchronizedWithCurrentItem="True"
CanUserSortColumns="False"
CanUserReorderColumns="False"
CanUserResizeColumns="True"
CanUserResizeRows="True"
HorizontalAlignment="Left"
Width="964"
Height="416">
<my:DataGrid.Columns>
<my:DataGridTemplateColumn Header="Tis">
<my:DataGridTemplateColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
</Style>
</my:DataGridTemplateColumn.CellStyle>
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Name="txtC" PBOValidation:TextBoxMaskBehavior.Mask="Integer" LostFocus="txtC_LostFocus" Text="{Binding Path=TIME}" GotKeyboardFocus="txtC_GotKeyboardFocus"></TextBox>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>
在代碼後面的文件我寫了如下的事件處理程序。
private void txtC_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
try
{
((TextBox)sender).SelectAll();
}
catch { }
}
private void txtC_LostFocus(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(((System.Windows.Controls.TextBox)(sender)).Text.Trim()))
{
((System.Windows.Controls.TextBox)(sender)).Text = 0.ToString();
}
}
但是還是我的問題不解決,我得到以下錯誤:
'DataGridCell' targettype does not match type of element 'DataGridCell'
請幫我解決我的標籤的焦點問題。
喜,謝謝你的答覆。我在我的示例應用程序中添加了你的代碼。我遇到了setter屬性的問題。我改變了setter屬性,如下所示。 – user5668833
您是否在上述評論中發佈了評論? – user1672994
嗨,謝謝你的答覆。我在我的示例應用程序中添加了你的代碼。我遇到了setter屬性的問題。我改變了setter屬性,如下所示。 <形式X:鍵= 「DataGridCellSingleClickEditStyle」 的TargetType = 「{x:類型DataGridCell}」> 我正類型 'PBO:DataGridCellSingleClickEditDependency'沒有找到。我在名稱空間PBO下添加了您的類。請幫助我解決我的問題。應該在XAML中定義 –
user5668833