I have a pivot that creates the items from a list.
Now I want to show a count in the Heading-Text
For example when I have a list of 5 items, I want in the header following text:
Item1, Item2, Item3 ...
This is the code of my Pivot:
<Pivot ItemsSource="{Binding Items}" SelectedItem="{Binding CurrentItem, Mode=TwoWay}" SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}">
<Pivot.ItemTemplate>
<DataTemplate>
<!-- Data-->
</DataTemplate>
</Pivot.ItemTemplate>
</Pivot>
Any ideas??
Maybe inside <DataTemplate> to create a PivotItem with
Header="{Binding YOURITEM}">
Related
My XAML is as below.:
<ComboBox x:Name="cbCurrencyValueList" SelectionChanged="cbCurrencyValueList_SelectionChanged" ItemsSource="{Binding Source={StaticResource MyCurrencyLists}, Path=librarycurrencylist}" DisplayMemberPath="CurrencyCode" SelectedValuePath="CurrencyCode" SelectedValue="{Binding PricingCurrency, Mode=TwoWay}"/>
<ListView x:Name="lbPriceChangeSchedule" ItemsSource="{Binding PricingScheduleList}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="cbSchedulePriceValueList" ItemsSource="{Binding Source={StaticResource MyPricingLists}, Path=librarypricinglist}" DisplayMemberPath="PriceValue" SelectedValuePath="PriceValue" SelectedValue="{Binding ScheduleDisplayPricing, Mode=TwoWay}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Question: Any selection change in 'cbCurrencyValueList' combobox will change the itemssource list of cbSchedulePriceValueList inside listview. if listview contains n instance of ComboBox cbSchedulePriceValueList then all of them's itemsource will change.
So how can I access every instance of cbSchedulePriceValueList in codebehind and update/change its itemssource individually.?
Any guidance ?
I'm new to MVVM. I created a TreeView with hierarchy of 3 levels: level1: Program, level2: Action, level3: Position. I also created a ListView under the TreeView (see xaml) . Right now the items of the ListView are not bound to anything (the names "Type", "Speed" are only placeholders.)
When selecting an item from level2 (Action) in the TreeView, i'd like to see it's properties (type, speed) appear on the ListView below.
Is there a way to do it through a change in the View only (xaml), without using code in the ViewModel ? maybe there's a way to use a certain binding, that can be changed when pressing on the item in the TreeView?
xaml (model):
<TreeView
Grid.Row="0"
x:Name="MainTreeView"
HorizontalAlignment="Stretch"
Margin="10"
VerticalAlignment="Stretch"
ItemsSource="{Binding Programs}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Actions}" DataType="{x:Type VM:ProgramVM}">
<Label Content="{Binding ProgramName}"/>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Poses}" DataType="{x:Type VM:ActionVM}">
<Label Content="{Binding Actiontype}"/>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="{x:Type VM:PositionVM}">
<Label Content="{Binding PosName}"/>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
<ListView Grid.Row="1" Margin="10" Name="lvUsers">
<ListView.View>
<GridView>
<GridViewColumn Header="Type" Width="100" DisplayMemberBinding="{Binding Type}" />
<GridViewColumn Header="Speed" Width="100" DisplayMemberBinding="{Binding Speed}" />
</GridView>
</ListView.View>
</ListView>
This is a well known issue with the treeview in WPF. You have to create an 'is selected' property for each object in your tree so that you know what the user has chosen, then you can just show the selected object in your listview.
It's been a while since I played with a treeview, but here are some of the links that I think helped me in the past.
Data binding to SelectedItem in a WPF Treeview
WPF MVVM TreeView SelectedItem
When I create ItemsControl and grouping it, for example:
<CollectionViewSource x:Key="items" Source="{Binding Items}">
<CollectionViewSource.GroupDescriptions>
<swd:PropertyGroupDescription PropertyName="User"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<ItemsControl ItemsSource="{Binding Source={StaticResource items}}"
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"</TextBlock>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding item}"></TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Now, with default stlye it's looks somthing like this:
Group name
item1, item2, item3 etc.
But I don't want items in new line, I want it in the same line with group name, like this:
Group name item1, item2, item3 etc.
How to do it? I know that probably need to create Style but I don't know which property excatly I need to change.
You probably have to overwrite the Template of the GroupItem using the GroupItem.ContainerStyle.
I'm trying to organize the items in a combobox into groups. To do this I've created an object that has project and group name strings. I then set the GroupStyle and ItemTemplate to display these values. However, Currently, only the project string is displayed in the combobox (and the box has a red border, indicating some kind of error).
Here's the xaml for my combobox:
<ComboBox x:Name="comboBoxProjects" Margin="165,90,28,0" Grid.Column="0" VerticalAlignment="Top" Height="25"
IsSynchronizedWithCurrentItem="True" SelectedIndex="0" Style="{StaticResource ComboBoxDefault}"
ItemsSource="{Binding Path=ProjectClientSelections.ProjectGroupItems,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding Path=ProjectClientSelections.SelectedProject, UpdateSourceTrigger=PropertyChanged}">
<ComboBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding GroupName}"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ComboBox.GroupStyle>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Project}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Does anyone see where I'm going wrong?
In GroupStyle, the DataContext is not your item (the type contained in your ItemsSource), but a CollectionViewGroup object, which is formed based on the collection of items that you have grouped. Because of this you have to declare a binding path to one of the properties in CollectionViewGroup, for example, based on your code you probably want to use Name property. See MSDN CollectionViewGroup Class
Change your GroupStyle.HeaderTemplate to this:
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
You don't show how you have formed your GroupDescriptions. If you have not grouped the items already, you can do it in following way (assuming the XAML you have provided is contained inside Window and Window's and GroupBox's DataContext is the same):
<Window.Resources>
<CollectionViewSource
Source="{Binding ProjectClientSelections.ProjectGroupItems}"
x:Key="GroupedProjectItems">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription
PropertyName="GroupName" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</Window.Resources>
After this change GroupBox ItemSource binding to the following (directly to CollectionViewSource resource):
ItemsSource="{Binding Source={StaticResource GroupedProjectItems}}"
I would like to create a grouped ComboBox with a group header which is bound to not only the group's name, but other properties of the values by which the 'ItemsSource' of the ComboBox is grouped as well.
This is the CollectionViewSource which is used as the ComboBoxes ItemsSource:
<CollectionViewSource x:Key="Tools" Source="{Binding AvailableTools}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Toolbox" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
The property by which I group, is not a string property, but an object of a custom type. The CollectionViewSource obviously creates groups and gives each group the name of [object by which is group].ToString(), yielding the type name of the property Toolbox in my example.
Here's the combo:
<ComboBox
SelectedItem="{Binding SelectedTool, Mode=TwoWay}"
Margin="10,0,0,0"
Width="40"
ItemsSource="{Binding Source={StaticResource Tools}}">
<ComboBox .GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate DataType="CollectionViewGroup">
<Grid Background="{StaticResource LighterBackgroundBrush}">
<TextBlock Text="{Binding Name}"/>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ComboBox .GroupStyle>
<ComboBox.ItemTemplate>
<DataTemplate DataType="viewModels1:ToolSelectionItem">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Tool.ToolIcon}" Width="16" />
<TextBlock Text="{Binding ToolName}" Margin="10,0,0,0"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
In the header template, I can bind to the groups name but nothing else. What I would like to achieve, is a binding to the object by which a group was created and not just it's ToString() result. I.e. the values of the Toolbox property by which I group contain an Icon property of type BitmapImage which I would like to bind to an Image inside the header template to display this icon in the group header. Can this be done at all and if so, how?
The issue is a bit difficult to explain, please ask, if I am not being clear enough...