wpf - Select ListBoxItem if TextBox in ItemTemplate gets focus -


I added the DataTemplate to bind the ListBox class Is I name = "lstEmails" height = "259" margin = "12,0,12,41" width = "276" SelectionChanged = "lstEmails_SelectionChanged" & gt; ListBox X

  & lt; to archive; & Lt; ListBox.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; StackPanel Orientation = "Horizontal" & gt; & Lt; Label visibility = "hidden" content = "{binding ID}" & gt; & Lt; / Labels & gt; & Lt; Text box width = "200" text = "{binding email address}" & gt; & Lt; / Textbox & gt; & Lt; / StackPanel & gt; & Lt; / DataTemplate & gt; & Lt; /ListBox.ItemTemplate> & Lt; / ListBox & gt;  

This does what I should do. However when I click on Textbox , then ListBox is automatically set to ListItem as the selected does not do. I could do this in code, but I like to use it as a component (there is no wonder).

Any ideas about how to achieve this?


It does not seem to work, it will not let me click on anything. Did I miss something, here's my new XML.

  & lt; UserControl.Resources & gt; & Lt ;! - & lt; Text box x: key = "TB" x: name = "text box insidelistbox item" & gt; & Lt; TextBox.Style & gt; - & gt; & Lt; Style TargetType = "{x: type text box}" & gt; & Lt; Setter Property = "IhiteTestVisible" value = "False" /> & Lt; Style.Triggers & gt; & Lt; DataTrigger Binding = "{IsSelected Binding, RelativeSource = {RelativeSource FindAncestor, AncestorType = {x: Type ListBoxItem}, AncestorLevel = 1}}" Value = "True" & gt; & Lt; Setter Property = "IhiteTestVisible" Value = "True" /> & Lt; / DataTrigger & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; -! & Lt; /TextBox.Style> & Lt; / Text box & gt; - & gt; & Lt; /UserControl.Resources> & Lt; Grid & gt; & Lt; ListBox x: name = "lstEmails" height = "259" margin = "12,0,12,41" width = "276" selection switch = "lstEmails_SelectionChanged" & gt; & Lt; ListBox.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; StackPanel Orientation = "Horizontal" & gt; & Lt ;! - & lt; Label visibility = "hidden" content = "{binding ID}" & gt; & Lt; / Labels & gt; - & gt; & Lt; Width of text box = "220" text = "{binding email address}" & gt; & Lt; / Text box & gt; & Lt; -! & Lt; Text box width = "220" text = "{EmailAddress binding}" GotFocus = "TextBox_GotFocus" & gt; & Lt; / Text box & gt; - & gt; & Lt; / StackPanel & gt; & Lt; / DataTemplate & gt; & Lt; /ListBox.ItemTemplate> & Lt; / ListBox & gt; & Lt; Button width = "20" margin = "12,0,0,12" name = "btnAdd" VerticalAlignment = Click "Below" = "btnAdd_Click" height = "23" HorizontalAlignment = "Left" & gt; + & Lt; / Button & gt; & Lt; Button width = "20" HorizontalAlignment = "left" margin = "30,0,0,12" name = "btnRemove" VerticalAlignment = Click "Below" = "btnRemove_Click" height = "23" & gt; - & lt; / Button & gt; & Lt; Button height = "23" HorizontalAlignment = "right" margin = "0,0,12,12" name = "btnApply" VerticalAlignment = "down" width = "49" = "btnApply_Click" & gt; Apply & lt; / Button & gt; & Lt; / Grid & gt;  

I think the click has two good functionality.

If you have more than one example of ListBox You can use the custom list box (by getting the ListBox ). See.


Or, if you have only 1 (or only small number) such a ListBox and do not want it, then use Hack To create a separate category for this:

  & lt; TextBox x: name = "textbox insidelistboxime theme" ... & gt; & Lt; TextBox.Style & gt; & Lt; Style TargetType = "{x: type text box}" & gt; & Lt; Setter Property = "IhiteTestVisible" value = "False" /> & Lt; Style.Triggers & gt; & Lt; DataTrigger binding = "{Iscielected IsSelected, RelativeSource = {RelativeSource FindAncestor, AncestorType = {x: Type ListBoxItem}, AncestorLevel = 1}}" Value = "True" & gt; & Lt; Setter Property = "IhiteTestVisible" Value = "True" /> & Lt; / DataTrigger & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; /TextBox.Style> & Lt; / Text box & gt;  

Note that you will have to click once again to edit the text in the TextBox (which is actually cool according to me).


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

c++ - QtQuick: QQmlApplicationEngine failed to load component qrc:/main.qml:23 Invalid attached object assignment -