Xamarin.Forms. Collectionview adds a lot of extra white space after its content - xaml

I would like there to be no empty space after the content of the collection view.
I tried to put my button in footer but then i ran into problem that property isenabled = false is not being applied to it in my code behind.
Here is my xaml file:
<ContentPage.Content>
<RefreshView x:DataType="local:QuestionViewModel" Command="{Binding LoadCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">
<ScrollView>
<StackLayout>
<views:MyTextView LaTeX="{Binding Formulation}" HorizontalOptions="Center" Margin="15, 10, 15, 0"/>
<!--<RefreshView x:DataType="local:QuestionViewModel" Command="{Binding LoadCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">-->
<CollectionView
ItemsSource="{Binding Answers, Mode=TwoWay}"
SelectedItems="{Binding SelectedAnswers, Mode=TwoWay}"
SelectionMode="Multiple"
x:Name="collectionView"
SelectionChanged="collectionView_SelectionChanged"
>
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Answer">
<StackLayout Padding="10">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal">
<VisualState.Setters>
<Setter TargetName="frame" Property="Frame.BackgroundColor" Value="{Binding AnswerColor}"/>
</VisualState.Setters>
</VisualState>
<VisualState Name="Selected">
<VisualState.Setters>
<Setter TargetName="frame" Property="Frame.BackgroundColor" Value="{DynamicResource MainColor}"/>
<Setter TargetName="label" Property="views:MyTextView.TextColor" Value="White"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Frame CornerRadius="10" HasShadow="True" x:Name="frame" BackgroundColor="{Binding AnswerColor}">
<views:MyTextView x:Name="label" LaTeX="{Binding Content}" />
</Frame>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<!--</RefreshView>-->
<StackLayout>
<Label x:Name="conditionLabel" TextColor="{DynamicResource AnswerColor}"/>
<Button x:Name="checkButton" Text="Проверить ответы" CornerRadius="10" Margin="10"
Command="{Binding CheckAnswersCommand}"/>
</StackLayout>
</StackLayout>
</ScrollView>
</RefreshView>
</ContentPage.Content>
Result:
1 part of screen
2 part of screen

You shouldn't use Listview/Collection View with in Scrollview as described in official documentation.
There is an alternative to listview within Scrollview. Look at following code:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ScrollViewDemos"
x:Class="ScrollViewDemos.Views.ColorListPage"
Title="ScrollView demo">
<ScrollView>
<StackLayout BindableLayout.ItemsSource="{x:Static local:NamedColor.All}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal">
<BoxView Color="{Binding Color}"
HeightRequest="32"
WidthRequest="32"
VerticalOptions="Center" />
<Label Text="{Binding FriendlyName}"
FontSize="24"
VerticalOptions="Center" />
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ScrollView>
</ContentPage>
Follow Documentation for more support:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/scrollview

Unfortunately, this is a known problem, and an open issue.
See that thread for possible work-arounds. And to track any progress on fixing it.
Bottom line: you have to manually specify/calculate height. There are multiple ways to do so, of various difficulty. Thread mentions some. You would need to Google for more details.
One quick-and-dirty solution I like, when acceptable, is to wrap CollectionView in Grid, and then use RowDefinitions to force how much height is given to row containing CollectionView, how much to everything else. Something like:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<CollectionView Grid.Row="0" ...>
...
</CollectionView>
<StackLayout Grid.Row = "1" ...>
... everything that is below the CV ...
</StackLayout>
</Grid>
This would restrict row 0 (which contains CollectionView) to top 1/3 of screen.

Related

UWP ListView with no scrolling

