itemscontrol

Binding to custom control inside DataTemplate for ItemsControl

喜你入骨 提交于 2019-11-26 23:16:01
I have a problem with bindings for DataTemplate based on defined DataType in ItemsControl , when I want to bind to my custom user control . For demonstration purposes, I've created simple Item class example, where I have collection of items like this: public class Item { public string ItemNameToBeSureWhatPropertyIsBound { get; set; } } In my ViewModel I create such collection, and expose it (with one item for comparison separately): public class MainWindowViewModel : INotifyPropertyChanged { private ObservableCollection<Item> _items; private Item _exampleItem; public MainWindowViewModel() {

WPF: Alternating colors on a ItemsControl?

ぐ巨炮叔叔 提交于 2019-11-26 21:31:15
问题 How do I get alternating colors on a ItemsControl? I have AlternationCount set to 2, but the ItemsControl.AlternationIndex property always returns 0. <ItemsControl ItemsSource="{Binding}" AlternationCount="2"> <ItemsControl.Resources> <Style x:Key="FooBar" TargetType="Grid"> <Style.Triggers> <Trigger Property="ItemsControl.AlternationIndex" Value="0"> <Setter Property="Background" Value="Blue"/> </Trigger> <Trigger Property="ItemsControl.AlternationIndex" Value="1"> <Setter Property=

Finding control within WPF itemscontrol

落花浮王杯 提交于 2019-11-26 20:26:28
Hi i have few a single textbox within the the datatemplate for itemscontrol. When i bind the itemcontrols to a observable collection i get two text boxes. But i need to do some manipulations based on each of the text boxes for which i want to find each textbox seperatly using some id. Can anybody help on how to find a control witin the itemscontrol in WPF. Using the ItemContainerGenerator you can obtain the generated container for an item and traverse the visual tree downwards to find your TextBox. In the case of an ItemsControl it will be a ContentPresenter, but a ListBox will return a

WPF ItemsControl the current ListItem Index in the ItemsSource

 ̄綄美尐妖づ 提交于 2019-11-26 20:14:21
问题 Is it possible to know the current item's Index in a ItemsControl? EDIT This works! <Window.Resources> <x:Array Type="{x:Type sys:String}" x:Key="MyArray"> <sys:String>One</sys:String> <sys:String>Two</sys:String> <sys:String>Three</sys:String> </x:Array> </Window.Resources> <ItemsControl ItemsSource="{StaticResource MyArray}" AlternationCount="100"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Margin="10"> <!-- one --> <TextBlock Text="{Binding Path=., StringFormat={}Value is {0}}"

How to display search results in a WPF items control with highlighted query terms

馋奶兔 提交于 2019-11-26 18:29:34
问题 I'd like to display search results within a WPF ItemsControl with the query terms highlighted. The search engine I use, Lucene.Net with the Highlighter plugin, returns strings with the query terms marked up like so: ...these <Bold>results</Bold> were found to be statistically significant... I can instruct the Highlighter plugin to use any set of markup tags to wrap a query term. I'm not limited to the <Bold> tag in the example above. For WPF, I'd likely make these <Run/> elements with a style

WPF Dynamic Layout with ItemsControl and Grid

自作多情 提交于 2019-11-26 15:47:19
问题 I am creating a WPF form. One of the requirements is that it have a sector-based layout so that a control can be explicitly placed in one of the sectors/cells. I have created a tic-tac-toe example below to convey my problem: There are two types and one base type: public class XMoveViewModel : MoveViewModel { } public class OMoveViewModel : MoveViewModel { } public class MoveViewModel { public int Row { get; set; } public int Column { get; set; } } The DataContext of the form is set to an

WPF: ItemsControl with scrollbar (ScrollViewer)

会有一股神秘感。 提交于 2019-11-26 15:26:59
问题 I followed this small "tutorial" on how to add a scrollbar to an ItemsControl, and it works in Designer view, but not when I compile and execute the program (only the first few items show up, and no scrollbar to view more - even when VerticalScrollbarVisibility is set to "Visible" instead of "Auto"). Any idea on how to solve this? This is the code I use to show my items (normally I work with Databinding, but to see the items in my Designer I added them manually): <ItemsControl x:Name=

Setting Canvas properties in an ItemsControl DataTemplate

我的梦境 提交于 2019-11-26 14:20:24
I'm trying to databind to this ItemsControl : <ItemsControl ItemsSource="{Binding Path=Nodes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> By using this DataTemplate , I'm trying to individually position my Node elements on the Canvas correctly: <DataTemplate DataType="{x:Type Model:EndNode}"> <Controls:EndNodeControl Canvas.Left="{Binding Path=XPos}" Canvas.Top="{Binding Path=YPos}" /> </DataTemplate> However, it's not working as expected. All my node elements are

Bind to ItemsControl&#39;s DataContext from inside an ItemTemplate

左心房为你撑大大i 提交于 2019-11-26 12:29:28
问题 I have an ItemsControl whose for the ItemTemplate DataTemplate contains a Button. I want the Command on the button to bind to a Command on the DataContext of the ItemsControl, not the ItemTemplate. I think the solution has to do with using RelativeSource, but my attempts so far have failed: <ItemsControl ItemsSource=\"{Binding Games}\"> <ItemsControl.ItemTemplate> <DataTemplate> <Button Command=\"{Binding Path=GameSelectedCommand, Source={RelativeSource FindAncestor, AncestorType={x:Type

How to get a List<string> collection of values from app.config in WPF?

心已入冬 提交于 2019-11-26 12:23:25
问题 The following example fills the ItemsControl with a List of BackupDirectories which I get from code. How can I change this so that I get the same information from the app.config file? XAML: <Window x:Class=\"TestReadMultipler2343.Window1\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" Title=\"Window1\" Height=\"300\" Width=\"300\"> <Grid Margin=\"10\"> <Grid.RowDefinitions> <RowDefinition Height=\"30\"/>