I got a ItemsControl in my XAML.
In the < ItemsPanelTemplate > is a Grid
and in the < ItemsControl.ItemTemplate > is a Button.
I want to add the Button in the Grid only if a condition is true. What kind of triggers I have to use and where?
Related
I have an ItemsControl that I've bound to an IEnumerable. In the DataTemplate, I am creating a CheckBox for each Enum.
For ONE of the Enum's, I want to enable a textbox outside of the ItemsControl if it is checked. How can I do this?
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#)
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.
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.
How to check whether the vertical scrollbar of the listbox is visible in code-behind?
I have a listbox with x:Name="listOfItems" and its underlying ScrollViewer's VerticalScrollbarVisibility is set to auto.
When the ItemsSource property of the ListBox is set, I want to check whether the verticalScrollbar is visible, but I don't know which property to check or how to dive into the scrollviewer element of the listbox.
Any suggestions
You can find Listbox' ScrollViewer as described here: WPF - Animate ListBox.ScrollViewer.HorizontalOffset?
Then you can use ComputedVerticalScrollBarVisibility property to check if the scrollbar is visible:
ScrollViewer sv = FindVisualChild<ScrollViewer>(listOfItems);
Visibility scrollbarVisibility = sv.ComputedVerticalScrollBarVisibility;