For some reason, scrolling simply doesn't work on this ListView, and I really don't know why. The items display properly, just the list isn't scrollable. Using grids isn't viable (from what I know, anyway) since the items that are set to appear are pulled from a web source (don't know how many there will be, nor am I very willing to use hacky methods to get a scrollable list).
<Page
x:Class="Hello_World.News_Feed"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Hello_World"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d">
<ListView x:Name="NewsFeedList" x:FieldModifier="public"
Padding="15,15,15,15"
FontFamily="Segoe UI Variable Display"
SelectionMode="None"
VerticalAlignment="Top"
Margin="10,0,0,0">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Margin" Value="0, 10, 0, 10"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Frame
BorderThickness="1"
Padding="10,10,10,10"
CornerRadius="5"
Height="Auto">
<Frame.BorderBrush>
<SolidColorBrush Color="Gray" Opacity="0.2" />
</Frame.BorderBrush>
<Frame.Background>
<SolidColorBrush Color="Gray" Opacity="0.05" />
</Frame.Background>
<Grid>
<Grid Padding="0,5,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Margin="3,3,0,0" CornerRadius="100" Height="50" Width="50" VerticalAlignment="Top">
<Border.Background>
<ImageBrush Stretch="Fill" ImageSource="{Binding AuthorPicture}"/>
</Border.Background>
</Border>
<TextBlock x:Name="Author" Margin="15,5,0,0" Height="Auto" Grid.Column="1" FontSize="17" FontFamily="Segoe UI Variable Text" FontWeight="Semibold" Text="{Binding Author}" TextWrapping="WrapWholeWords">
<TextBlock.Foreground>
<SolidColorBrush>#353535</SolidColorBrush>
</TextBlock.Foreground>
</TextBlock>
<TextBlock x:Name="Time" Margin="15,28,0,0" Height="Auto" Grid.Column="1" FontSize="15" FontFamily="Segoe UI Variable Text" FontWeight="Normal" Text="{Binding Time}" TextWrapping="WrapWholeWords">
<TextBlock.Foreground>
<SolidColorBrush>#656565</SolidColorBrush>
</TextBlock.Foreground>
</TextBlock>
</Grid>
<Grid Padding="10,5,10,10">
<TextBlock x:Name="Heading" Margin="0,70,0,0" Height="Auto" Grid.Column="1" FontSize="18" FontFamily="Segoe UI Variable Text" FontWeight="Semibold" Text="{Binding Title}" TextWrapping="WrapWholeWords"/>
<TextBlock x:Name="Body" Margin="0,100,0,0" Height="Auto" Grid.Column="1" FontFamily="Segoe UI Variable Text" FontWeight="Normal" Text="{Binding Body}" TextWrapping="WrapWholeWords"/>
</Grid>
</Grid>
</Frame>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Page>
Even after conducting some research online, I couldn't find a solution to this annoying issue. Any ideas?
After conducting more tests, I finally found that it was the automatic height of the frame which I call NavigateTo on which causes this issue. Manually setting the height fixes the problem, but the problem with is I want the size to be dynamic but also know when content stops fitting on the screen. What could I do about that?
Edit: Fixed this - realised the frame was under a StackPanel (forgot that they break auto height/width).

Trigger IsVisible true- false of label on radio button checked- Uncheck in xaml

I am trying to show/hide a label using Trigger on RadioButton check/uncheck but I am getting the error. I can also do it in c# code by inotifypropertychanged but i want to use Triggers and this is my first time. I am not able to understand this error.
<StackLayout Orientation="Vertical" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Padding="10">
<Frame HasShadow="False" Margin="10,20" CornerRadius="5" BorderColor="{StaticResource BorderColor}" BackgroundColor="#F7F7F7">
<Grid HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<RadioButton Content="English" x:Name="rdbEnglish" HorizontalOptions="FillAndExpand" BackgroundColor="Transparent"
CornerRadius="10" BorderWidth="2" Margin="2"
Grid.Column="0" Grid.Row="0" IsChecked="{Binding IsCheckedEnglish,Mode=TwoWay}" >
</RadioButton>
<RadioButton Content="hindi" x:Name="rdbHindi" HorizontalOptions="FillAndExpand"
BackgroundColor="Transparent"
CornerRadius="10" BorderWidth="2" IsChecked="{Binding IsCheckedHindi,Mode=TwoWay}"
Margin="2" Grid.Column="1" Grid.Row="0" />
</Grid>
</Frame>
<StackLayout Orientation="Vertical" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Padding="10">
<Label x:Name="lblrdbEnglish" Text="Note : Menu iteam changes will be updated next time"
Margin="2,-10,2,5" TextColor="Red" IsVisible="false" FontAttributes="Italic" >
<Label.Triggers>
<DataTrigger TargetType="RadioButton"
Binding="{Binding Source={x:Reference rdbEnglish},Path=IsChecked}" Value="True" >
<Setter Property="IsVisible" Value="True" />
</DataTrigger>
</Label.Triggers>
</Label>
</StackLayout>
</StackLayout>
Error
System.InvalidOperationException: 'bindable not an instance of AssociatedType'
The TargetType should be of type Label and not RadioButton.
From triggers docs:
TargetType - the control type that the trigger applies to.
...
<Label.Triggers>
<DataTrigger TargetType="Label"
Binding="{Binding Source={x:Reference rdbEnglish},
Path=IsChecked}" Value="True">
<Setter Property="IsVisible" Value="True" />
</DataTrigger>
</Label.Triggers>

