itemscontrol

WPF - Why do ContextMenu items work for ListBox but not ItemsControl?

不打扰是莪最后的温柔 提交于 2020-01-04 02:57:13
问题 Items in a list have context menus. The context menu items are bound to routed commands. The context menu items work correctly if the list control is a ListBox , but as soon as I downgrade it to an ItemsControl it no longer works. Specifically the menu items are always greyed out. The CanExecute callback in my CommandBinding is not being called either. What is it about ListBox that allows context menu items with commands to bind correctly? Here are some excerpts from a sample app I put

Separator in ItemsControl renders in different shades for each item

*爱你&永不变心* 提交于 2020-01-03 02:19:06
问题 I have an ItemsControl presenting TextBlocks, with a Separator at the bottom of each item. My problem is that each Separator is rendered in a slightly different shade of gray - it looks really dodgy: Here is my XAML: <ItemsControl ItemsSource="{Binding Path=Items}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel></StackPanel> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding}" ></TextBlock> <Separator

How can I get SelectedItem and show Headers using ItemsControl?

跟風遠走 提交于 2020-01-03 01:42:33
问题 I am working on WPF Windows Application. I'm using ItemsControl to show collection list. Working on this I found there is no SelectedItem property in ItemsControl. Then how can I get the Selected Item from the ItemsControl. And also How can I display the Headers of ItemsControl. <ItemsControl ItemsSource="{Binding CustomSalesProducts, Mode=TwoWay}"> <ItemsControl.Template> <ControlTemplate TargetType="ItemsControl"> <Border> <ScrollViewer VerticalScrollBarVisibility="Auto"> <ItemsPresenter/>

How to focus a datatemplated TextBox in the first element of an ItemsControl in a Window, when the Window is opened? (C#, WPF)

六月ゝ 毕业季﹏ 提交于 2020-01-02 06:23:20
问题 When the user clicks a button in the application, a window opens up. I want the TextBox belonging to the first item in the ItemsControl to be focused, so that the user can start typing as soon as the Window is opened, without needing to manually select the TextBox. How can this be done? For simplicity, we can say that the Window looks approximately like this: <Window> <Grid> <ItemsControl ItemsSource="{Binding MyItems}"> <DataTemplate> <Grid> <StackPanel> <StackPanel> <customControls

Strange focus behavior for simple WPF ItemsControl

£可爱£侵袭症+ 提交于 2020-01-01 03:39:51
问题 I'm seeing strange behavior when it comes to focus and keyboard navigation. In the example below I have a simple ItemsControl that has been templated so that it presents a list of CheckBoxes bound to the ItemsSource. <ItemsControl FocusManager.IsFocusScope="True" ItemsSource="{Binding ElementName=TheWindow, Path=ListOStrings}"> <ItemsControl.ItemTemplate> <DataTemplate> <CheckBox Content="{Binding}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> For some strange reason the

Scrolling to an element of a virtualising ItemsControl

强颜欢笑 提交于 2019-12-31 14:20:10
问题 I have a ItemsControl which displays its items in a ScrollViewer , and does virtualisation. I am trying to scroll that ScrollViewer to an (offscreen, hence virtualised) item it contains. However, since the item is virtualised, it doesn't really exist on the screen and has no position (IIUC). I have tried BringIntoView on the child element, but it doesn't scroll into view. I have also tried manually doing it with TransformToAncestor , TransformBounds and ScrollToVerticalOffset , but

Why does the Parent property of a container of an ItemsControl return null and not the Panel it sits on?

天涯浪子 提交于 2019-12-30 08:07:49
问题 This one has me stumped. We have a custom ItemsControl which uses both custom containers as well as a custom panel as its ItemsHost. Now the panel has some metrics that the containers need for rendering purposes. Since they are direct children of the panel in the visual tree, you'd think that the Parent property of the container would return the panel, but it doesn't! I have also confirmed this exact thing using Snoop on a standard ListBox so this isn't exclusive to our code, but apparently

How to convert X/Y position to Canvas Left/Top properties when using ItemsControl

半城伤御伤魂 提交于 2019-12-28 13:58:32
问题 I am trying to use a Canvas to display objects that have "world" location (rather than "screen" location). The canvas is defined like this: <Canvas Background="AliceBlue"> <ItemsControl Name="myItemsControl" ItemsSource="{Binding MyItems}"> <Image x:Name="myMapImage" Panel.ZIndex="-1" /> <ItemsControl.ItemTemplate> <DataTemplate> <Canvas> <TextBlock Canvas.Left="{Binding WorldX}" Canvas.Top="{Binding WorldY}" Text="{Binding Text}" Width="Auto" Height="Auto" Foreground="Red" /> </Canvas> <

Multiple Image in Canvas ItemsControl

谁说胖子不能爱 提交于 2019-12-28 04:34:07
问题 I want to show multiple image on a canvas. I need to position them differently in the canvas. I made a class for my images : class MapItem:Image { public int DistanceToTop { get; set; } public int DistanceToLeft { get; set; } } My XAML looks like this : <UserControl.DataContext> <Map:MapViewModel/> </UserControl.DataContext> <ItemsControl ItemsSource="{Binding All}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl

Accurate scrollbar control in an ItemsControl with a VirtualizingStackPanel

被刻印的时光 ゝ 提交于 2019-12-25 08:58:37
问题 I have an Itemscontrol using a VirtualizingStackPanel to display a huge (and growing) list of items: <ItemsControl Grid.Row="1" Name="ConversationItemsControl" VirtualizingStackPanel.VirtualizationMode="Recycling"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Vertical" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.Template> <ControlTemplate TargetType="ItemsControl"> <ScrollViewer> <ItemsPresenter /> </ScrollViewer> </ControlTemplate>