Strange Windows Phone ListBoxItem Layout - windows-phone-8.1

I have a ListBox in my XAML
<ListBox x:Name="ListBox" ItemTemplate="{StaticResource ListBoxDataTemplate}"
BorderThickness="0" />
ListBoxDataTemplate is
<DataTemplate x:Key="ListBoxDataTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="34" />
</Grid.ColumnDefinitions>
<TextBlock TextWrapping="Wrap" FontSize="18"
Grid.Column="0">A QUICK BROWN</TextBlock>
<Image Grid.Column="1" Margin="4,0,4,0"
Width="30" Height="30" Source="ms-appx:///Assets/Dark/icon.arrowright.png" />
</Grid>
</DataTemplate>
But when I run this on emulator, instead of the the Image align to right in row,
the Image position is right after Text A QUICK BROWN.
Here screenshot from emulator,
XAML code is here : http://pastebin.com/GVqC2Si9

Because your grid column for the image is only 34
change it to
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
I would also add HorizontalAlignment="Right" to the image xaml
EDIT
tried your code and notice you had to add HorizontalContentAlignment
<ListBox x:Name="ListBox" ItemTemplate="{StaticResource ListBoxDataTemplate}" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>

Related

a TopAppbar and BottomAppBar for WindowsPhone

I have a TopAppbar and BottomAppBar in my universal app,I want to create the same AppBars in my windows phone 8,this is my code:
<Page.TopAppBar>
<CommandBar HorizontalContentAlignment="Stretch" Background="#FF00AEEF">
<CommandBar.Content >
<Grid>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal" >
<Image Margin="2" Height="35" Source="images/4.png" Width="35"/>
</StackPanel>
<Button VerticalAlignment="Stretch" Background="#FF00AEEF" x:Name="HomeBtn" Click="HomeBtn_Click">
<StackPanel Orientation="Horizontal">
<Image Source="images/berry.png" Height="35" Width="35" />
<TextBlock Text="BarBerry" Foreground="White"></TextBlock>
</StackPanel>
</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button VerticalAlignment="Stretch" Background="#FF00AEEF" Style="{StaticResource CustomButtonStyle}" Margin="5,0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Contact" Foreground="White"></TextBlock>
</StackPanel>
</Button>
</StackPanel>
</Grid>
</CommandBar.Content>
</CommandBar>
</Page.TopAppBar>
<Page.BottomAppBar>
<CommandBar Background="#eff0f2" HorizontalContentAlignment="Stretch">
<CommandBar.Content>
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" VerticalAlignment="Stretch">
<Image Source="images/world.png" Height="35" Width="35" Margin="5,0"/>
<ComboBox Margin="2" BorderThickness="0" SelectedItem="test" x:Name="combo">
<ComboBoxItem Content="test" />
<ComboBoxItem Content="test1" />
</ComboBox>
</StackPanel>
</Grid>
</CommandBar.Content>
</CommandBar>
</Page.BottomAppBar>
but the problem is that,I get only the BottomAppBar displayed,is it possible to define in windows Phone 8 a Top and a Bottom AppBars,should I use a StackPanel in place of the Top appBar?
thanks for help
You can't create the Top App Bar in windows phone. Because their is only Bottom App Bar is defined in the Windows phone project. So you can only define the bottom app bar in windows phone.Yes you can use the Stack panel instead of Top App bar but i think this is not a good idea to implement that kind of functionality in windows phone :).

Disable the Grid vertical scroll-behavior of the scrollviewer in windows phone

Grid Structure
Load
When click on textbox and open keypad then title scroll up..I want to fix the title place (not scroll)
how to resove this problem?
when click on textbox keypad opened but title scroll up...
My xaml code
<Grid x:Name="grdEmergencyServices" ScrollViewer.VerticalScrollMode="Disabled" >
<Grid.Background>
<ImageBrush ImageSource="/Assets/1.png"/>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="50*"/>
<RowDefinition Height="500*"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border Background="#8C6446" Grid.Row="0" Grid.ColumnSpan="3"/>
<Grid Grid.Row="0" Background="#8C6446" Opacity="0.8">
<TextBlock Name="pageTitle" Text="Title Name" Style=" {StaticResource CommonStyle}"/>
</Grid>
</Grid>
<ProgressRing Grid.Row="1" x:Name="ProgressRingLoad" Visibility="Collapsed" Background="Transparent" IsActive="True" Height="50" HorizontalAlignment="Center" VerticalAlignment="Center" />
<ScrollViewer Grid.Row="1" Margin="20">
<TextBox TextWrapping="Wrap" Text="TextBox" Margin="0,500,0,0"/>
</ScrollViewer>
</Grid>

disable click event everywhere when Process Ring is Active in Windows phone 8.1

