WPF DataGrid Hide selected row? - wpf

Is there a way to "hide" the SelectedItem of the DataGrid ?
dataGrid.SelectedItem.Visibility = Visibility.Hidden

Setting the Visibility of "SelectedItem", as you have, would not change the grid - it would be changing the "SelectedItem" property value of the bound object for that SelectedItem, which is not going to affect the grid at all.
In order to change the grid row's visibility, you'll need to change it directly. You can retemplate the DataGrid to change how the selected row is displayed.
For details, see DataGrid Styles and Templates.

Related

Programmatically highlight combobox item

Is there any way to highlight comboboxitem programmatically?
Property IsHighlighted has no setter((. Changing style is not enought.
If you goal is to select rather than highlight (the IsHighlighted property is used to indicate a selected item), you can just set the IsSelected property or the SelectedItem or SelectedValue of the parent ComboBox.

How to set focus on element on ItemsControl?

I've ItemsControl that its ItemsSource property bind to some dictionary from code behind. The ItemTemplate is consist of only one button. So, for each item in dictionary it creates button.
My question is how can I set focus to one of these buttons (dynamically)?
Should I use ItemContainerGenerator.ContainerFromItem ?
Any other idea?
Thanks in advance!
Yes, use can ItemContainerGenerator.ContainerFromItem to get a container for your data item, then you will need to find you button inside this container and call Focus() on the button.
OR you can use an attached property to bind IsFocused to a property on your data item. See Set focus on textbox in WPF from view model (C#)

WPF - databinding label on listbox ismouseover

I'm still new to WPF, and I'm trying to do something that's beyond my knowledge at the moment.
I have a listbox databinded to the source collection, and a label. I'd like to bind the label's Content value to the listbox's item over which is mouse hovered.
Say I have DataTemplate binded to the class MenuItem:
<DataTemplate DataType="{x:Type local:MenuItem}" x:Key="MenuListTemplate">
Which has member Text. I want my Label to display Text from element which is mouse overed in list. I have the IsMouseOver trigger for my textbox, but have no idea how to bind Label.Content to it.
Any tips?
I don't think that binding can achieve your goal with ease. I think it's easier to do with routed events.
Subscribe to the MouseMove event at the ListBox level. Check if the source of the event is a ListBoxItem, and if it is use this item to update the label.

How to get OnSelectionChanged ListBoxItem background change when modifying the data at the same time using a ListBox control?

I have a ListBox control with an ObservableCollection instance as the control's ItemsSource property.
Everything works fine, but when I handle the control's OnSelectionChanged, my business logic modifies the collection's data and I no longer get the ListBoxItem background change you usually get when your ListBox selection changes.
Did anyone encounter the same problem ? Any solution here ?
Thanks and best regards,
Romain
It sounds like you are losing your selected item reference when the list changes.
Bind your ListBox's SelectedItem to a property on your data context and handle selection changes there.

Binding datagrid and combobox to the same datasource

I'm facing the following problem:
I have a datagrid on the first tab and combobox on the second. They both are bound to the same property - FieldList (OneWay for datagrid and TwoWay for combobox).
The point is that the user needs to be able to select item from the combobox on the seconds page, but when he does such thing - the SelectedItem in the datagrid on the first page is changing as well.
And my question is how to prevent this? I don't want to change selection in the datagrid.
Sounds like you need OneTime binding for the grid, rather than OneWay

Resources