How would I add an icon to each of these parent nodes
I tried adding under each TreeViewItem but the icon doesn't show and when I bind my collection to the ItemSource, it says it must be empty fist.
<TreeView x:Name="tvMessages" HorizontalAlignment="Left" Height="262" Margin="10,37,0,0" VerticalAlignment="Top" Width="248">
<TreeViewItem x:Name="itemsCritical" Header="Critical">
<TreeViewItem.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Description}"/>
<TextBlock Text="{Binding ID}" Visibility="Hidden"/>
</StackPanel>
</DataTemplate>
</TreeViewItem.ItemTemplate>
</TreeViewItem>
<TreeViewItem x:Name="itemsAlert" Header="Alert">
<TreeViewItem.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Description}"/>
<TextBlock Text="{Binding ID}" Visibility="Hidden"/>
</StackPanel>
</DataTemplate>
</TreeViewItem.ItemTemplate>
</TreeViewItem>
<TreeViewItem x:Name="itemsInformational" Header="Informational">
<TreeViewItem.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Description}"/>
<TextBlock Text="{Binding ID}" Visibility="Hidden"/>
</StackPanel>
</DataTemplate>
</TreeViewItem.ItemTemplate>
</TreeViewItem>
</TreeView>
Take a look at this example:
<TreeViewItem Name="treeViewItem1" IsEnabled="True">
<TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<Image Height="16" Source="Images/16x16_red_lamp.png" Width="16" />
<TextBlock Margin="5,0" Text="HostA: Disconnected" />
</StackPanel>
</TreeViewItem.Header>
</TreeViewItem>
Just place the Image inside and tell the Source where is your Icon located.
You can also use HeaderTemplate in case you have Bindings against associated item.
Related
I want to show just tree dataypes in my list view.(GeometryNode, ToolNode and StockNode). But my item source has 5 dataypes. How can I filter this datatypes?
My list view seems like that. And I want to remove or hide the items which are in top of the list view.
listview
<ListView.Resources>
<DataTemplate DataType="{x:Type treeview:MachineGeometryNodeViewItem}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding IconUri, Mode=OneWay}" Margin="0,0,5,0" Height="20" Width="20" />
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type treeview:MachineToolNodeViewItem}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding IconUri, Mode=OneWay}" Margin="0,0,5,0" Height="20" Width="20" />
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type treeview:MachineStockNodeViewItem}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding IconUri, Mode=OneWay}" Margin="0,0,5,0" Height="20" Width="20" />
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ListView.Resources>
I would like to have TreeViewItems configured inside a SwipeControl; this works but the tree gets spaced really ugly, because I can't find a way to shrink the size of the SwipeItem; any idea where to look next?
Here is my Treeview-XAML
<TreeView ItemsSource="{x:Bind fileViewModel.collection}">
<TreeView.ItemTemplate>
<DataTemplate x:DataType="vm:vTreeItem">
<TreeViewItem ItemsSource="{x:Bind Children}">
<SwipeControl Height="25">
<SwipeControl.RightItems>
<SwipeItems Mode="Execute">
<SwipeItem x:Name="DeleteSwipeItem"
Background="Red"
Command="{Binding Source={StaticResource ViewModel}, Path=deleteCmd}"
CommandParameter="{x:Bind Name}"/>
</SwipeItems>
</SwipeControl.RightItems>
<StackPanel Orientation="Horizontal" Height="25">
<Image Width="20" Height="20" Source="{x:Bind Icon}"/>
<TextBlock Text="{x:Bind Name}" Margin="10,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"/>
</StackPanel>
</SwipeControl>
</TreeViewItem>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
I'm trying to put a ComboBox, a checkbox and a few textboxes inside a treeview in WPF.
Following is the basic structure of the treeview requirement
-Parent
--Label Textbox
--Label Textbox
--Label Textbox
--Label Combo box
--Label Check box
--Payload
---Label
----Label Textbox
----Label Combobox
----Label Textbox
Following is the xaml code
<TreeView x:Name="BTreeView" Grid.Column="1" Grid.Row="1" Margin="1,10,0,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding TreeViewListings}" >
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type viewmodel:TreeViewBViewModel}" ItemsSource="{Binding Positions}" >
<TextBlock Text="Level1"/>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding PayLoadList}" DataType="{x:Type viewmodel:Position}">
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 1" />
<TextBox Text="{Binding Path=Text1, UpdateSourceTrigger=PropertyChanged}" Width="200" Margin="10,0,0,0" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 2" />
<TextBox Text="{Binding Path=Text1, UpdateSourceTrigger=PropertyChanged}" Width="200" Margin="10,0,0,0" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 3"/>
<ComboBox Width="100" Height="18" Margin="10,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="10" IsEditable="True" IsReadOnly="True" BorderThickness="0">
<ComboBoxItem IsSelected="True">Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
<ComboBoxItem>Item 3</ComboBoxItem>
<ComboBoxItem>Item 4</ComboBoxItem>
<ComboBoxItem>Item 5</ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Canvas.Left="10" Canvas.Top="10" Content="Active" IsChecked="False"/>
</StackPanel>
<TextBlock Text="{Binding PayLoadText}"/>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding PayLoadData}" DataType="{x:Type viewmodel:Payload}">
<Label Content="{Binding FieldName}"/>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="{x:Type viewmodel:PayloadData}">
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 4" />
<TextBox Text="{Binding Path=Text4, UpdateSourceTrigger=PropertyChanged}" Width="200" Margin="10,0,0,0" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Data}" />
<TextBox Text="{Binding Path=DataFieldValue, UpdateSourceTrigger=PropertyChanged}" Width="200" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Operation" />
<ComboBox Width="100" Height="18" Margin="10,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="10" IsEditable="True" IsReadOnly="True" BorderThickness="0">
<ComboBoxItem>Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
<ComboBoxItem>Item 3</ComboBoxItem>
<ComboBoxItem>Item 4</ComboBoxItem>
</ComboBox>
</StackPanel>
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
I am using MVVM architectural pattern to achieve this goal. The problem that I am facing is with the arrow head of second level node. It is not aligned at the right position. The arrowhead gets automatically aligned to "Text3" combo box instead of "Payload" node. Following is the image of my tree view
I do not know if there is any other approach to include Combo box, check box, text boxes inside a treeview using MVVM approach. Would appreciate if you let me know your approach of designing this treeview
I have an object hierarchy of this: Orders have Allocations. My DataGrid has an ItemSource of Orders which then shows some details of each order in each grid row. Upon clicking on a grid row, a details pane comes up with additional details including a list of Allocations for each order. What I need to do is to somehow reference back to the Master record and pull a bit of detail (which would end up repeating) for each allocation. If I try to RelativeSource back to the DataGrid, I cannot refer to the property since that source is a whole collection and I need to get the value off of the item of that collection.
Below is a simplified version of the XAML I'm using. Basically, I need to bind to QuantityTypeDescription that's in the master record from each Allocation item in the child (Order) record.
<DataGrid ItemsSource="{Binding Orders}" AutoGenerateColumns="False" IsReadOnly="True" HorizontalScrollBarVisibility="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="Trade" Binding="{Binding TransactionTypeDescription}" Width="*"/>
<DataGridTextColumn Header="Adjustment" Binding="{Binding QuantityTypeDescription}" Width="Auto"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<!--Order Summary-->
<StackPanel Orientation="Vertical">
<StackPanel Background="DarkSlateGray" Orientation="Vertical">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="{Binding TransactionTypeDescription}" FontWeight="Bold" Margin="5,0,0,0" FontSize="14" Foreground="White"/>
</StackPanel>
<TextBlock Name="Name" Text="{Binding SecurityName}" HorizontalAlignment="Center" FontWeight="Bold" Foreground="White" Background="DarkSlateGray"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<ItemsControl ItemsSource="{Binding Allocations}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
NOTE: Here I need to get back up one level to get QuantityTypeDescription
<!--<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid, AncestorLevel=1}, Path=QuantityTypeDescription}" Margin="5,0,0,0"/>-->
<TextBlock Text="{Binding Amount}" Margin="5,0,0,0"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
Use ElementName Binding to refer to your main DataGrid's SelectedItem
<DataGrid Name="MainDataGrid" ItemsSource="{Binding Orders}" AutoGenerateColumns="False" IsReadOnly="True" HorizontalScrollBarVisibility="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="Trade" Binding="{Binding TransactionTypeDescription}" Width="*"/>
<DataGridTextColumn Header="Adjustment" Binding="{Binding QuantityTypeDescription}" Width="Auto"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<!--Order Summary-->
<StackPanel Orientation="Vertical">
<StackPanel Background="DarkSlateGray" Orientation="Vertical">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="{Binding TransactionTypeDescription}" FontWeight="Bold" Margin="5,0,0,0" FontSize="14" Foreground="White"/>
</StackPanel>
<TextBlock Name="Name" Text="{Binding SecurityName}" HorizontalAlignment="Center" FontWeight="Bold" Foreground="White" Background="DarkSlateGray"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<ItemsControl ItemsSource="{Binding Allocations}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ElementName=MainDataGrid,Path=SelectedItem.QuantityTypeDescription}" Margin="5,0,0,0"/>
<TextBlock Text="{Binding Amount}" Margin="5,0,0,0"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
<ListBox Height="498" Margin="2,0,0,0" Name="listBox1" Width="879" ItemsSource="{Binding}" >
<ListBoxItem >
<StackPanel Width="418" Orientation="Horizontal">
<TextBlock Name="MedicineName" Text="Alamoxy"
FontWeight="Bold" FontSize="18"
Margin="5" Width="205" >
</TextBlock>
<TextBlock Name="ListBoxLetter" Text="Amoksilin"
FontSize="18" Margin="0" Width="255" Height="23">
</TextBlock>
</StackPanel>
</ListBoxItem>
</ListBox>
I want to bind data to the listbox.
Textblock will show seprate fields. How i can do it?
please Help me about this/
Use an ItemTemplate to make it look something like this.
<ListBox Width="400" Margin="10" ItemsSource="{Binding myItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=MedicineName}" />
<TextBlock Text="{Binding Path=ListBoxLetter}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>