I have a XAML Page in that i have putted various control for login, whenever i click on Login Button , process will start for authenticate the user ,process ring is activated at the start of Login_click event and it will stop at the end of that event.
i Just want that during that process no buddy can click on any control of the page.
i think it is possible from both the methods from c# and also from and XAML
<Grid>
<ProgressRing Name="prcsring1" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" Height="200" Background="Transparent" Canvas.ZIndex="9999"/>
<Grid Margin="0,0,0,0" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<!--1-->
<RowDefinition />
<!--2-->
<RowDefinition />
<!--3-->
<RowDefinition />
<!--4-->
<RowDefinition />
<!--5-->
<RowDefinition />
<!--6-->
<RowDefinition />
<!--7-->
<RowDefinition Height="25" />
<!--8-->
<RowDefinition Height="60"/>
<!--9-->
<RowDefinition Height="20"/>
<!--10-->
<RowDefinition />
<!--11-->
<RowDefinition Height="40"/>
<!--12-->
<RowDefinition />
<!--13-->
<RowDefinition Height="70" />
<!--14-->
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Grid.Row="0" x:Name="stackpanHead1" Background="#424242" />
<Image x:Name="imgstatusGreen" Visibility="Collapsed" Source="../Images/Confirmed Images/index_green1.png" HorizontalAlignment="Right" Margin="0,21,10,0" VerticalAlignment="Top" Width="20" />
<Image x:Name="imgstatusRed" Source="../Images/Confirmed Images/index_red1.png" Visibility="Collapsed" HorizontalAlignment="Right" Margin="0,21,10,0" VerticalAlignment="Top" Width="20" />
<Image x:Name="imgstatusOrange" Source="../Images/Confirmed Images/Orange.png" Visibility="Collapsed" HorizontalAlignment="Right" Margin="0,21,10,0" VerticalAlignment="Top" Width="20" />
<TextBlock Grid.Column="0" Grid.Row="1" HorizontalAlignment="Center" Margin="0,10,0,0" Foreground="#5C5C5C" FontSize="50" FontWeight="Bold" TextWrapping="Wrap" Text="Welcome to" />
<Image Grid.Column="0" Grid.Row="2" x:Name="imglogo" Source="../Images/alogo.png" Margin="40,0,40,0" VerticalAlignment="Center" />
<TextBlock Grid.Column="0" Grid.Row="3" FontSize="30" Margin="0,0,0,0" TextWrapping="Wrap" FontWeight="Bold" TextAlignment="Center" Text="Your Gateway to" VerticalAlignment="Top" HorizontalAlignment="Center" Foreground="#5C5C5C" />
<TextBlock Grid.Column="0" Grid.Row="4" FontSize="30" Margin="0,0,0,0" TextWrapping="Wrap" FontWeight="Bold" TextAlignment="Center" Text="e-Government and Visas" VerticalAlignment="Top" HorizontalAlignment="Center" Foreground="#5C5C5C" />
<Border Grid.Column="0" Grid.Row="5" Margin="50,5,50,5" Name="cornradusername" CornerRadius="10" Height="40" BorderThickness="2" Background="White" BorderBrush="Black" >
<TextBox x:Name="txtusername" BorderBrush="Transparent" BorderThickness="0" VerticalAlignment="Center" TextWrapping="Wrap" Text="" PlaceholderText="User Name" Background="White" />
</Border>
<Border Grid.Column="0" Grid.Row="6" Name="cornradpass" CornerRadius="10" Margin="50,5,50,5" Height="40" BorderThickness="2" Background="White" BorderBrush="Black" >
<PasswordBox x:Name="txtpass" BorderBrush="Transparent" BorderThickness="0" VerticalAlignment="Center" PlaceholderText="Password" Background="White" />
</Border>
<TextBlock Grid.Column="0" Grid.Row="7" Name="lblwrong" FontSize="15" Margin="0,0,0,0" TextWrapping="Wrap" TextAlignment="Center" Text="" FontWeight="Bold" VerticalAlignment="Top" HorizontalAlignment="Center" Foreground="Red" Width="390"/>
<TextBlock Grid.Column="0" Grid.Row="8" FontSize="15" Margin="0,0,0,0" TextWrapping="Wrap" TextAlignment="Center" Text="Enter credentials To Authenticate" HorizontalAlignment="Center" Foreground="#5C5C5C"/>
<WebView Grid.Column="0" Grid.Row="9" Name="WebView2" Margin="0,0,0,0" Width="360" Height="30" HorizontalAlignment="Center" />
<HyperlinkButton Grid.Column="0" Grid.Row="10" Foreground="#086A87" FontFamily="Arial Black" FontWeight="Bold" FontSize="20" Content="Forgot password? click here.." HorizontalAlignment="Center" Click="HyperlinkButton_Click"/>
<Grid Grid.Column="0" Grid.Row="11" Margin="0,0,0,0" Background="White">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Grid.Row="0" Content="Login" Margin="0,0,5,0" x:Name="btnlogin1" HorizontalAlignment="Right" Click="Button_Click" BorderThickness="0" Foreground="White">
<Button.Background>
<ImageBrush ImageSource="../Images/button_green.png"/>
</Button.Background>
</Button>
<Button Grid.Column="1" Grid.Row="0" Margin="5,0,0,0" Content="New User" x:Name="btnnewuser1" HorizontalAlignment="left" BorderThickness="0" Foreground="White">
<Button.Background>
<ImageBrush Stretch="Fill" ImageSource="../Images/button_green.png"/>
</Button.Background>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.Row="12" VerticalAlignment="Center" FontSize="15" Margin="0,0,0,0" TextWrapping="Wrap" TextAlignment="Center" Text="Version: 1.79" HorizontalAlignment="Center" Foreground="#5C5C5C"/>
<StackPanel Grid.Column="0" Grid.Row="13" x:Name="Add" Background="Aqua" />
</Grid>
</Grid>
private async void Button_Click(object sender, RoutedEventArgs e)
{
Ringprocess_Activate(prcsring1);
----------------------My Code for Process--------------------
Ringprocess_DeActivate(prcsring1);
}
Can be as simple as
private async void Button_Click(object sender, RoutedEventArgs e)
{
this.IsEnabled = false; // disable the page
Ringprocess_Activate(prcsring1);
// .. your code
Ringprocess_DeActivate(prcsring1);
this.IsEnabled = true; // enable the page
}
If you do it this way make sure you comment out any StoryBoard that enables the "Disable" state, other wise, it will kinda grey out the controls which you probably don't want on that RingProcess Control.

