i am binding a lot of images in listview using following code
lvImages.ItemsSource = lstVisualDuplicateImage;
following properties used in ListView
here is my complete XAML Binding ang Grouping is performed iam using .net 4.5
<ListView Name="lvImages" Margin="0,2,0,38"
VirtualizingPanel.IsContainerVirtualizable="True"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
VirtualizingPanel.VirtualizationMode="Recycling" Grid.Row="1"
SelectionChanged="ListViewFiles_SelectionChanged"
ContextMenuOpening="ListViewFiles_ContextMenuOpening"
ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.RowSpan="3">
<ListView.ContextMenu>
<ContextMenu>
<MenuItem x:Name="menuOpen" Header="Open" Click="menuOpen_Click" />
<MenuItem x:Name="menuOpenFileLocation" Header="Open File Location" Click="menuOpenFileLocation_Click" />
<MenuItem x:Name="menuRemove" Header="Remove" Click="menuRemove_Click" />
<MenuItem x:Name="menuOpenProperties" Header="Properties" Click="menuOpenProperties_Click" />
</ContextMenu>
</ListView.ContextMenu>
<ListView.ItemsPanel>
<ItemsPanelTemplate >
<!--<VirtualizingStackPanel Orientation="Horizontal" >-->
<WrapPanel Orientation="Horizontal"/>
<!--</VirtualizingStackPanel>-->
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.View>
<GridView >
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn Width="160" Header="Group Details" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Border CornerRadius="2" BorderThickness="2" BorderBrush="#B3B4B5">
<StackPanel >
<StackPanel Orientation="Horizontal">
<CheckBox Margin="0" MinWidth="22" Name="chkSelRow" IsChecked="{Binding Path=Checked}" Unchecked="lvFileItem_UnChecked" Checked="lvFileItem_Checked" />
<TextBlock Margin="5,0,0,0" Text="{Binding Path=size}" />
</StackPanel>
<Image Height="120" Width="120">
<Image.Source>
<BitmapImage
DecodePixelHeight="120"
DecodePixelWidth="120"
UriSource="{Binding Path=getUri, Mode=OneWay,UpdateSourceTrigger=Explicit }"
CreateOptions="IgnoreColorProfile"
CacheOption="None" />
</Image.Source>
</Image>
<StackPanel Orientation="Vertical">
<TextBlock Margin="5,0,0,3" Text="{Binding Path=FileName}" />
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True" Style="{DynamicResource newExpanderStyle}" >
<Expander.Header>
<StackPanel Orientation="Horizontal">
<Button Content="View Gropu" Style="{StaticResource LinkButton}" Foreground="Blue" Margin="10,5,0,0" x:Name="btnViewGroup" ></Button>
<TextBlock Text=" Group NO " FontSize="12" Foreground="Black" Margin="30,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Text="(" FontSize="14" Margin="0,2,0,0" Foreground="Black" />
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Black" FontSize="12" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Text=")" FontSize="14" Margin="0,2,0,0" Foreground="Black" />
<TextBlock Text=" Items in Group" FontSize="12" Foreground="Black" Margin="60,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Text="(" FontSize="14" Margin="0,2,0,0" Foreground="Black" />
<TextBlock Text="{Binding ItemCount}" FontSize="12" Foreground="Black" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Text=")" FontSize="14" Margin="0,2,0,0" Foreground="Black" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
no of item is complete in listview
Problem is images repeat and change their position in groups not loading correctly and refreshing is there any way to virtualize groups.
You have changed the ListView.ItemsPanel from a VirtualizingStackPanel to a WrapPanel. Virtualization only works correctly when the panel supports virtualization. In this case, the standard WrapPanel does not support virtualization.
Related
I have a list box Bound to XML data correctly , but i have multiple Tree Views inside this listbox which you can select item for every one of them!
i want single item selecting from all of these tree views. which every one of those are inside an unique expander.
if you look at my xml data ,consider i have 2 groups inside xml , i can select item for both of those groups in listbox which now they are different treeviews in my ui , and i want single item selecting for all this listbox items.
<ListBox Background="Transparent" BorderThickness="0" SelectedValue="{Binding SelectedMenuValue,Mode=TwoWay}" ItemsSource="{Binding Path=Items,Source={StaticResource XmlSourceMenu}}">
<ListBox.Resources>
<DataTemplate DataType="{x:Type revoxml:Group}">
<Expander Header="{Binding Title}">
<TreeView ItemsSource="{Binding Menus}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding}">
<StackPanel Orientation="Horizontal" Margin="10 0">
<fa:ImageAwesome Height="30" Width="30" VerticalAlignment="Center" Margin="5" Icon="{Binding Icon}" />
<TextBlock Text="{Binding Title}" Height="30" VerticalAlignment="Center" Margin="5"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Expander>
</DataTemplate>
<DataTemplate DataType="{x:Type revoxml:SubMenu}">
<StackPanel Orientation="Horizontal" Margin="10 0">
<fa:ImageAwesome Height="30" Width="30" VerticalAlignment="Center" Margin="5" Icon="{Binding Icon}" />
<TextBlock Text="{Binding Title}" Height="30" VerticalAlignment="Center" Margin="5"/>
</StackPanel>
</DataTemplate>
</ListBox.Resources>
</ListBox>
for easier understanding data for this listbox comming from xml file like this :
<MainMenu>
<Group Title="title">
<SubMenu Icon="Inbox" Title="inbox" Tag="38"/>
<SubMenu Icon="CommentingOutline" Title="New Message" Tag="37"/>
<SubMenu Icon="Tachometer" Title="Archive" Tag="39"/>
<Menu Icon="CartArrowDown" Title="purchases" >
<SubMenu Icon="CartArrowDown" Title="new" Tag="26"/>
<SubMenu Icon="CartPlus" Title="list" Tag="28"/>
</Menu>
</Group>
<SubMenu Icon="InfoCircle" Title="info" Tag="6000" />
<SubMenu Icon="Close" Title="close" Tag="0"/>
</MainMenu>
this should solve it ! but you need to implement your own selected item, or you could change groupboxes to expander and items control to tree view to match your code
<Style TargetType="StackPanel" x:Key="HoverStackPanelStyle">
<Setter Property="Background" Value="Transparent"></Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
<ScrollViewer>
<HeaderedItemsControl Background="Transparent" ItemsSource="{Binding Path=Items,Source={StaticResource XmlSourceMenu}}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type revoxml:SubMenu}">
<StackPanel Orientation="Horizontal" Margin="10 0" Style="{StaticResource HoverStackPanelStyle}">
<fa:ImageAwesome Height="30" Width="30" VerticalAlignment="Center" Margin="5" Icon="{Binding Icon}" />
<TextBlock Text="{Binding Title}" FontFamily="{StaticResource nazanin}" Height="30" VerticalAlignment="Center" Margin="5"/>
</StackPanel>
</DataTemplate>
<HierarchicalDataTemplate DataType="{x:Type revoxml:Menu}" ItemsSource="{Binding Menus}">
<GroupBox Header="{Binding Title}" Margin="0 5">
<ItemsControl ItemsSource="{Binding Menus}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type revoxml:SubMenu}">
<StackPanel Name="StackPanel" Orientation="Horizontal" Margin="10 0" Style="{StaticResource HoverStackPanelStyle}">
<fa:ImageAwesome Height="30" Width="30" VerticalAlignment="Center" Margin="5" Icon="{Binding Icon}" />
<TextBlock Text="{Binding Title}" FontFamily="{StaticResource nazanin}" Height="30" VerticalAlignment="Center" Margin="5"/>
</StackPanel>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
</GroupBox>
</HierarchicalDataTemplate>
</ItemsControl.Resources>
</HeaderedItemsControl>
</ScrollViewer>
I am developing a UWP application.
Here I want to show data in a table formate like below,
Here my purpose is I will search items and add those to this grid.
with out data in grid If I click on Rounded button(Red Color it's a datagrid Header template ) its working fine , but if grid contains some data in that case if I click on Rounded Image Button getting unhand-led Exception like ,
Here I am placing the code which I have used,
<controls:DataGrid x:Name="dgNewBill" Grid.Row="0" Grid.Column="0" MinHeight="500" HorizontalAlignment="Left" HeaderBackground="Black" DefaultOrderIndex="1" Background="Black" RowBackgroundEvenBrush="Black" RowBackgroundOddBrush="Black" >
<controls:DataGrid.RowStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="0"></Setter>
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
</Style>
</controls:DataGrid.RowStyle>
<controls:DataGrid.Columns>
<controls:DataGridTextColumn Width="50" Binding="{Binding SNumber}" Foreground="White"
IsAscendingDefault="False" CanSort="False">
<controls:DataGridTextColumn.Header>
<Button x:Uid="RSNO" Height="40" Width="50" HorizontalAlignment="Left" Style="{StaticResource RoundButtonTemplate}" Margin="-10,0,0,0"/>
</controls:DataGridTextColumn.Header>
<controls:DataGridTextColumn.Style>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"></Setter>
</Style>
</controls:DataGridTextColumn.Style>
</controls:DataGridTextColumn>
<!--Item Column-->
<controls:DataGridTextColumn Width="380" Binding="{Binding description}" Foreground="White" CanSort="False">
<controls:DataGridTextColumn.Header>
<Button x:Uid="RItem" Height="40" Width="380" Style="{StaticResource RoundButtonTemplate}" Margin="-12,0,0,0"/>
</controls:DataGridTextColumn.Header>
<controls:DataGridTextColumn.Style>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"></Setter>
</Style>
</controls:DataGridTextColumn.Style>
</controls:DataGridTextColumn>
<!--UOM column-->
<controls:DataGridTextColumn Width="120" Binding="{Binding uom}" Foreground="White" CanSort="False">
<controls:DataGridTextColumn.Header>
<Button x:Uid="RUOM" Height="40" Width="120" Style="{StaticResource RoundButtonTemplate}" Margin="-12,0,0,0"/>
</controls:DataGridTextColumn.Header>
<controls:DataGridTextColumn.Style>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"></Setter>
</Style>
</controls:DataGridTextColumn.Style>
</controls:DataGridTextColumn>
<!--Price Column-->
<controls:DataGridTemplatedColumn>
<controls:DataGridTemplatedColumn.Header>
<Button x:Uid="RPrice" Height="40" Width="110" Style="{StaticResource RoundButtonTemplate}" Margin="-12,0,0,0"/>
</controls:DataGridTemplatedColumn.Header>
<controls:DataGridTemplatedColumn.CellTemplate>
<DataTemplate>
<StackPanel Name="pricePanel" Width="110" Height="30" Tapped="pricePanel_Tapped" >
<TextBlock Name="price" Foreground="White" Text='{Binding price}' VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,5,0,0"></TextBlock>
</StackPanel>
</DataTemplate>
</controls:DataGridTemplatedColumn.CellTemplate>
</controls:DataGridTemplatedColumn>
<!--Qty Column-->
<controls:DataGridTemplatedColumn>
<controls:DataGridTemplatedColumn.Header>
<Button x:Uid="RQty" Height="40" Width="110" Style="{StaticResource RoundButtonTemplate}" Margin="-25,0,0,0"/>
</controls:DataGridTemplatedColumn.Header>
<controls:DataGridTemplatedColumn.CellTemplate>
<DataTemplate>
<StackPanel Name="quantityPanel" Width="50" Height="30" Tapped="quantityPanel_Tapped">
<TextBlock Name="quantity" Foreground="White" Text='{Binding quantity}' VerticalAlignment="Center" Margin="0,5,0,0"></TextBlock>
</StackPanel>
</DataTemplate>
</controls:DataGridTemplatedColumn.CellTemplate>
</controls:DataGridTemplatedColumn>
<!--Discount Column-->
<controls:DataGridTemplatedColumn>
<controls:DataGridTemplatedColumn.Header>
<Button x:Uid="Rdiscount" Height="40" Width="60" Style="{StaticResource RoundButtonTemplate}" Margin="-25,0,0,0"/>
</controls:DataGridTemplatedColumn.Header>
<controls:DataGridTemplatedColumn.CellTemplate>
<DataTemplate>
<StackPanel Name="discountPanel" Width="60" Height="30" Tapped="discountPanel_Tapped" >
<TextBlock Name="Discount" Foreground="White" Text='{Binding discount}' VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,5,0,0"></TextBlock>
</StackPanel>
</DataTemplate>
</controls:DataGridTemplatedColumn.CellTemplate>
</controls:DataGridTemplatedColumn>
<!--Cost Column-->
<controls:DataGridTextColumn Width="110" Binding="{Binding cartTotal}" Foreground="White" CanSort="False" >
<controls:DataGridTextColumn.Header>
<Button x:Uid="RCartTotal" Height="40" Width="110" Style="{StaticResource RoundButtonTemplate}" Margin="-25,0,0,0"/>
</controls:DataGridTextColumn.Header>
<controls:DataGridTextColumn.Style>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center"></Setter>
</Style>
</controls:DataGridTextColumn.Style>
</controls:DataGridTextColumn>
<!--void image column-->
<controls:DataGridTemplatedColumn>
<controls:DataGridTemplatedColumn.Header>
<Button Name="Cancelbtn" Height="50" Click="Cancelbtn_Click" Width="55" >
<Image Source="/Images/erase.png" Name="ImgClearCartp" Height="40" Width="40" ></Image>
</Button>
</controls:DataGridTemplatedColumn.Header>
<controls:DataGridTemplatedColumn.CellTemplate>
<DataTemplate>
<StackPanel Name="voidImagePanel" Width="50" Height="30" Tapped="voidImagePanel_Tapped" >
<Image Name="VoidImage" Source='{Binding imageUrl}' Height="20" Width="30" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,5,0,0"></Image>
</StackPanel>
</DataTemplate>
</controls:DataGridTemplatedColumn.CellTemplate>
</controls:DataGridTemplatedColumn>
</controls:DataGrid.Columns>
</controls:DataGrid>
I have tested and according to my understanding, because of using DataGridTemplatedColumn getting this exception. But according to my scope I have to use TemplateColumn instead of DataGridTextColumn.
And I have used https://github.com/MyToolkit/MyToolkit/wiki/DataGrid
link.
Please suggest me how can I solve this issue?
I have tested and according to my understanding, because of using DataGridTemplatedColumn getting this exception. But according to my scope I have to use TemplateColumn instead of DataGridTextColumn.
Yes, for this issue, one workaround is to replace DataGridTemplatedColumn to DataGridTextColumn.But there are other two workarounds you can use which I think are better than directly replacing.
You can add the order property like Order="{Binding imageUrl}"for the DataGridTemplatedColumn as follows:
<controls:DataGridTemplatedColumn Order="{Binding imageUrl}">
<controls:DataGridTemplatedColumn.Header>
<Button Name="Cancelbtn"
Width="55"
Height="50"
Background="Green"
Click="Cancelbtn_Click">
<Image Name="ImgClearCartp"
Width="40"
Height="40"
Source="Assets/cafee2.jpg" />
</Button>
</controls:DataGridTemplatedColumn.Header>
<controls:DataGridTemplatedColumn.CellTemplate>
<DataTemplate>
<StackPanel Name="voidImagePanel"
Width="50"
Height="30"
Tapped="voidImagePanel_Tapped">
<Image Name="VoidImage"
Width="30"
Height="20"
Margin="0,5,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Source="{Binding imageUrl}" />
</StackPanel>
</DataTemplate>
</controls:DataGridTemplatedColumn.CellTemplate>
If you don't need to sort the column you can simply add the CanSort="False" for the DataGridTemplatedColumn element as follows:
<controls:DataGridTemplatedColumn CanSort="False">
...
</controls:DataGridTemplatedColumn.CellTemplate>
The reason of the exception from MyToolkit is the order property of DataGridTemplatedColumn element is null initial but to be got path parameter from it as following picture shows.You can also submit this issue to MyToolKit issues to ask the MyToolKit team to fix it.
I have a List View Control with grouping and sorting.
The group headers are Dates in descending order.
I am trying to find out how to order the grouped items under each group header in an ascending order, but cant figure out how to get it done or if it is even possible with ListView.
Here is the XAML I have so far.
Note: ScheduledItemSearchResults is an observable collection of ScheduleItems each item has a Title and a ScheduleDate property.
<Grid x:Name="TxScheduleItemResults"
Grid.Column="1">
<Grid.Resources>
<CollectionViewSource Source="{Binding ScheduledItemSearchResults}" x:Key="scheduledItems">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Value.ScheduleDateTime" Direction="Descending"/>
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<dat:PropertyGroupDescription PropertyName="Value.ScheduleDateTime.Date" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</Grid.Resources>
<ListView x:Name="ScheduledItemResultsList"
Style="{StaticResource TransparentListViewStyle}"
ItemContainerStyle="{StaticResource alternatingListViewItemStyle}"
AlternationCount="2"
ItemsSource="{Binding Source={StaticResource scheduledItems}}"
>
<ListView.View>
<GridView>
<GridViewColumn Header="Scheduled Items"
Width="{Binding ElementName=ScheduledItemResultsList, Path=ActualWidth}"
>
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource ModuleGroupHeader}"
Text="{Binding}"
/>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Value.Title}" Width="200"/>
<TextBox Text="{Binding Value.ScheduleDateTime, StringFormat={}{0:HH:mm:ss}}" Width="120"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Items[0].Value.ScheduleDateTime.Date, StringFormat={}{0:dd/MM/yyyy}}" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text=" item(s)" FontSize="22" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</Grid>
You can have several SortDescriptions elements in one CollectionViewSource:
<CollectionViewSource Source="{Binding ScheduledItemSearchResults}" x:Key="scheduledItems">
<CollectionViewSource.SortDescriptions>
<!--This will sort groups-->
<scm:SortDescription PropertyName="Value.ScheduleDateTime.Date" />
<!--This will items-->
<scm:SortDescription PropertyName="Value.ScheduleDateTime" Direction="Descending"/>
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<dat:PropertyGroupDescription PropertyName="Value.ScheduleDateTime.Date" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
P.S. I don't quite get how exactly you want to sort it, but if you sort first groups and then items it should work.
I have a listbox for which I want to keep the first index fixed and all the rest to scroll. I am using WPF Technology.
Can anyone help me please. Thanks
I am using two different template for binding.
Here is my code.
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsEnabled" Value="{Binding isEnable}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsSource>
<CompositeCollection>
<CollectionContainer x:Name="collection_item_data" />
<CollectionContainer x:Name="dbCollection" />
</CompositeCollection>
</ListBox.ItemsSource>
<ListBox.Resources>
<DataTemplate DataType="{x:Type EBS:SingleItem}" >
<StackPanel Orientation="Vertical" x:Name="stk">
<StackPanel Orientation="Horizontal" TextBlock.Foreground="White">
<StackPanel.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFD3F1F9" Offset="0" />
<GradientStop Color="#FF70AED7" Offset="0.991" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</StackPanel.Background>
<TextBlock Width="160" Text="Item" FontWeight="Bold" Margin="2" TextAlignment="Center" />
<TextBlock Width="100" Text="Style" FontWeight="Bold" Margin="2" TextAlignment="Center" />
<TextBlock Width="100" Text="Brand" FontWeight="Bold" Margin="2" TextAlignment="Center" />
<TextBlock Width="100" Text="Color" FontWeight="Bold" Margin="2" TextAlignment="Center" />
<TextBlock Width="70" Text="Size" FontWeight="Bold" Margin="2" TextAlignment="Center" />
<TextBlock Width="100" Text="Price" FontWeight="Bold" Margin="2" TextAlignment="Center" />
<TextBlock Width="50" Text="Qty" FontWeight="Bold" Margin="2" TextAlignment="Center" />
<TextBlock Width="100" Text="Tax" FontWeight="Bold" Margin="2" TextAlignment="Center" />
<TextBlock Width="100" Text="Total" FontWeight="Bold" Margin="2" TextAlignment="Center" />
</StackPanel>
<StackPanel TextBlock.FontFamily="Rupee Foradian" x:Name="stk_add_item" Orientation="Horizontal">
<ComboBox ItemsSource="{Binding dsItem}" DisplayMemberPath="Product_Name" SelectedValuePath="Product_Code"
SelectionChanged="auto_item_SelectionChanged" x:Name="auto_item" Width="160" Margin="2" Loaded="auto_item_Loaded" >
</ComboBox>
<ComboBox x:Name="combo_style" Margin="2" Width="100" ItemsSource="{Binding DsStyle}" DisplayMemberPath="Style_Name" SelectedValuePath="ID" SelectionChanged="combo_style_SelectionChanged" Loaded="combo_style_Loaded" />
<ComboBox x:Name="combo_brand" Margin="2" Width="100" ItemsSource="{Binding DsBrand}" DisplayMemberPath="Brand" SelectedValuePath="ID" SelectionChanged="combo_brand_SelectionChanged" Loaded="combo_brand_Loaded" />
<ComboBox x:Name="combo_color" Margin="2" Width="100" ItemsSource="{Binding dsColor}" DisplayMemberPath="Color_Name" SelectedValuePath="ID" SelectionChanged="combo_color_SelectionChanged" Loaded="combo_color_Loaded" />
<ComboBox x:Name="combo_size" Margin="2" Width="70" ItemsSource="{Binding dsSize}" DisplayMemberPath="Size_Name" SelectedValuePath="ID" SelectionChanged="combo_size_SelectionChanged" Loaded="combo_size_Loaded" />
<xctk:WatermarkTextBox Width="100" TextAlignment="Right" Margin="2" Watermark="Price" MaxLength="10" my2:TextBoxMaskBehavior.Mask="Decimal" my2:TextBoxMaskBehavior.MinimumValue="0" my2:TextBoxMaskBehavior.MaxLength="10" >
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="Text" Value="{Binding PriceString, UpdateSourceTrigger=PropertyChanged}" />
<Style.Triggers>
<Trigger Property="Control.IsFocused" Value="True">
<Setter Property="Text" Value="{Binding Price, StringFormat=F2, UpdateSourceTrigger=PropertyChanged}" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</xctk:WatermarkTextBox>
<xctk:WatermarkTextBox TextAlignment="Right" Text="{Binding Quantity,UpdateSourceTrigger=PropertyChanged}" Width="50" Margin="2" Watermark="Qty" MaxLength="6" PreviewTextInput="WatermarkTextBox_PreviewTextInput" />
<Rectangle Fill="White" Height="26" Margin="2" Width="100" />
<xctk:WatermarkTextBox TextAlignment="Right" Text="{Binding TotalString,UpdateSourceTrigger=PropertyChanged}" Width="130" Margin="2" Watermark="Total" IsReadOnly="True" IsReadOnlyCaretVisible="True" KeyDown="WatermarkTextBox_KeyDown" />
</StackPanel>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type EBS:Items}">
<StackPanel IsEnabled="{Binding isEnable}" TextBlock.FontFamily="Rupee Foradian" Orientation="Horizontal">
<TextBlock Text="{Binding ItemName}" Margin="2" Width="160" />
<TextBlock Text="{Binding Style_Name}" Margin="2" Width="100" />
<TextBlock Text="{Binding Brand_Name}" Margin="2" Width="100" />
<TextBlock Text="{Binding Color_Name}" Margin="2" Width="100" />
<TextBlock Text="{Binding Size}" Margin="2" Width="70" />
<TextBlock Text="{Binding PriceString}" TextAlignment="Right" Margin="2" Width="100" />
<TextBlock Text="{Binding Quantity}" TextAlignment="Right" Margin="2" Width="50" />
<TextBlock Text="{Binding Tax, StringFormat=F2}" TextAlignment="Right" Margin="2" Width="100" />
<TextBlock Text="{Binding TotalString}" TextAlignment="Right" Margin="2" Width="130" />
</StackPanel>
</DataTemplate>
</ListBox.Resources>
</ListBox>
I don't if this could be achieved with a single listbox but You could make your scenario work if you use two listboxes one below the other (Bit of a heck).
just make one more listbox above the listbox you have currently using. resources are going to be same for both (but obvious!)
Somthing like this.
<Stackpanel>
<Listbox name="lb1"/>
<Listbox name="lb2"/>
</Stackpanel>
And assign 1st item of the list in lb1 and rest of the list as an item source to lb2, and make lb1 vertically unscrollable
thats how we make a listbox horizontally, vertically unscrollable
<Listbox name="lb1" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
I have almost tried everything but for some reason it is not working
<StackPanel Orientation="Vertical" Grid.Row="1" Margin="5,30,5,10">
<TextBlock Text="View Options" FontSize="25" Style="{StaticResource PhoneTextNormalStyle}"/>
<ListBox HorizontalContentAlignment="Stretch" Background="Red" ItemsSource="{Binding Path=ViewOptions}" Margin="10">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center" TextAlignment="Center" Text="{Binding}" FontSize="35" Margin="20" Style="{StaticResource PhoneTextNormalStyle}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
Above XAML give me
How to move the textblock to center of listboxitem?
<StackPanel Orientation="Vertical" Grid.Row="1" Margin="5,30,5,10">
<TextBlock Text="View Options" FontSize="25" Style="{StaticResource PhoneTextNormalStyle}"/>
<ListBox x:Name="listBox" HorizontalContentAlignment="Stretch" ItemsSource="{Binding Path=ViewOptions}" Margin="10,30,10,10">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center" TextAlignment="Center" Text="{Binding}" FontSize="35" Margin="20" Style="{StaticResource PhoneTextNormalStyle}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
You need to change the HorizontalContentAlignment to center
<StackPanel Orientation="Vertical" Grid.Row="1" Margin="5,30,5,10">
<TextBlock Text="View Options" FontSize="25" Style="{StaticResource PhoneTextNormalStyle}"/>
<ListBox HorizontalContentAlignment="Center" Background="Red" ItemsSource="{Binding Path=ViewOptions}" Margin="10">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center" TextAlignment="Center" Text="{Binding}" FontSize="35" Margin="20" Style="{StaticResource PhoneTextNormalStyle}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I just tried this and it worked. Two possible differences:
My data source was a simple List<string>.
I removed the references to your styles (i.e. PhoneTextNormalStyle).
Are you binding to simple data?
Does PhoneTextNormalStyle specify left-alignment?