Styling ListView in UWP - xaml

I found this question + answer to my problem here on stackoverflow, but for me its not totally clear where to change the
ListViewItemPresenter
I tried many things, but it seems like I cant find it on my own :(
Here is my XAML code for this frame:
<Page.Resources>
<DataTemplate x:Key="ItemListDataTemplate" x:DataType="data:Item">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Image Name="image" Source="{x:Bind CoverImage}" HorizontalAlignment="Center" Width="150" />
<StackPanel Margin="20,20,0,0">
<TextBlock Text="{x:Bind Name}" HorizontalAlignment="Left" FontSize="16" Name="NameTextBlock"/>
<TextBlock Text="{x:Bind Description}" HorizontalAlignment="Left" FontSize="10" Name="DescriptionTextBlock"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Price}" HorizontalAlignment="Left" FontSize="26" Name="PriceTextBlock"/>
<TextBlock Text="€" FontSize="26" Name="Currency" Margin="5,0,0,0"/>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView ItemsSource="{x:Bind Items}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
ItemClick="ListView_ItemClick"
IsItemClickEnabled="True"
ItemTemplate="{StaticResource ItemListDataTemplate}"
>
</ListView>
</Grid>
Can someone help me our please? Thank you very much for your time!

There are two ways to edit ListViewItemPresenter in your Page:
You can copy the XAML Template from here (the first XAML codes block below Default Style). Add it to your Page.Resources. ListViewItemPresenter lies among those XAML codes, you can edit its Properties and this style will be applied to all the items of this page's ListView. Notes: don't add x:Key to this style.
Add a ListViewItem Control to your Page like below:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListViewItem></ListViewItem>
</Grid>
Document Outline->Select ListViewItem->Edit Template->Edit a Copy:
Remove the x:Key Property of generated Style Resource, so that this style will be applied to all ListViewItem. Then you can edit the ListViewItemPresenter in the generated XAML Resource.

Just add your DataTemplate inside of the Listview.
Put it in the ItemTemplate property.
<ListView ItemsSource="{x:Bind Items}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
ItemClick="ListView_ItemClick"
IsItemClickEnabled="True" >
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Image Name="image" Source="{x:Bind CoverImage}" HorizontalAlignment="Center" Width="150" />
<StackPanel Margin="20,20,0,0">
<TextBlock Text="{x:Bind Name}" HorizontalAlignment="Left" FontSize="16" Name="NameTextBlock"/>
<TextBlock Text="{x:Bind Description}" HorizontalAlignment="Left" FontSize="10" Name="DescriptionTextBlock"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Price}" HorizontalAlignment="Left" FontSize="26" Name="PriceTextBlock"/>
<TextBlock Text="€" FontSize="26" Name="Currency" Margin="5,0,0,0"/>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

Related

Vertical Scrollbar not visible in listbox inside popup-element

The vertical Scrollbar is visible in W 8.1 but not in WP 8.1 on my emulator.
What have i missed?
I have also tried to set VerticalScrollBarVisibility to Visible
<Popup x:Name="LayerPopupWindow" IsLightDismissEnabled="True" >
<ListBox x:Name="MyList" Margin="3" Width="auto" Background="#DDFFFFFF"
Height="{Binding Path=ActualHeight,ElementName=MyMapView}" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollMode="Enabled">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Height="auto" >
<CheckBox IsChecked="{Binding IsVisible, Mode=TwoWay}" BorderBrush="Black" MinWidth="30"/>
<TextBlock Text="{Binding ID, Mode=OneWay}" VerticalAlignment="Center" >
<ToolTipService.ToolTip>
<StackPanel MaxWidth="400">
<TextBlock FontWeight="Bold" Text="{Binding CopyrightText}" TextWrapping="Wrap" />
<TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
</StackPanel>
</ToolTipService.ToolTip>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Popup>
Looked at your links Depechie and tried it in my example, for some reason the scrollbars still wasnt visible.
Then i found this link
Making ScrollViewer's ScrollBar always visible through overriding or styling
Tried it and the scrollbars know were visible, so problem solved.

TextBlock is Cutting Text in Windows Phone