ScrollViewer doesn't scroll to VerticalOffset

I've got a Scrollviewer which has a StackPanel (which contain ExpanderViews)
I'm updating the ScrollViewer VerticalOffset when the ExpanderViews are expanded. However the Scrollviewer doesn't scroll up at all.
The only time the scrollviewer scrolls to a vertical offset is from within FScrollViewer_LayoutUpdated() method. (This is tied to the LayoutUpdated event of ScrollViewer)
Is there any way to update the VerticalOffset (or ScrollToVerticalOffset) from another method?
<Grid x:Name="FilterGrid" Height="696" Grid.Row="0" Background="White">
<Grid.Projection>
<PlaneProjection/>
</Grid.Projection>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollViewer x:Name="FScrollViewer" toolkit:TiltEffect.SuppressTilt="True" LayoutUpdated="FScrollViewer_LayoutUpdated"
MouseMove="FScrollViewer_MouseMove" Width="{Binding ElementName=FilterGrid, Path=ActualWidth}" Height="{Binding ElementName=FilterGrid, Path=ActualHeight}" >
<StackPanel Name="StackPanel" Margin="50,0,0,0" >
<StackPanel x:Name="Header" Height="65" Orientation="Horizontal" Background="Transparent" >
<TextBlock x:Name="HeaderTextBlock" Text="Random text" Style="{StaticResource PhoneTextTitle2Style}" TextTrimming="WordEllipsis" FontWeight="SemiBold" Foreground="Black" Margin="60,5,5,5" VerticalAlignment="Center"/>
</StackPanel>
<Line Width="Auto" StrokeThickness="1.5" Stretch="Fill" Stroke="Gray" X1="2" />
</StackPanel>
</ScrollViewer>
</Grid>

textblock does not fill mobile phone window

I have below code
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent" Loaded="LayoutRoot_Loaded">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="70"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<TextBlock x:Name="ApplicationTitle" FontWeight="Bold" Padding="20,0,0,0" Grid.Row="0" Text="فرآن کریم"/>
<ListBox x:Name="myListBox" Grid.Row="1" Padding="0,0,0,0" ScrollViewer.VerticalScrollBarVisibility="Visible">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Background="{Binding Converter={StaticResource AlternateRowConverter}}" Tap="pQuranAya_Tap">
<TextBlock Width="Auto" Text="{Binding Aya}" Foreground="Black" FontSize="50" Padding="20,0,0,20" TextWrapping="Wrap" Tap="TextBlock_Tap" />
<StackPanel Background="Black" />
<TextBlock Width="Auto" Text="{Binding AyaTranslation}" Foreground="Black" FontSize="35" Padding="20,0,0,20" TextWrapping="Wrap" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I want textblock should be always in window size, but its text size. How can I make it to fill the window size?
Thanks,
Remove <TextBlock Width="Auto" and add <TextBlock HorizontalAlignment="Stretch". After that, your textblock will fit the parent container (window, grid, stackpanel).
Remove Padding="20,0,0,20" And Margin (if You have in that Code )