How can i make listitem 100% width? - windows-phone-7

I have some usercontrols that I want to put in a list:
<ListBox HorizontalContentAlignment="Stretch">
<StackPanel x:Name="audioList" />
</ListBox>
but by some reason they I'm not allowed to put the width to 100%. It does not look good, I want 100% width but not by setting it specifically to some pixel as that would break other device screen resolutions (?)

Each item within your list box is hosted within a container. You need to stretch the container as follows:
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>

Related

Style changes keep reverting after restarting the program

I'm working on a mobile app and I want to change the colors of some buttons but every time I change something, the changes revert back when the code itself didn't change.
For example, I'm trying to change the color of a button from purple to blue. So I simply changed the BackgroundColor in the ResourceDictionary:
<ResourceDictionary>
<Style TargetType="{x:Type Button}">
<Setter Property="BackgroundColor" Value="#5E17EB"/>
<Setter Property="Margin" Value="10,30,10,0"/>
</Style>
</ResourceDictionary>
<StackLayout Orientation="Horizontal" IsVisible="{Binding IsPrompt}">
<Button Text="{Binding MessageArgs.Ok}" Clicked="OkClicked"/>
<Button Text="{Binding MessageArgs.Cancel}" Clicked="ClosePopup"/>
</StackLayout>
The change worked, so I stopped running the app, worked on other stuff, but when I come back to the same button, it went back to purple. So I tried changing it to various other colors and the changes worked and then changed it back to the color I wanted. Restarted the app, only for the changes to revert back to the original purple when the code clearly shows a different color.
I'm so confused, what's going on here?

Is there a way that I can determine the display size and use this to adjust the height of a font with Xamarin Forms?

I set the size of a font like this:
<Style x:Key="DetailLabel" TargetType="Label">
<Setter Property="FontSize">
<Setter.Value>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="iOS" Value="35" />
<On Platform="Android" Value="35" />
</OnPlatform>
</Setter.Value>
</Setter>
</Style>
How could I for example change this iOS font size to 20 if I found the mobile application being used was a phone with a smaller display area height?
I read before that Xamarin had some nuget package that could help me with this. Has anyone come across this?

Transparent modal popup in Xamarin.Forms

I was able to create a transparent modal popup in Xamarin forms(Version 2.2.*) by setting the background color of a stack layout to Color.FromRgba(0,0,0,0.5).
But the same is not working when i updated my Xamarin Forms to Version 2.4.*. Do we have any alternate solution to achieve this without using any third party plugins?
I'm talking about using Xamarin.PushModalAsync(View) so that i could see through the View.
You can make a color transparent by setting its alpha channel to a value between 0 and 1.
Here is one I have in my resource dictionary
<Color x:Key="BlockingColor">
<x:Arguments>
<x:Double>0</x:Double>
<x:Double>0</x:Double>
<x:Double>0</x:Double>
<x:Double>0.75</x:Double>
</x:Arguments>
</Color>
The fourth parameter is the alpha channel. Setting it to 0.75 makes it semi-transparent.
You can then use it in a style
<Style x:Key="BlockingPanel" TargetType="StackLayout">
<Setter Property="BackgroundColor" Value="{StaticResource BlockingColor}" />
<Setter Property="HorizontalOptions" Value="FillAndExpand" />
<Setter Property="VerticalOptions" Value="FillAndExpand" />
</Style>
And then use it in XAML
<StackLayout Style={StaticResource BlockingPanel}>
</Stacklayout>

ExpanderView Header width to 100%

I've working on a project where in a page I'm having a ListBox and every ListBoxItem is an ExpanderView control... everything is working ok, but I'm having problems setting the ExpanderView header to have the maximum width (100% of the available space). I've set
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
on my ListBoxItem, but without any success...
The ExpanderView header template is using a grid view which has 1 row and 2 columns (first should have * width, second should have 100)... so far the first column expands based on the content width and doesn't stretch if needed.
Any idea how I could implement this?
Thank you in advance!
Andrei

Setting the foreground color of the page

Hi in my application i displaying the news details. It contains template(hedaline, said by and story). I need to set the foreground of the each textblock as "White" irrespective of the theme color change. Is there any common plalce set the foreground color so it will affect whole page.
Please help me , dont tell me to set the foreground to all textblocks.
Define a Style (without a x:Key) for a TextBlock and it'll automatically affect all TextBlock in your application.
If you want it only affects the whole page, add a Foreground color to the page like this,
<phone:PhoneApplicationPage Foreground="{StaticResource PhoneAccentBrush}" ...
Please note that if you apply any style to your TextBlocks on this page, this color (in this case PhoneAccentBrush) will be overwritten by the color defined in the TextBlock's style.
you can refer to this link http://innovativesingapore.com/2010/08/experession_phone/ for creating style as follows
<phone:PhoneApplicationPage.Resources>
<Style x:Key="MyStyle" TargetType="TextBlock">
<Setter Property="Foreground" Value="White"/>
</Style>
</phone:PhoneApplicationPage.Resources>
And apply to the Text blocks as
<TextBlock Height="49" Name="textblock" Margin="67,49,0,0" Text="WhiteForegroundText" Style="{StaticResource MyStyle}" />

Resources