[英]How to change textbox enable in a listview item by double click in WPF
我正在嘗試通過雙擊項目來編輯列表視圖項目內容(文本框),並且我希望能夠編輯列表視圖項目文本框。
這是我的 xaml
<ListView.View>
<GridView >
<GridView.Columns>
<GridViewColumn Header="ID" Width="50" DisplayMemberBinding="{Binding ID}"/>
<GridViewColumn Header="scanned Text" Width="380">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Tag="{Binding Index}" Name="itemTextBox" Text="{Binding scannedText}" BorderBrush="{x:Null}" BorderThickness="0" FontSize="16" Focusable="False">
</TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<EventSetter Event="MouseDoubleClick" Handler="listViewItem_MouseDoubleClick" />
</Style>
</ListView.ItemContainerStyle>
所以我猜你還沒有真正嘗試過? 如果您有,請也發布您的嘗試!
將 MouseDoubleClick 事件添加到您的文本框並在您的代碼中嘗試這樣的操作:
private void TextBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
sender.Focusable = true;
sender.Focus();
//These two lines prevent the Cursor to change and the border showing after clicking once and make them appear/change after the double click
sender.Cursor = Cursors.IBeam;
sender.BorderThickness = new Thickness(1);
}
我想你想在編輯后取消焦點,所以我建議使用以下代碼添加一個 LostFocus 事件:
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
Keyboard.ClearFocus();
sender.Focusable = false;
//These two lines prevent the Cursor to change and the border showing after clicking once and make them appear/change after the double click
sender.Cursor = Cursors.Arrow;
sender.BorderThickness = new Thickness(0);
}
我希望這適用於 ListView
~貝爾迪
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.