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>
Related
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?
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?
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>
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}" />
I need to create an Image Button for my application like web-oriented style.
I have an image 20x20 pixel and want an image button with the same dimension of the image.
I tried to set this inside my xaml but it doesn't work:
<Button Grid.Row="0" Margin="0" Padding="0" Click="AddtoFavorite_Click" Width="20" Height="20" VerticalAlignment="Top" HorizontalAlignment="Right">
<Button.Content>
<Image Source="/MyNamespace;component/images/star_yellow.png" Margin="0" Width="20" Height="20" />
</Button.Content>
</Button>
What is wrong?
SOLUTION
I found the best solution is:
<Image Source="/MyNamespace;component/images/star_yellow.png" ManipulationStarted="Image_ManipulationStarted" Width="20" Height="20"></Image>
Thanks to all!
I don't see particular errors in your code but I don't have the tools right now to test it ans see why it fails.
However you can create a VisualBrush with your image and use it as background for your Button:
<Button>
<Button.Background>
<ImageBrush ImageSource="xyz.png"/>
</Button.Background>
</Button>
Most Backgrounds are of type Brush, so you can use SolidColorBrush, LinearGradientBrush, ImageBrush, etc. You are not limited to colors.
I think the best solution is the following:
<Button ...>
<Button.Template>
<ControlTemplate>
<Image .... />
</ControlTemplate>
</Button.Template>
</Button>
Using manipulation started will result in subtly non-standard behaviour. On most buttons if you click on it but then drag off, the button click will not fire. However, if you use ManipulationStarted it will fire immediately.
The best way to manage these design time considerations is to use Expression Blend. In blend you can right click on the button and edit the template through the design tools, which makes knowing how to edit the xaml less important. It's really worth the effort to learn to use Blend.
This is old but I thought I would offer what I thought was a better solution here. Some of these solutions want you to replace the button with an image, or the background with an imagebrush. That's fine except it also surrounds the image with the normal button style, a black or white box (depending on your theme).
This solution lets you use an image as the button itself while maintaining the complete fidelity of a button but without having to subclass an object like the link by SilverGeek.
First, create a new style (either in your App.xaml or your page resources)
<Style x:Key="ImageButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Image x:Name="StartButtonImage" Source="/Images/YourImageFile.png"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content=""/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
Now, just create a button anywhere using that style:
<Button Style={StaticResource ImageButtonStyle}/>
And add click events or whatever else you want. The button will take on the entire style of the image.
Maybe you will be interested in this article:
http://silvergeek.net/2011/01/14/imagebutton-control-for-win-phone-7/
The Button control can take most controls as its content (not just text), so you don't need an "image button" - instead, you simply need to put an Image control inside your Button like so:
<Button>
<Image Source="http://www.richmondwiki.org/images/search-button.png"></Image>
</Button>
This approach (as opposed to using an ImageBrush for the Button background) means that you don't have to worry about or hardcode the sizes of the Image/Button - WP7 will handle this for you.
Using the provided Button control instead of hooking into the manipulation events is recommended, so that you won't have to worry about things like having appropriate margins for touch targets, etc.
You can set your image as the background for the button, or if you want to do it as content, in theory it should work inside a stackpanel.
You don't even need to use a Button.
You can hook the MouseLeftButtonUp event on the Image control.
<Image
Source='blue02.png'
Width='26'
Height='26'
Margin='5'
MouseLeftButtonUp='Image_MouseLeftButtonUp' />