In my WP8 project textblock is cutting text unexpectedly. How can I solve it? I have used VerticalAlignment Strecth or Height auto in scrollviewer but they have not solve it.
And my xaml, I am using one of these stackpanels :
<ScrollViewer>
<Grid>
<StackPanel x:Name="stackNormal" Visibility="Collapsed" VerticalAlignment="Top" Background="Transparent">
<ListBox Name="ImageList" ItemsSource="{Binding Summary.Text , Converter={StaticResource ImageFromRssText}}" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding URL}" Tag="{Binding Title}" Margin="5,15,0,0"></Image>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock TextDecorations="Underline" MouseLeftButtonUp="feedTitle_MouseLeftButtonUp" FontSize="25" Name="feedTitle" TextWrapping="Wrap" HorizontalAlignment="Stretch" Foreground="{StaticResource PhoneAccentBrush}" Text="{Binding Title.Text, Converter={StaticResource RssTextTrimmer}}" VerticalAlignment="Top" Margin="5,3,0,2" />
<TextBlock Name="feedSummary" TextWrapping="Wrap" Margin="5,0,15,0" Text="{Binding Summary.Text, Converter={StaticResource RssTextTrimmerLong}}" HorizontalAlignment="Stretch" FontSize="20" VerticalAlignment="Stretch"/>
<TextBlock Name="feedPubDate" Foreground="{StaticResource PhoneSubtleBrush}" Margin="12,20,0,5" Text="{Binding PublishDate.DateTime}" HorizontalAlignment="Center" />
</StackPanel>
<StackPanel x:Name="stackPhotoBug" Visibility="Collapsed" VerticalAlignment="Top" Background="Transparent">
<ListBox Name="ImageList2" ItemsSource="{Binding Links}" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Converter={StaticResource ImagesFromRssTextForPhotoBug}}" HorizontalAlignment="Stretch" Margin="5,15,0,0" MaxHeight="500"></Image>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock TextDecorations="Underline" MouseLeftButtonUp="feedTitle_MouseLeftButtonUp" FontSize="25" Name="feedTitle2" TextWrapping="Wrap" HorizontalAlignment="Stretch" Foreground="{StaticResource PhoneAccentBrush}" Text="{Binding Title.Text, Converter={StaticResource RssTextTrimmer}}" VerticalAlignment="Top" Margin="5,3,0,2" />
<TextBlock Name="feedSummary2" TextWrapping="Wrap" Margin="5,0,15,0" Text="{Binding Summary.Text, Converter={StaticResource RssTextTrimmerLong}}" HorizontalAlignment="Stretch" FontSize="20" VerticalAlignment="Stretch"/>
<TextBlock Name="feedPubDate2" Foreground="{StaticResource PhoneSubtleBrush}" Margin="12,20,0,5" Text="{Binding PublishDate.DateTime}" HorizontalAlignment="Center" />
</StackPanel>
</Grid>
</ScrollViewer>
Maybe it is because of such big text (TextBlock has limit - 2048px). You should try ScrollableTextBlock
Place the textblock inside scrollviewer
<scrollviewer verticalBarvisibility="visible">
<TextBlock Name="feedSummary" TextWrapping="Wrap"
Text="{Binding Summary.Text, Converter={StaticResource RssTextTrimmerLong}}"
HorizontalAlignment="Stretch" FontSize="20"
VerticalAlignment="Stretch"/>
</scrollviewer>
Any element that must be displayed beyond the area which is larger than 2048x2048 pixels would be clipped by the platform
Creating Scrollable TextBlock for WP7.

Horizontal alignment of Expanderview items in windows phone 7