How to fill and expand a Button within a Frame Xamarin.Forms

I have different Buttons that I want to put inside the <Frame> control, all this with the aim of avoiding the overflow of the image within the <ListView>, but when putting the HorizontalOptions and VerticalOptions property in FillAndExpand is not filling the Frame, I attached an image of the problem
How can I make the <Button> inside the <Frame> fill the space? I have tried to give the Columns and Rows the Auto property and I have not succeeded.
How can I keep the size of the button (Height and Width) but without losing the frame?
How can I fill and expand the button inside a Frame?
Any help for me?
VIEW.XAML:
<ListView
ItemsSource="{Binding ListaInventario}"
SelectionMode="None"
VerticalOptions="FillAndExpand"
IsRefreshing="{Binding IsRefreshing, Mode=TwoWay}"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout
Margin="0,4,0,0"
Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label
Text="{Binding Id}"
FontSize="Small"
HorizontalOptions="Center"
FontAttributes="Bold"
HeightRequest="39"
VerticalTextAlignment="Start"
TextColor="{StaticResource das.color.texto}"
Grid.Column="0"
Grid.Row="0">
</Label>
<Label
Text="{Binding NombreComercial}"
HorizontalOptions="Start"
FontSize="Small"
MaxLines="3"
HeightRequest="39"
TextColor="{StaticResource das.color.texto}"
VerticalOptions="Start"
Grid.Column="1"
Grid.Row="0">
</Label>
<Frame
HorizontalOptions="End"
BackgroundColor="Transparent"
Grid.Column="2"
Grid.Row="0">
<Button
ImageSource="ic_pdf"
HeightRequest="35"
WidthRequest="50"
BackgroundColor="{StaticResource das.color.estado_primary}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Command="{Binding HDSSisquimCommand}"/>
</Frame>
</Grid>
<!---->
<!--CANTIDAD-->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
Margin="0,1,0,2">
<StackLayout
Orientation="Horizontal"
HorizontalOptions="Start"
Margin="0,0,3,0">
<Label
HorizontalOptions="Start"
HorizontalTextAlignment="Start"
VerticalOptions="End"
VerticalTextAlignment="Center"
Text="Cantidad: "
FontAttributes="Bold"
FontSize="Small"
HeightRequest="35"
IsEnabled="{Binding EnabledEstimadoEntry}"></Label>
<Entry
HorizontalOptions="FillAndExpand"
Placeholder="Cantidad"
Keyboard="Numeric"
HorizontalTextAlignment="Center"
MaxLength="4"
FontSize="Small"
HeightRequest="35"
Text="{Binding CantidadDecimal}"
IsEnabled="{Binding EnabledContenedorEntry}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStatesEntry">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightGray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Entry>
</StackLayout>
<!--UNIDAD-->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand">
<Label
HorizontalOptions="Start"
HorizontalTextAlignment="Start"
VerticalOptions="End"
VerticalTextAlignment="Center"
Text="Unidad: "
FontAttributes="Bold"
FontSize="Small"
HeightRequest="35"
IsEnabled="{Binding EnabledEstimadoEntry}"></Label>
<Picker
iOSSpecific:Picker.UpdateMode = "WhenFinished"
ItemsSource="{Binding ListaUnidadesMedida}"
SelectedItem="{Binding SelectedUnidadMedida}"
ItemDisplayBinding="{Binding NombreCorto}"
Title="Unidad"
FontSize="Small"
HeightRequest="35"
HorizontalOptions="FillAndExpand"
IsEnabled="{Binding EnabledContenedor}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStatesPicker">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightGray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Picker>
</StackLayout>
</StackLayout>
<!-- TWO BUTTONS -->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="End"
Margin="0,1,0,2">
<Button
Margin="0,0,2,0"
ImageSource="ic_actualizar"
BackgroundColor="{Binding ColorBotonActualizar}"
HorizontalOptions="End"
VerticalOptions="Center"
HeightRequest="35"
WidthRequest="50"
Command="{Binding ActualizarSQCommand}"/>
<Button
ImageSource="ic_minus_sisquim"
BackgroundColor="{StaticResource das.color.estado_danger}"
HorizontalOptions="End"
VerticalOptions="Center"
HeightRequest="35"
WidthRequest="50"
Command="{Binding DesasociarSQCommand}"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I only needed to set Padding="0" in the frame.
HorizontalOptions and VerticalOptions where not necessary to set as #Jessie Zhang -MSFT suggested.
<Frame Padding="0">
<Button />
</Frame>
You can try to added a property Padding="0" to Frame and remove the following properties of Button.
HeightRequest="35"
WidthRequest="50"
So the code is like this:
<Frame
HorizontalOptions="End"
BackgroundColor="Green"
Grid.Column="2"
Padding="0"
Grid.Row="0">
<Button
Text="test"
BackgroundColor="Accent"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
/>
</Frame>

