UWP RelativePanel plan an element right to another then stretch to the panel - xaml

This is my XAML
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="10,0,0,0">
<TextBlock x:Name="PageTitle"
RelativePanel.AlignTopWithPanel="True"
Style="{StaticResource WindowTitle}">This is my page title</TextBlock>
<TextBlock x:Name="ActivityLabel"
RelativePanel.Below="PageTitle"
Style="{StaticResource CaptionTitle}">Activity</TextBlock>
<ComboBox x:Name="ActivityOptions"
RelativePanel.RightOf="ActivityLabel"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignHorizontalCenterWith="ActivityLabel"
ItemsSource="{Binding Path=SupportedActivityTypes}">
</ComboBox>
</RelativePanel>
And this is my output
What I want to achieve is that the title is on top of the page, multiple lines below the title. Each line has a caption, right to the caption is combo box, textbox and so on, but the right side should stretch to the right border of the panel.
Obviously my code does not work, the combo does not even central align with my caption text as I specified in markup. And how to make the left side of combo to touch the caption text and right side to the border of the panel?

I figured it out, I need following XAML
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="10,0,0,0">
<TextBlock x:Name="PageTitle"
Margin="0,0,0,20"
RelativePanel.AlignTopWithPanel="True"
Style="{StaticResource WindowTitle}">This is page title</TextBlock>
<TextBlock x:Name="ActivityLabel"
RelativePanel.Below="PageTitle"
Style="{StaticResource CaptionTitle}">Activity</TextBlock>
<ComboBox x:Name="ActivityOptions"
Margin="10,0,0,0"
HorizontalAlignment="Stretch"
RelativePanel.RightOf="ActivityLabel"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignVerticalCenterWith="ActivityLabel"
ItemsSource="{Binding Path=SupportedActivityTypes}">
</ComboBox>
</RelativePanel>
The combo box is on the same line of caption label ("Activity") and meanwhile the width stretches to relative panel size.

how to make the left side of combo to touch the caption text and right side to the border of the panel?
You need to set RelativePanel.RightOf="PageTitle" and RelativePanel.AlignVerticalCenterWith="PageTitle".
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="10,0,0,0">
<TextBlock x:Name="PageTitle"
RelativePanel.AlignTopWithPanel="True"
Style="{StaticResource TitleTextBlockStyle}" VerticalAlignment="Center" FontSize="35">This is my page title</TextBlock>
<TextBlock x:Name="ActivityLabel"
RelativePanel.Below="PageTitle"
Style="{StaticResource CaptionTextBlockStyle}">Activity</TextBlock>
<ComboBox x:Name="ActivityOptions"
RelativePanel.RightOf="PageTitle"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignVerticalCenterWith="PageTitle"
ItemsSource="{Binding Path=SupportedActivityTypes}">
</ComboBox>
</RelativePanel>

Related

Control not resizing with the gridsplitter

I have a dock panel to the left of my screen which contains a listbox. The listbox is populated with custom items, defined in another class. To the right of my listbox i have a gridsplitter.
When i click and drag my gridsplitter, the listbox gets resized as expected, howvever the items inside do not.
I would like the items inside to resize accordingly so i can use textrimming when the control would be cut off.
I currently have:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" MaxWidth="500" MinWidth="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<toolkit:DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,9,0">
<Button toolkit:DockPanel.Dock="Top" Height="30" Content="Create" Visibility="{Binding Path=IsVisible, Mode=TwoWay}" Command="{Binding Path=Create, Mode=TwoWay}" />
<ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden">
<ListBox HorizontalAlignment="Stretch" ItemContainerStyle="{StaticResource ItemContainerStyle}" ItemsSource="{Binding Path=ViewModel, Mode=TwoWay}" SelectedItem="{Binding Path=Selected, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
<ContentControl HorizontalAlignment="Stretch">
<myNamespace:MycustomControl HorizontalAlignment="Stretch" DataContext="{Binding}" Height="40"/>
</ContentControl>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
</toolkit:DockPanel>
<sdk:GridSplitter Width="10" HorizontalAlignment="Right" Grid.Row="1" Style="{StaticResource VerticalGridSplitterStyle}" />
Also within my custom item class, everything is defined HorizontalAlignment = Stretch and has no fixed width set.
Edit: Also i have tried binding my custom item's width to my listbox width with no luck.
It turned out that the horizontal scroll bar was causing the issue (even though it wasn't visible)
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Solved my issue

Highlighting around GridView items

I started off with a Grouped Items Page template and have my data displaying in groups. I added some margins around these items to improve spacing, but now when I hover over these items, the margin area shows as highlighted. I'm sure this is an easy one for xaml gurus. Please assist!!
Here's my markup:
<GridView.ItemTemplate>
<DataTemplate>
<!-- ******************* here is my margins ******************* -->
<Border BorderBrush="LightGray" BorderThickness="2" Margin="0,0,20,20">
<Grid HorizontalAlignment="Left" Width="390" Height="190">
<Grid.Background>
<ImageBrush ImageSource="/Assets/default.png" Stretch="None"/>
</Grid.Background>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<Image VerticalAlignment="Top" Stretch="None" Source="{Binding ImageUrl}" Margin="10,10,0,0"/>
<StackPanel MaxWidth="270">
<TextBlock Text="{Binding Summary}"/>
<TextBlock Text="{Binding Brand}" />
<TextBlock Text="{Binding Detail}" TextWrapping="Wrap" />
</StackPanel>
</StackPanel>
</Grid>
</Border>
</DataTemplate>
</GridView.ItemTemplate>
Your ItemTemplate just populates over the existing style template for the GridViewItem Style which if you look in the default template shown in that link you'll see a Rectangle named "PointerOverBorder" which is shown (via the VisualStateManager) in the PointerOver state with its Fill set to ListViewItemPointerOverBackgroundThemeBrush.
You could go into the template (right-click, edit template) and remove it, or add your margins, or make it transparent or a number of options. Or could just overwrite the brush resource on the instance to be transparent or something kind of like;
<blah.Resources>
<SolidColorBrush x:Key="ListViewItemPointerOverBackgroundThemeBrush" Color="Transparent" />
</blah.Resources>
Hope this helps.

XAML gridview items expanding to full width of GridView

I'm new at developing apps for Windows 8, and its my first encounter with XAML.
I'm trying to build a GridView that will show a grid of 150x150 tiles. The GridView's XAML looks like this:
<GridView Grid.Row="2" Grid.Column="0"
x:Name="ClocksContainer"
VerticalAlignment="Top"
Height="190"
Margin="80,20,80,0"
HorizontalContentAlignment="Left">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Height="150" Margin="75,0,940,0" Width="150" Background="#FF971485">
<TextBlock Text="12:23pm" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="130" FontSize="32" Foreground="White"/>
<TextBlock Text="23 February, 2014" HorizontalAlignment="Left" Margin="10,48,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="-0.444,0.385" Foreground="#B2FFFFFF"/>
<TextBlock Text="29° / 20°" HorizontalAlignment="Left" Margin="102,128,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#B2FFFFFF" TextAlignment="Right" FontSize="10"/>
<TextBlock Text="Party Cloudy" HorizontalAlignment="Left" Margin="10,128,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#B2FFFFFF" FontSize="10"/>
<Border BorderBrush="{x:Null}" HorizontalAlignment="Left" Height="45" Margin="10,78,0,0" VerticalAlignment="Top" Width="130">
<TextBlock Text="Chennai, India" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Bottom" Foreground="White" Width="130" FontSize="14"/>
</Border>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.Items>
<x:String>test</x:String>
<x:String>test</x:String>
</GridView.Items>
</GridView>
However, in the output I'm finding that my grid items are stretching to the width of the grid itself!
To illustrate, here are two cropped screenshots of the rendered GridView.
The first screenshot shows how a grid item expands to the width of the GridView. (I've added the red outline myself in photoshop).
The second screenshot is of the gridview scrolled ahead to reveal teh second item. The red outline on the first item has been replicated via photoshop. The second item's background is a darker colour because it is mouse-over-ed.
My Question: How do I make the grid items not expand to the width? The intended output is this:
Remove Margin="75,0,940,0" from GridView's ItemTemplate

Windows 8 Metro XAML. How to change background of grid on hover and/or click

I would like to change the background of my grid to white when you hover over or select it. I'd also like to change the color of the text inside at the same time to black. This is specific to one page only, so it would need to be applied with an XKey or something as a guess. The grid starts with a transparent background, also.
I'm really struggling to find the direction for this. Please let me know if you have any ideas or links!
Here's my code:
<GridView.ItemTemplate>
<DataTemplate>
<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Width="335" Height="152">
<StackPanel Orientation="Horizontal" Margin="2,2,2,2" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel Margin="13,0,13,0" Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom">
<TextBlock Style="{StaticResource SmallText}" Text="{Binding Town}" />
<TextBlock Style="{StaticResource SmallText}" Text=", "/>
<TextBlock Style="{StaticResource SmallText}" Text="{Binding State}"/>
<TextBlock Style="{StaticResource SmallText}" Text=", "/>
<TextBlock Style="{StaticResource SmallText}" Text="{Binding Postcode}"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
Thanks for any help.
It seems like you would probably want to modify your GridView's ItemContainerStyle and change its background and visual states to match your requirements. Check my answer to an earlier question related to restyling items here to learn how to extract and modify these styles and templates.

WP8 XAML ScrollViewer staying at chosen position

I have a TextBox inside a ScrollViewer, as shown below
<ScrollViewer Name="scrollViewer1" Height="480" HorizontalAlignment="Left" Margin="0,480,8,82" VerticalAlignment="Bottom" Width="480" VerticalScrollBarVisibility="Auto">
<TextBox Name="box1" TextWrapping="Wrap" FontSize="32" IsReadOnly="True" TextAlignment="Center"/>
</ScrollViewer>
I don't want VerticalAlignment="Bottom" as I want to scroll to a specific place in the TextBox and for it to stay there without automatically scrolling to the bottom again.
Thanks