I want to align the contents or items of ExpanderView in horizontal layout instead of vertical layout. The ExpanderHeader is set dynamically and also its contents are added dynamically.
The xaml part and CustomeItemTemplate in app.xaml is as below
<toolkit:ExpanderView
Width="470"
Header="{Binding TaskName, Mode=TwoWay}"
x:Name="taskNameExpander"
Margin="5,10,5,10"
Foreground="#FF677389" FontSize="24" VerticalAlignment="Top"
HorizontalAlignment="Left"
ItemsSource="{Binding dateTime}"
ItemTemplate="{StaticResource CustomItemTemplate}"
HorizontalContentAlignment="Left">
</toolkit:ExpanderView>
<DataTemplate x:Key="CustomItemTemplate">
<StackPanel Orientation="Horizontal" Height="60" >
<TextBlock FontSize="16" Text="{Binding Date, Mode=OneWay}"
TextWrapping="Wrap" Foreground="#FF677389" Margin="0,6,0,0" Height="30" Width="100"/>
<TextBox BorderBrush="Goldenrod" BorderThickness="1" FontSize="16" Text="{Binding Time, Mode=TwoWay}" TextWrapping="Wrap" Foreground="#FF677389" Margin="0" Height="60" Width="150"/>
</StackPanel>
</DataTemplate>
Still i get the contents aligned vertically. Can someone point me what am i doing wrong here?
here is the sample code you have asked for
<Border BorderBrush="White" BorderThickness="1" Margin="5">
<ScrollViewer Width="Auto" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled">
<toolkit:ExpanderView
Width="1600"
Header="{Binding TaskName, Mode=TwoWay}"
x:Name="taskNameExpander" Margin="5,10,5,10" Foreground="#FF677389" FontSize="24" VerticalAlignment="Top" HorizontalAlignment="Left"
ItemsSource="{Binding dateTime}"
ItemTemplate="{StaticResource CustomItemTemplate}"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
HorizontalContentAlignment="Left">
<toolkit:ExpanderView.ItemsPanel>
<ItemsPanelTemplate >
<StackPanel Orientation="Horizontal" Width="Auto" ScrollViewer.HorizontalScrollBarVisibility="Visible"/>
</ItemsPanelTemplate>
</toolkit:ExpanderView.ItemsPanel>
</toolkit:ExpanderView>
</ScrollViewer>
</Border>
and my app.xaml has CustomItemTemplate definition as below
<DataTemplate x:Key="CustomItemTemplate">
<StackPanel Orientation="Vertical" Height="100" >
<TextBlock FontSize="16" Text="{Binding Date, Mode=OneWay}" TextWrapping="Wrap" Foreground="#FF677389" Margin="0,6,0,0" Height="30" Width="100"/>
<TextBox BorderBrush="Goldenrod" BorderThickness="1" FontSize="16" Text="{Binding Time, Mode=TwoWay}" TextWrapping="Wrap" Foreground="#FF677389" Margin="0" Height="60" Width="150">
<TextBox.InputScope>
<InputScope >
<InputScopeName NameValue="Number"></InputScopeName>
</InputScope>
</TextBox.InputScope>
</TextBox>
</StackPanel>
</DataTemplate>
I want to horizontally scroll only ExpanderView items. Rightnow it is scrolling but the whole ExpanderView is scrolling including its header. The header must be intact and only the items must scroll. How can i acheive it?
You should set the ItemsPanel for the ExpanderView control.
<toolkit:ExpanderView
Width="470" Height="100"
x:Name="taskNameExpander"
Margin="5,10,5,10"
FontSize="24" Background="White"
HorizontalAlignment="Left"
ItemsSource="1 2 3 4"
ItemTemplate="{StaticResource CustomItemTemplate}"
HorizontalContentAlignment="Left">
<toolkit:ExpanderView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</toolkit:ExpanderView.ItemsPanel>
</toolkit:ExpanderView>

the property content is set more than once

I am getting the following error with my code shown below.
Error:
The property 'Content' is set more than once
Code:
<controls:PanoramaItem Header="headlines">
<TextBlock Text="{Binding Tones}" />
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Tones}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<Image Source="{Binding ImageUrl}" Height="75" Width="100"
Margin="12,10,9,0" VerticalAlignment="Top"/>
<StackPanel Width="311">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap"
Style="{StaticResource PhoneTextLargeStyle}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>
A PanoramaItem can only have one child control but you currently have a TextBlock and a ListBox. To fix this, simply add another parent control to hold the TextBlock and ListBox (such as a StackPanel or a Grid). For example:
<controls:PanoramaItem Header="headlines">
<grid>
<TextBlock Text="{Binding Tones}" />
<!--Double line list with image placeholder and text wrapping-->
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Tones}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<!--Replace rectangle with image-->
<Image Source="{Binding ImageUrl}" Height="75" Width="100" Margin="12,10,9,0" VerticalAlignment="Top"/>
<!--<Rectangle Height="100" Width="100" Fill="#FFE5001b" Margin="12,0,9,0"/>-->
<StackPanel Width="311">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}"/>
<!--<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>-->
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</grid>
</controls:PanoramaItem>

ComboBox in DataForm, SL4