Xamarin forms page layout with relative layout and background image

I am new to Xamarin forms and Xaml, trying to design a page layout with a background image, I found out that using Relative layout, I can get the image expand to whole screen using aspect property. However, When I put a grid or layout after the image inside RelativeLayout, It does not expand to whole area, It only covers the given content.
I have tried to achieve this using relative layout. I am using an Image tag with aspect property and then my stacklayout on top of image.
<RelativeLayout>
<Image Aspect="AspectFill" Source="c1.jpg" />
<StackLayout>
<Button Text="Meha" TextColor="White"/>
</StackLayout>
</RelativeLayout>
I want the button to cover whole width and align it vertically center.
This is how i normally solve this situation:
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="White">
<Image Source="c1.jpg" Aspect="AspectFill" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="Center">
<Button Text="Meha" TextColor="Black" HorizontalOptions="FillAndExpand"/>
</StackLayout>
</Grid>
Another way you can try is to use a grid strategy instead of a relative layout. like this example of a welcome page that i use in my app with a bg image:
<Grid
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<!---BG IMAGE -->
<Image
Source="yourimage"
Aspect="AspectFill"
Opacity="0.5"
/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto"/>
<RowDefinition
Height="Auto"/>
<RowDefinition
Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="*" />
<ColumnDefinition
Width="100" />
<ColumnDefinition
Width="*" />
</Grid.ColumnDefinitions>
<!--TEXT-->
<StackLayout
Grid.Row="1"
Grid.ColumnSpan="3"
Spacing="10"
Orientation="Vertical"
VerticalOptions="Center"
TranslationY="-20"
Padding="20">
<Label
LineBreakMode="WordWrap"
Text="Welcome!"
TextColor="White"
VerticalTextAlignment="Center"
FontAttributes="Bold"
>
<Label.FontSize>
<OnIdiom
x:TypeArguments="x:Double"
Phone="26"
Tablet="36" />
</Label.FontSize>
</Label>
<Setter
Property="HeightRequest"
Value="4" />
<Setter
Property="VerticalOptions"
Value="End" />
<Setter
Property="WidthRequest"
Value="40" />
<Setter
Property="BackgroundColor"
Value="{ DynamicResource AccentColor }"
<!-- ACCENT LINE -->
<BoxView VerticalOptions= "End"
HeightRequest = "4"
BackgroundColor="Green" />
</StackLayout>
</Grid>
</Grid>

