WinUI 3 Height of SwipeItem - swipe

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>

Related

Do not want to show all datatypes in listview, is there a chance to hide some datatypes?

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>

WPF:- How to create a Treeview control with combo box, check box and text box in it using MVVM

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

WPF TreeViewItem default icon for each parent node

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.

Binding data to the Listbox where ListBox has textblocks

<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>

WPF Treeview HierarchicalDataTemplate Drag and drop

I have a treeview in wpf that is built using the xaml below. It is a well structured data source, and I am having a lot of trouble dragging and dropping. I have tried several methods, all to no avail. Can anyone tell me what the standard procedure is for doing this type of thing?
<TreeView x:Name="_treeView" ItemsSource="{Binding}" Grid.Row="0" Grid.Column="0">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type Logic:Statement}"
ItemsSource="{Binding Path=PagedChildren}">
<TextBlock Text="{Binding StatementName}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type Logic:StatementPage}"
ItemsSource="{Binding Path=Children}">
<WrapPanel>
<TextBlock Text="Page: "/>
<TextBlock Text="{Binding PageIndex}"/>
</WrapPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type Logic:StatementFund}">
<Border HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="2" CornerRadius="25">
<WrapPanel Margin="30 0 30 0" Width="150" Height="150" >
<StackPanel>
<TextBlock Text="Fund"/>
<WrapPanel>
<TextBlock Text="Fund: "/>
<TextBlock Text="{Binding FundNumber}"/>
</WrapPanel>
<WrapPanel Margin="10 0 0 0">
<TextBlock Text="{Binding ColumnIndex}"/>
</WrapPanel>
</StackPanel>
</WrapPanel>
</Border>
</DataTemplate>
<DataTemplate DataType="{x:Type Logic:StatementPreviousCycle}">
<Border HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="2" CornerRadius="25">
<WrapPanel Margin="30 0 30 0" Width="150" Height="150" >
<StackPanel>
<TextBlock Text="Previous Cycle"/>
<WrapPanel>
<TextBlock Text="Fund: "/>
<TextBlock Text="{Binding FundNumber}"/>
</WrapPanel>
<WrapPanel Margin="10 0 0 0">
<TextBlock Text="{Binding ColumnIndex}"/>
</WrapPanel>
</StackPanel>
</WrapPanel>
</Border>
</DataTemplate>
</TreeView.Resources>
</TreeView>
i use the techniques on this site for a general drag and drop.
tree view can get messy, if you want to know which node you are preivewMouseDown'ing on, to then use as your drag item you can end up walking the visual tree. there is some code to do that here. another way is to subclass treeview, and treeviewitem, then you can override the preview mouse down on each tree view item, and tell your derived parent treeview about it, which could set the tree view item to be the selected item.

Resources