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 ?
Related
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
I have to do a Master/Detail in UWP
1- If you're in Laptop:
The responsible GridView of show the data of this person appear.
So when you select a item is binded to ViewModel.
<ScrollViewer x:Name="ScrollLista" Grid.Column="0" Grid.Row="1">
<ListView x:Name="Lista" ItemsSource="{Binding Lista}" ItemClick="Lista_ItemClick" SelectedItem="{Binding PersonaSeleccionada, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding nombre}" />
<TextBlock Text="{Binding apellido}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollViewer>
<Grid x:Name="CRUD" Grid.Column="1" Grid.Row="1" DataContext="{Binding PersonaSeleccionada}" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
...
</Grid>
2- When is a mobile:
Only will appear the list and when I select a item this should be two things.
Call to ViewModel by binding using SelectedItem.
Call to code behind using ItemClick, this will be in charge of calling another page.
The problem: ItemClick not working, not call to Lista_ItemClick... How can I call a method and send the item selected to code behind?
For click event to work, IsItemClickEnabled="True" should be added to the ListView.
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}">
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}}"
In my application using DataTemplate mechanism I insert into ListBox item another listbox. But is it possible that when selected one listboxitem in parent listbox, the focus may be on another parent listboxitem's child (see picture)
How to do: if one of child listbox in focus (one item from them selected), then parent listboxitem being selected to? Using binding or templating
<DataTemplate x:Key="NotesListBoxDataTemplate" DataType="Note">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Path=Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
<my:DatePicker Height="25" Name="datePicker1" Width="115" xmlns:my="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
SelectedDate="{Binding LastEdit,
Mode = TwoWay}" />
</StackPanel>
<TextBox Text="{Binding Path=Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
<StackPanel Orientation="Horizontal">
<ListBox Name="ImagesListBox" SelectedIndex="{Binding Mode=OneWayToSource, Source={StaticResource progParameters}, Path=SelectedImage, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Path=Images}" ItemTemplate="{StaticResource NotesListBoxImagesTemplate}" Style="{StaticResource HorizontalListBox}">
</ListBox>
<StackPanel Orientation="Vertical">
<Button Name="AddImageButon" Content="+" Click="AddImageButon_Click"></Button>
<Button Name="RemoveImageButon" Content="-" Click="RemoveImageButon_Click"></Button>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
On the parent ListBox set property IsSynchronizedWithCurrentItem to true, then in the inner ListBoxes set the SelectedItem property to "{Binding SelectedItem ElementName=lbParent}".
Consider using a Converter to help you get specific data that is not accessible thru xaml or if you need to do some caculations.
Hope this helps.