The splitview items aren't properly stacking beneath hamburger button

I am working on Visual Studio 2015 and trying to make a hamburger style navigation... but the items of the pane of the splitview are automatically getting a margin, and are not properly stacking beneath the hamburger button [look at the attached image]. I want them to properly stack beneath the Hamburger button on the leftmost of the grid.
I want to use the listbox so that when user navigates to a different page, it remains selected/highlighted, so I can't remove that.
I have attached the MainPage.xaml code and the code of the style i have used. Hope you would help .. Thanks!
<Page
x:Class="MathAssistant.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MathAssistant"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Name="HBbutton" Click="HBbutton_Click" Grid.Column="0" Grid.Row="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" FontFamily="Segoe MDL2 Assets" Content="" FontSize="25" Background="BlueViolet"/>
<TextBlock Name="Heading" Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Center" FontSize="36" Foreground="CornflowerBlue" />
<SplitView Grid.Row="1"
Grid.ColumnSpan="2"
Name="Menu"
DisplayMode="CompactOverlay"
OpenPaneLength="270"
CompactPaneLength="56">
<SplitView.Pane>
<ListBox SelectionMode="Single"
SelectionChanged="MenuListBox_SelectionChanged">
<ListBoxItem Name="MenuItemUnitConverter">
<StackPanel Orientation="Horizontal">
<Image Margin="0" Source="Assets/unitconverterlogo.png" Style="{StaticResource SplitviewLogoStyle}" />
<TextBlock FontSize="24" Margin="20,0,0,0">
<Run Text="Unit Converter"/>
</TextBlock>
</StackPanel>
</ListBoxItem>
<ListBoxItem Name="MenuItemCalculator" >
<StackPanel Orientation="Horizontal">
<Image Margin="0" Source="Assets/calculatorlogo.png" Style="{StaticResource SplitviewLogoStyle}"/>
<TextBlock FontSize="24" Margin="20,0,0,0">Calculator</TextBlock>
</StackPanel>
</ListBoxItem>
</ListBox>
</SplitView.Pane>
<SplitView.Content>
<Frame Name="MyFrame" Grid.Column="1" Grid.Row="1"></Frame>
</SplitView.Content>
</SplitView>
</Grid>
<Application.Resources>
<Style TargetType="Image" x:Key="SplitviewLogoStyle">
<Setter Property="Height" Value="50" />
<Setter Property="Width" Value="45" />
</Style>
ListBoxItem has a default padding (that's the opposite of a margin) of "12,11,12,13". Try setting the Padding of the ListBoxItems to 0 then it should be aligned to the left. To set it in the center you could do something like this:
<ListBoxItem Name="MenuItemUnitConverter" Padding="0">
<StackPanel Orientation="Horizontal">
<Image Margin="4" Source="Assets/unitconverterlogo.png" Style="{StaticResource SplitviewLogoStyle}" />
<TextBlock FontSize="24" Margin="20,0,0,0">
<Run Text="Unit Converter"/>
</TextBlock>
</StackPanel>
</ListBoxItem>
And modify the Style so that image's margin on left + width + image's margin on the right = SplitView.Width (4+48+4=56):
<Style TargetType="Image" x:Key="SplitviewLogoStyle">
<Setter Property="Height" Value="50" />
<Setter Property="Width" Value="48" />
</Style>