I know that this question is what many of you already posted, but I'm still having a problem. The idea is very simple: I have a DataGrid and when I select the item in DataGrid, it should select item in ComboBox which is in DataForm. I have read many posts, and implemented few ideas in what I did, and now, I have this:
<StackPanel Grid.Column="1" Grid.Row="4" Name="stackPanel1" Margin="0,0,0,-257">
<sdk:DataGrid Name="PhysicalQuantitiesGrid"
MinHeight="100" IsReadOnly="True"
Margin="0,12,0,0"
ItemsSource="{Binding PhysicalQuantities}"
SelectedItem="{Binding Path=CurrentPhysicalQuantity, Mode=TwoWay}"
AutoGenerateColumns="False" VerticalGridLinesBrush="{x:Null}">
<sdk:DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Margin="5">
<StackPanel Orientation="Horizontal" Margin="5">
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock
FontSize="12"
Width="Auto"
Text="Base unit term"/>
<TextBlock
Foreground="CadetBlue"
FontSize="12"
Width="Auto"
TextWrapping="Wrap"
Text="{Binding Path=Unit.Term}"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock
FontSize="12"
Width="Auto"
Text="Short term"/>
<TextBlock
Foreground="CadetBlue"
FontSize="12"
Width="Auto"
TextWrapping="Wrap"
Text="{Binding Path=Unit.ShortTerm}"/>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</sdk:DataGrid.RowDetailsTemplate>
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Term"
Binding="{Binding Path=Term}"
FontSize="14"
Foreground="DarkBlue"
>
</sdk:DataGridTextColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,12,0,0">
<Button x:Name="NewPhysicalQuantity" Content="AddNew" Height="23" Click="NewPhysicalQuantity_Click"/>
</StackPanel>
<dataform:DataForm x:Name="PhysicalQuantityDetails"
Header="Fizicke velicine - detalji"
AutoGenerateFields="False"
AutoEdit="False"
CommandButtonsVisibility="Commit,Cancel,Edit"
Margin="0,12,0,0"
CurrentItem="{Binding Path=CurrentPhysicalQuantity}"
CancelButtonContent="Cancel"
CommitButtonContent="Commit"
>
<dataform:DataForm.EditTemplate>
<DataTemplate>
<StackPanel>
<dataform:DataField Label="Physical Quantity term:">
<TextBox Text="{Binding Path=Term, Mode=TwoWay}" />
</dataform:DataField>
<dataform:DataField Label="Base unit">
<StackPanel>
<riaControls:DomainDataSource AutoLoad="True" Height="0" Name="baseUnitsDataSource" QueryName="GetBaseUnitsOrdered" Width="0">
<riaControls:DomainDataSource.DomainContext>
<myService:DomainDomainContext/>
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<myControl:ComboBox
ItemsSource="{Binding ElementName=baseUnitsDataSource, Path=Data}"
SelectedValuePath="IDUnit"
DisplayMemberPath="Term"
SelectedValue="{Binding Path=IDUnit, Mode=TwoWay}"
>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</myControl:ComboBox>
</StackPanel>
</dataform:DataField>
</StackPanel>
</DataTemplate>
</dataform:DataForm.EditTemplate>
</dataform:DataForm>
<StackPanel
Orientation="Horizontal"
HorizontalAlignment="Right"
Margin="0,12,0,0">
<Button
Content="Save"
x:Name="SaveChangesButton"
Width="100"
Height="23"
Margin="4,0,4,0"
Command="{Binding SaveCommand}" />
</StackPanel>
</StackPanel>
So, I use MVVM with RIA. For data grid I use MVVM, and for ComboBox data context I use RIA. That is the only way to fill the ComboBox and to bind DataGrid value with ComboBox value, but in the wrong way! When I click Edit in data form, I always get ComboBox initialized to the first item. Of course, value in data grid get the same value (wrong!).
What I am doing wrong?
Thanks!
P.S. I forgot to mention that I have two tables, PhysicalQuantity and Unit, where PhysicalQuantity has one or zero Units (BaseUnit).
Lucky
You're using the wrong ComboBox.
Kyle McClellan has a far more capable ComboBox, which honestly should have been rolled out with the toolkit 2 times over by now, but there seems to be something going fishy with toolkit support as well. Please read more about it here:
http://blogs.msdn.com/b/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx