I have a master/details page with a list view and a content presenter. My problem is that the content presenter does not fill the entire remaining space of the parent grid when the content of the text block is smaller the current window.
I have tried adding both HorizontalAlign='Stretch' and VerticalAlign='Stretch' as well but nothing works.
Here's the code for the MasterDetailPage.xaml
<Page.Resources>
<DataTemplate x:Key="MasterListViewItemTemplate" x:DataType="data:List">
<Grid Margin="0,11,0,13">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{x:Bind Title}" Style="{ThemeResource BaseTextBlockStyle}" />
<TextBlock Style="{ThemeResource CaptionTextBlockStyle}"
Text="{x:Bind Date}"
Grid.Column="1"
Margin="12,1,0,0" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="DetailContentTemplate" x:DataType="data:List">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel
Orientation="Vertical"
Margin="0,9,12,9">
<TextBlock
Margin="0,8"
Style="{ThemeResource TitleTextBlockStyle}"
TextWrapping="WrapWholeWords"
Text="{x:Bind Title}"/>
<RichTextBlock
x:Name="textContent"
IsTextSelectionEnabled="True"
TextWrapping="WrapWholeWords"
common:Html2TextParser.Html="{x:Bind Content}"/>
</StackPanel>
</ScrollViewer>
</DataTemplate>
<DataTemplate x:Key="comboListTemplate" x:DataType="data:Combo">
<TextBlock Text="{x:Bind Title}"/>
</DataTemplate>
</Page.Resources>
<Grid x:Name="LayoutRoot" Loaded="LayoutRoot_Loaded" UseLayoutRounding="True">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="AdaptiveStates" CurrentStateChanged="AdaptiveStates_CurrentStateChanged">
<VisualState x:Name="DefaultState">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="720" />
</VisualState.StateTriggers>
</VisualState>
<VisualState x:Name="NarrowState">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="MasterColumn.Width" Value="*" />
<Setter Target="DetailColumn.Width" Value="0" />
<Setter Target="MasterListView.SelectionMode" Value="None" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="MasterColumn" Width="320" />
<ColumnDefinition x:Name="DetailColumn" Width="*" />
</Grid.ColumnDefinitions>
<ComboBox
Name="comboList"
Margin="2,2,2,2"
ItemsSource="{x:Bind comboSource.combos}"
LayoutUpdated="comboList_LayoutUpdated"
SelectionChanged="comboList_SelectionChanged"
ItemTemplate="{StaticResource comboListTemplate}"
HorizontalAlignment="Stretch" />
<ListView
x:Name="MasterListView" ItemsSource="{x:Bind listSource.lists}"
Grid.Row="1"
ItemContainerTransitions="{x:Null}"
ItemTemplate="{StaticResource MasterListViewItemTemplate}"
IsItemClickEnabled="True"
ItemClick="MasterListView_ItemClick">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
<ContentPresenter
x:Name="DetailContentPresenter"
Grid.Column="1"
Grid.RowSpan="2"
BorderThickness="1,0,0,0"
BorderBrush="{ThemeResource SystemControlForegroundBaseLowBrush}"
Content="{x:Bind MasterListView.SelectedItem, Mode=OneWay}"
ContentTemplate="{StaticResource DetailContentTemplate}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="12,0,0,0">
<ContentPresenter.ContentTransitions>
<!-- Empty by default. See MasterListView_ItemClick -->
<TransitionCollection />
</ContentPresenter.ContentTransitions>
</ContentPresenter>
</Grid>
Can anyone solve this issue? Here's a screenshot my problem.
You could try to put your contentpresenter inside a ViewBox. The ViewBox is designed to stretch and scale a single child to fill the avialable space.
Documentation here
I hope that helps you :)
I tested your xaml and I can not reproduce your problem Please see the screenshot
I the blue space is your contentPresenter, the orange space is the ScrollViewer and finally your textblocks with dummy text.
After setting different colors to the ContentPresenter and the main grid itself, I found that even my main grid "LayoutRoot" was not expanding to full width!
The reason being that I was using a SplitView and I was navigating my MasterDetailPage.xaml inside the SpiltView's Content element. I simply set HorizontalAlign='Stretch' for the SplitView and it solved my issue!!
Related
I basically want to decrease the size of the drawer in my Xamarin forms UWP app. I have a FlyoutPage and a Custom Renderer for that but i can't find the property of the size of the drawer.
I guess i'm totally lost on Xamarin Forms because i'm a beginner and non-native english speaker.
So, here are my codes:
FlyoutMenuPage.xaml
'''
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="using:FlyoutPageNavigation"
x:Class="FlyoutPageNavigation.FlyoutMenuPage"
Padding="0,20,0,0"
IconImageSource=""
Title="Random"
>
<StackLayout >
<ListView x:Name="listView" x:FieldModifier="public">
<ListView.ItemsSource>
<x:Array Type="{x:Type local:FlyoutPageItem}">
<local:FlyoutPageItem Title="Menu" IconSource="" TargetType="{x:Type local:BasePage}" />
<local:FlyoutPageItem Title="Settings" IconSource="" TargetType="{x:Type local:SettingsPage}" />
<local:FlyoutPageItem Title="Information" IconSource="" TargetType="{x:Type local:InformationPage}" />
</x:Array>
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="5,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding IconSource}" />
<Label Grid.Column="1" Text="{Binding Title}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
'''
Custom Renderer
i tried to add some code in here for the drawer size but nothing works so i deleted everything.
'''
[assembly: ExportRenderer(typeof(FlyoutMenuPage), typeof(FlyoutCustomRenderer))]
namespace Random.UWP.Custom_Renderers
{
class FlyoutCustomRenderer : PageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
}
}
}
'''
Thanks.
If you need a none-Shell project ,you can refer to the following solution .
FlyoutPage was renamed from MasterDetailPage , and I found the solution here , it used to work when it is named as MasterDetailPage , so I made a little modification , and it works now .
Add the following style into App.xaml in UWP project .
And OpenPaneLength repensents the width of the drawer , you can modify the value .
xmlns:uwp="using:Xamarin.Forms.Platform.UWP">
<Application.Resources>
<Style TargetType="uwp:FlyoutPageControl">
<Setter Property="ToolbarForeground" Value="{ThemeResource DefaultTextForegroundThemeBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="uwp:FlyoutPageControl">
<SplitView x:Name="SplitView" OpenPaneLength="100" IsPaneOpen="{Binding IsPaneOpen,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" DisplayMode="Overlay">
<SplitView.Pane>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Visibility="{TemplateBinding FlyoutToolbarVisibility}" Background="{TemplateBinding ToolbarBackground}">
<Button Name="PaneTogglePane" Style="{ThemeResource PaneButton}" Foreground="{TemplateBinding ToolbarForeground}"
AutomationProperties.Name="{Binding Path=(AutomationProperties.Name), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
AutomationProperties.HelpText="{Binding Path=(AutomationProperties.HelpText), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
AutomationProperties.LabeledBy="{Binding Path=(AutomationProperties.LabeledBy), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
AutomationProperties.AccessibilityView="{Binding Path=(AutomationProperties.AccessibilityView), RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
<TextBlock Margin="10,0,0,0" Style="{ThemeResource TitleTextBlockStyle}" VerticalAlignment="Center" Text="{TemplateBinding FlyoutTitle}" Visibility="{TemplateBinding FlyoutTitleVisibility}" Foreground="{TemplateBinding ToolbarForeground}"/>
</StackPanel>
<ContentPresenter x:Name="FlyoutPresenter" Grid.Row="1" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Flyout}" />
</Grid>
</SplitView.Pane>
<SplitView.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border x:Name="TopCommandBarArea" HorizontalAlignment="Stretch" Background="{TemplateBinding ToolbarBackground}">
<uwp:FormsCommandBar x:Name="CommandBar" Background="{TemplateBinding ToolbarBackground}" MinHeight="{ThemeResource TitleBarHeight}" HorizontalAlignment="Stretch">
<uwp:FormsCommandBar.Resources>
<Thickness x:Key="AppBarButtonContentViewboxMargin">12,14,0,14</Thickness>
<Thickness x:Key="AppBarButtonContentViewboxCompactMargin">0,14,0,14</Thickness>
<Thickness x:Key="AppBarButtonContentViewboxCollapsedMargin">0,14,0,4</Thickness>
<Thickness x:Key="AppBarButtonOverflowTextTouchMargin">0,11,0,13</Thickness>
<Thickness x:Key="AppBarButtonOverflowTextLabelPadding">0,5,0,7</Thickness>
<Thickness x:Key="AppBarButtonTextLabelMargin">2,0,2,8</Thickness>
<Thickness x:Key="AppBarButtonTextLabelOnRightMargin">8,15,12,17</Thickness>
<Thickness x:Key="AppBarToggleButtonOverflowTextTouchMargin">0,11,0,13</Thickness>
<Thickness x:Key="AppBarToggleButtonOverflowCheckTouchMargin">12,12,12,12</Thickness>
<Thickness x:Key="AppBarToggleButtonOverflowCheckMargin">12,6,12,6</Thickness>
<Thickness x:Key="AppBarToggleButtonTextLabelMargin">2,0,2,8</Thickness>
<Thickness x:Key="AppBarToggleButtonTextLabelOnRightMargin">8,15,12,17</Thickness>
<Thickness x:Key="AppBarToggleButtonOverflowTextLabelPadding">0,5,0,7</Thickness>
<x:Double x:Key="AppBarButtonContentHeight">20</x:Double>
<x:Double x:Key="AppBarThemeMinHeight">60</x:Double>
<!-- We probably want to keep this in sync with TitleBarHeight in Resources.xaml -->
<x:Double x:Key="AppBarThemeCompactHeight">48</x:Double>
</uwp:FormsCommandBar.Resources>
<uwp:FormsCommandBar.Content>
<Border x:Name="TitleArea" Height="{ThemeResource TitleBarHeight}" Visibility="{TemplateBinding DetailTitleVisibility}" HorizontalAlignment="Stretch">
<Grid x:Name="TitleViewPresenter" VerticalAlignment="Center" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Name="ContentTogglePane" Style="{ThemeResource PaneButton}" Foreground="{TemplateBinding ToolbarForeground}"
Visibility="{TemplateBinding ContentTogglePaneButtonVisibility}" />
<Image Grid.Column="1" Source="{TemplateBinding DetailTitleIcon}" />
<Border Grid.Column="2" Height="{ThemeResource TitleBarHeight}" Visibility="{TemplateBinding DetailTitleVisibility}">
<TextBlock Text="{TemplateBinding DetailTitle}" VerticalAlignment="Center" Margin="10,0,0,0" Foreground="{TemplateBinding ToolbarForeground}" Style="{ThemeResource TitleTextBlockStyle}" />
</Border>
<ContentPresenter Grid.Column="3" Content="{Binding DetailTitleView, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource ViewToRenderer}}" Visibility="{TemplateBinding DetailTitleViewVisibility}" HorizontalAlignment="Stretch" />
</Grid>
</Border>
</uwp:FormsCommandBar.Content>
</uwp:FormsCommandBar>
</Border>
<ContentPresenter x:Name="DetailPresenter" Grid.Row="1" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Detail}" />
<Border x:Name="BottomCommandBarArea" Grid.Row="2" HorizontalAlignment="Stretch"></Border>
</Grid>
</SplitView.Content>
</SplitView>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
You can try this at the top of AppShell.xaml for example 360
FlyoutWidth="360"
Like this :
The documents here: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/flyout#flyout-width-and-height
I have created page1 with hamburger menu in Universal Windows App. I would like to open a page2 in new screen instead of showing the page2 in page1.
Here is my xaml:
<Page x:Class="Hamburger_Menu.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Hamburger_Menu"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:triggers="using:WindowsStateTriggers"
mc:Ignorable="d"
DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=MainViewModel}">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1300" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="NavigationPane.DisplayMode"
Value="CompactOverlay" />
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="720" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="NavigationPane.DisplayMode"
Value="CompactOverlay" />
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="NavigationPane.DisplayMode"
Value="Overlay" />
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<triggers:DeviceFamilyStateTrigger DeviceFamily="Mobile" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="NavigationPane.DisplayMode"
Value="Overlay" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="48" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ToggleButton x:Name="TogglePaneButton"
TabIndex="1"
Background="#990000"
Style="{StaticResource SplitViewTogglePaneButtonStyle}"
IsChecked="{Binding IsPaneOpen, ElementName=NavigationPane, Mode=TwoWay}"
AutomationProperties.Name="Menu"
ToolTipService.ToolTip="Menu" />
<Grid Grid.Column="1"
Background="#990000">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock FontSize="20"
Margin="10,11,0,10"
Foreground="White"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Text="{Binding SelectedMenuItem.Title}" Grid.RowSpan="2" />
</Grid>
</Grid>
<SplitView x:Name="NavigationPane"
Grid.Row="1"
OpenPaneLength="215"
CompactPaneLength="48"
DisplayMode="Inline"
IsPaneOpen="False">
<SplitView.Pane>
<ListView x:Name="LeftMenu"
Grid.Row="1"
Background="{StaticResource MenuBGColorBrush}"
ItemContainerStyle="{StaticResource MenuListViewItem}"
ItemsSource="{Binding MenuItems}"
SelectedItem="{Binding SelectedMenuItem,Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid x:Name="MenuGrid"
Margin="0"
Tapped="MenuGrid_Tapped"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="48" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<SymbolIcon Symbol="{Binding SymbolIcon}"
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ToolTipService.ToolTip="{Binding Title}" />
<TextBlock Grid.Column="1"
VerticalAlignment="Center"
Text="{Binding Title}"
Margin="10,0,0,0"
FontSize="16"
TextTrimming="CharacterEllipsis" />
</Grid>
<Border Grid.Row="1"
BorderBrush="#33415B"
Height="2"
Margin="0"
VerticalAlignment="Bottom"
BorderThickness="0,0,0,1" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</SplitView.Pane>
<SplitView.Content>
<Frame x:Name="FrameContent">
<Frame.ContentTransitions>
<TransitionCollection>
<NavigationThemeTransition>
<NavigationThemeTransition.DefaultNavigationTransitionInfo>
<EntranceNavigationTransitionInfo />
</NavigationThemeTransition.DefaultNavigationTransitionInfo>
</NavigationThemeTransition>
</TransitionCollection>
</Frame.ContentTransitions>
</Frame>
</SplitView.Content>
</SplitView>
</Grid>
</Page>
Screen1:
screen2:
screen3:
When i tab the get quotes button from Page1, I want open a page2 in new screen as a 3rd screen but page2 is displayed on Page1 as screen2 (i.e) page2 is display inside the page1 only.
I used the following code to navigate to the page3 from page1,
this.Frame.Navigate(typeof(GetQuotes));
Advance thanks for reply.
I am working on windows universal app. I want to change my list view selected background color.The system default selected background color is blue and i need a gray color.I used a data template for binding data to listview.
Code
Datatemplate
<Page.Resources>
<DataTemplate x:Name="datatemplate1" x:DataType="data:storedata">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="{x:Bind name}"
x:Phase="1"
x:Name="product_name_layout"
Style="{ThemeResource BaseTextBlockStyle}"
TextWrapping="NoWrap"
Foreground="#FF080808"
Margin="2,3,0,0"
FontSize="12"
/>
<TextBlock x:Name="status_title_layout" FontSize="12" Foreground="Gray" Style="{ThemeResource BaseTextBlockStyle}" Visibility="Visible" SelectionHighlightColor="#FFB1B4BE" Margin="2,5,0,0" Text="SKU:" Grid.Column="1" Grid.Row="1"></TextBlock>
<TextBlock Grid.Column="1"
Grid.Row="0"
Text="{x:Bind status}"
x:Phase="2"
Foreground="Gray"
FontSize="12"
Style="{ThemeResource BaseTextBlockStyle}"
Margin="32,5,0,0"
x:Name="sku_layout"/>
</Grid>
</DataTemplate>
</Page.Resources>
ListView:
<ListView x:Name="MasterListView"
UseLayoutRounding="False"
ScrollViewer.VerticalScrollMode="Enabled"
BorderBrush="#FFA70EAA"
SelectionChanged="OnSelectionChanged"
IsItemClickEnabled="True"
ShowsScrollingPlaceholders="False"
ItemTemplate="{StaticResource datatemplate1 }"
ItemClick="OnItemClick"
Grid.Column="0"
Grid.Row="1"
>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
I also Put some Screen shot so you can easily understand.
Image
Add to your ListViewItem's style this template:
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter
ContentTransitions="{TemplateBinding ContentTransitions}"
SelectionCheckMarkVisualEnabled="True"
CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}"
PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListAccentMediumBrush}"
PressedBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
ContentMargin="{TemplateBinding Padding}"
CheckMode="Inline"/>
</ControlTemplate>
</Setter.Value>
</Setter>
Here you can delete or modify what you want, it looks like you want to change SelectedBackground color to DarkGrey.
I am having a difficult time solving a Visual State problem after moving to VS2013 and Windows Store Apps for 8.1. I have an app with a AppBar "About" button that takes the user to the About page. Works just fine. I want a stackpanel on the About page to change orientation when the view changes to Portrait. Been working on this for hours and reading countless websites with exact replicas of this code, but mine will not work. Any ideas?
Here's the C# code on AboutPage.cs:
private void AboutPage_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (e.NewSize.Height / e.NewSize.Width >= 1)
{
VisualStateManager.GoToState(this, "Portrait", true);
}
else
{
VisualStateManager.GoToState(this, "DefaultLayout", true);
}
}
Here's the XAML on AboutPage.xaml:
<Page
x:Name="pageRoot"
x:Class="xxxxxxxxxxxxxxxxx.AboutPage"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:xxxxxxxxxxxxxxxxxx"
xmlns:common="using:xxxxxxxxxxxxxxx.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" SizeChanged="AboutPage_SizeChanged">
<Page.Resources>
<!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
<!--<x:String x:Key="AppName">xxxxxxxxxxxxxxxxxxx</x:String>-->
</Page.Resources>
<!--
This grid acts as a root panel for the page that defines two rows:
* Row 0 contains the back button and page title
* Row 1 contains the rest of the page layout
-->
<Grid x:Name="pageMainGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Back button and page title -->
<Grid x:Name="pageHeaderGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel
x:Name="headerStackPanel"
Grid.ColumnSpan="3"
Background="#FF4617B4"
Orientation="Horizontal" >
<Button
x:Name="backButton"
Margin="39,59,39,0"
Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button"/>
<TextBlock
x:Name="pageTitle"
Style="{StaticResource HeaderTextBlockStyle}"
Grid.Column="1"
IsHitTestVisible="false"
TextWrapping="NoWrap"
VerticalAlignment="Bottom"
Margin="0,0,30,40"
Text="{StaticResource AppName}"/>
</StackPanel>
</Grid>
<Grid
x:Name="pageContentGrid"
Grid.Row="1"
Visibility="Visible">
<Grid.RowDefinitions>
<RowDefinition Height="20*"/>
<RowDefinition Height="142*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150*"/>
<ColumnDefinition Width="372*"/>
<ColumnDefinition Width="150*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0,0,0,0"
TextAlignment="Center"
Text="About"
FontSize="48"
FontFamily="Segoe UI"/>
<ScrollViewer
BorderThickness="0,2,0,0"
BorderBrush="DarkGray"
Grid.Row="1"
Grid.Column="1"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
Margin="0">
<StackPanel
Margin="40">
<TextBlock
Text="xxxxxxxxxxxxxxxxxx"
FontSize="34" />
<TextBlock
Text="by xxxxxxxxxx"
FontSize="24"/>
<StackPanel
Orientation="Vertical"
Margin="0,25,0,0">
<TextBlock
Margin="0,6,0,0"
Padding="0,0,0,0"
Text="Website:"
FontSize="24"
VerticalAlignment="Center"/>
<HyperlinkButton
Margin="0,0,0,0"
Padding="-5,0,0,0"
FontSize="20"
NavigateUri="http://www.xxxxxxxxxxxxxx.com"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="www.xxxxxxxxxxxxxxxxxx.com" />
</StackPanel>
<StackPanel
x:Name="emailStack"
Orientation="Vertical"
Margin="0,25,0,0">
<TextBlock
Margin="0,4,0,0"
Padding="0,0,0,0"
Text="Support Email:"
FontSize="24"
VerticalAlignment="Center"/>
<HyperlinkButton
Margin="0,0,0,0"
Padding="-5,0,0,0"
FontSize="20"
NavigateUri="mailto:xxxxxxxxxxxxxx#gmail.com"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="xxxxxxxxxxxxxxxxx#gmail.com" />
</StackPanel>
<TextBlock
Margin="0,30,0,0"
Text="Feedback:"
FontSize="24"/>
<TextBlock
TextWrapping="Wrap"
Margin="0,10,0,10"
FontSize="20" >
Please take a few moments to rate and review my application.
Every little bit of encouragement and/or constructive feedback
is appreciated.
<LineBreak /><LineBreak />
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</TextBlock>
</StackPanel>
</ScrollViewer>
<Rectangle
Grid.Row="0"
Grid.Column="0"
Grid.RowSpan="2"
HorizontalAlignment="Stretch"
Fill="DarkGray" />
<Rectangle
Grid.Row="0"
Grid.Column="2"
Grid.RowSpan="2"
HorizontalAlignment="Stretch"
Fill="DarkGray" />
</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="DefaultLayout">
<Storyboard>
</Storyboard>
</VisualState>
<VisualState x:Name="Portrait">
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetProperty="(StackPanel.Orientation)"
Storyboard.TargetName="emailStack">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Orientation>Horizontal</Orientation>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
This needs to be highlighted because it's the answer:
Ok, finally... problem solved! The trick was to locate the VisualStateManager XAML block right after the Grid that contains the control you want to modify when changing screen size. I modified the AboutPage XALM block in my original post to show the correct configuration
This is a breaking change from .NET 4.5.1 where you can place the VisualStateManager before the controls that are effected.
Putting the VisualStateManager within the main control in the content of your Page (usually a Grid or a StackPanel) should change the layout of your AppBar. Give it a try.
<Page
...
SizeChanged="Page_SizeChanged">
<Page.BottomAppBar>
<AppBar>
<StackPanel
x:Name="emailStack"
Orientation="Vertical"
Margin="0,25,0,0">
<TextBlock
Margin="0,4,0,0"
Padding="0,0,0,0"
Text="Support Email:"
FontSize="24"
VerticalAlignment="Center"/>
<HyperlinkButton
Margin="0,0,0,0"
Padding="-5,0,0,0"
FontSize="20"
NavigateUri="mailto:xxxxxxxxxx#gmail.com"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="xxxxxxxxxxx#gmail.com" />
</StackPanel>
</AppBar>
</Page.BottomAppBar>
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="DefaultLayout">
<Storyboard>
</Storyboard>
</VisualState>
<VisualState x:Name="Portrait">
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetProperty="(StackPanel.Orientation)"
Storyboard.TargetName="emailStack">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Orientation>Horizontal</Orientation>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</Page>
I want to add context menu to listbox. But when I hold to listbox item, nothing happens.
Thanks..
This code is definition of my listbox. I added context menu into listbox.
<ListBox Grid.Row="1" Name="chList" ItemsSource="{Binding Ch.Texts}" SelectionChanged="TextChanged" Style="{StaticResource ListOfText}">
<ListBox.ItemTemplate>
<DataTemplate>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu Name="ContextMenu">
<toolkit:MenuItem Name="Edit" Header="Edit" Click="Edit_Click"/>
<toolkit:MenuItem Name="Delete" Header="Delete" Click="Delete_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</DataTemplate>
</ListBox.ItemTemplate>
</Listbox>
in styles.xaml
<Style x:Key="ListOfText" TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="RootElement" Padding="{StaticResource PhoneBorderThickness}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="{StaticResource PhoneAccentBrush}"
Opacity="{Binding IsRead,Converter={StaticResource opacityConverter}}" />
<Grid MinHeight="60" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding Title}" TextWrapping="Wrap"
Style="{StaticResource PhoneTextTitle3Style}" />
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding PbDate, Converter={StaticResource dateConverter}}"
VerticalAlignment="Center" TextWrapping="Wrap" Style="{StaticResource PhoneTextSmallStyle}" />
<Image Grid.Column="1" Height="{StaticResource PhoneFontSizeNormal}" HorizontalAlignment="Left"
Visibility="{Binding IsStared,Converter={StaticResource visibilityConverter}}" Source="/Toolkit.Content/favs.png" />
</Grid>
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Styles.xaml in mysolution... but I can't solve this problem..
Thanks...
You are setting the item DataTemplate to be a ContextMenuService.ContextMenu and there is no actual content. You need to actually have some content displayed there. Also, do you have any items in the list?
Move the ContextMenuService.ContextMenu in one main template - currently you are splitting it (for an unknown reason). Remove the DataTemplate declaration in the ListBox control itself and use your pre-defined style.