Following this tips, (Xamarin.Forms: how to set background image of NavigationPage bar)
I change the Navbar bg image.
I can change this image in specific pages? Already exist some custom render for that?
Use various navbar's backgrounds...
I think you might succeed doing what you want with the new TitleView introduced in Xamarin Forms 3.2 for NavigationPage without any CustomRenderer or platformspecific code.
<NavigationPage.TitleView>
<Image Source="main_background_image.png" Aspect="AspectFill">
</Image>
</NavigationPage.TitleView>
https://learn.microsoft.com/fr-fr/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical#displaying-views-in-the-navigation-bar
Related
I'm creating a mobile App. In this app there is the user's profile and i would like give an an octagonal shape to the user's profile. For the moment I have just an image:
<Image x:Name="ProfilePicture" HeightRequest="100" HorizontalOptions="Center" Source="Profile.png" TranslationY="50" VerticalOptions="End"/>
how can I shape this image?
The result I would like to achieve is this:
a yellow outline and instead of the gift the user image
Xaml doesn't support drawing shapes directly. You have several options:
Simple. Use shape image as resource. Put it all together with with grid or absolute layout.
Smart. Use Font Awesome icons in your XF. You can reuse other icons to reduce bitmaps in your app. Unfortunately octagonal shape is available only in PRO edition.
Heavy artillery. You can use Skiasharp or similar library to draw octagonal image with user image inside.
Hope it helps.
I have a UWP app and I want to upgrade it to fluent design system. I have created a new project using Windows Template Studio and my navigation is with Pivot.
Now I want to put acrylic background on the header of the pivot. as mentioned in the design guidelines of uwp it is recommended to use 70 percent acrylic in this scenario.
So I tried to use 70 percent acrylic with following code.
private void MainPivot_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush"))
{
MainPivot.Background = Application.Current.Resources["SystemControlAltHighAcrylicWindowBrush"] as AcrylicBrush;
}
}
Where MainPivot is the pivot I am using and this loaded method is loaded event for that pivot.
The problem is that it works only for either Light or Dark Theme (depends which theme was set during last run of the app), but when app is running and I change theme and switch between light or dark themes, it doesn't work well for both themes, for example if I make the theme dark the acrylic color remains white and pivot header text is also white hence creating disturbed UI.
Also the FallBack Color doesn't make sense either, for light theme fallback color is black (which blends in with black text) and same problem occurs in dark theme.
The reason I am doing it from code behind because the min project target of my app is creators update which doesn't have acrylic brush.
The Conditional XAML provides a way to use the ApiInformation.IsTypePresent method in XAML markup. This lets you set properties and instantiate objects in markup based on the presence of an API without needing to use code behind.
To use a conditional method in XAML, you must first declare a conditional XAML namespace at the top of your page.
xmlns:IsAcrylicBrushPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsTypePresent(Windows.UI.Xaml.Media.AcrylicBrush)"
xmlns:IsAcrylicBrushNotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsTypeNotPresent(Windows.UI.Xaml.Media.AcrylicBrush)"
After the namespace is defined, we can use the namespace prefix to the Background property of your Grid to qualify it as a property that should be set conditionally at runtime.
<Grid Name="MainPivot" IsAcrylicBrushPresent:Background="{ThemeResource SystemControlAltHighAcrylicWindowBrush}" IsAcrylicBrushNotPresent:Background="Red">
If the device supports AcrylicBrush, it will use the SystemControlAltHighAcrylicWindowBrush. If not, it will use the Red color.
I am using MapBox to display a custom map of a specific area. In MapBox: my specific area is yellow and the rest of the map is transparent (see following image).
What I want to achieve:
I want to put a MapControl over a Background Image. So when the tiles of the map are transparents, I can see the background image.
The problem I have:
In my UWP app, the specific area of the map is displayed correctly (yellow) but the rest of the map is black thus the background image is hidden by the map.
There is no problem with MapBox because the generated tiles are transparent. I think the problem is in my app.
I tried to set the background of the MapControl to Transparent with no success.
XAML
<Image x:Name="background"
Stretch="UniformToFill"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
<maps:MapControl x:Name="MyMap"
Background="Transparent"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
MapServiceToken="TOKEN"/>
C#
HttpMapTileDataSource leaflet = new HttpMapTileDataSource(
"URL_TO_MAPBOX_API");
MapTileSource mts = new MapTileSource(leaflet);
mts.IsTransparencyEnabled = true;
mts.AllowOverstretch = true;
mts.IsFadingEnabled = false;
this.MyMap.TileSources.Add(mts);
this.MyMap.Style = MapStyle.None;
Am I doing something wrong or is it simply not possible?
Thanks for your help
The MapControl is a very complicated control. It uses a SwapChainPanel to interop with Direct X. It would suprise me if what you try to do is possible.
I have a method that is triggered every time a user performs an action, within this method I want to trigger the color of an image to change color/illuminate every time the method is called.
Is there a simple way to change the color an image programmatically? I can't see any obvious methods or properties to do this attached to the image.
So the method below is as follow just not sure how to set the image color for BoxBagImage
void matcher_GestureMatch(Gesture gesture)
{
lblGestureMatch.Content = gesture.Name;
scoreCntr++;
boxBagImage. // <-- don't see any color or background property belonging to the image
lblScoreCntr.Content = scoreCntr;
}
What would setting it do? How WPF should guess what "background" you have in mind? There's couple of things that could be called 'background'. Also, how would WPF guess how large area you consider to be the background?
Let's start with the fact that Image displays a bitmap (or such) all over its area, so direct Foreground or Background are rather meaningless here. They would be overdrawn by the bitmap immediately. It's not like TextBox or Canvas.
That's probably why Image does not have such property.
--
If your bitmap itself has a "background" (ie. a drawing of a Tree on a blue sky, sky=background), it is still the content of the bitmap. WPF is not an image-editing program and will not change it for you easily. If you want to change the "background" withing your image, you can load the bitmap, modify its pixels, and load the modified bitmap into Image control. Or apply some smart filter (so-called "effect") at rendering stage.
Or, if your bitmap is transparent (for example, PNG with alpha channel, a Tree on a completely-alphaized-transparent pixels), and you want the "some background" to be seen through that "transparent gaps", then you have to set the background of not the image itself, but the component that the image lies on. So, if you have for example:
<Grid> <Image Source=.... /> </Grid>
then apply the Background on the Grid. Transparent-Image placed on a Blue-Grid will look as if were on blue background, just like drawing on a glass placed on blue table. In fact, the Grid here simply forms the background. You can get any layout or effect in that way. If you dont want to have whole grid in that color, you can inject another grid:
<Grid>
<Grid Background="Blue" Margins="30,30,30,30"> <Image Source=.... /> </Grid>
</Grid>
or whatever you like.
Or, if you meant the "background" of the Image control that shows up when the Image has its Stretch property set in a such way, that the bitmap does not fill the whole area (Stretch=Uniform likes to do that unless you carefully set Width/Height) - then simply look above. The "area" is simply transparent, so just add some color to the component beneath Image.
I'm having weird issues with the LargeImageSource for the Application menu (using Office2007Blue theme)
My image is 48x48 but it appears to be scaling down to 10x10. It's not using SmallImageSource at all.
<r:Ribbon.ApplicationMenu>
<r:RibbonApplicationMenu>
<r:RibbonApplicationMenu.Command>
<r:RibbonCommand
SmallImageSource="images/icon.png"
LargeImageSource="images/icon.png"
ToolTipTitle="Application Menu"
ToolTipDescription="Click here to open files or close the application." />
</r:RibbonApplicationMenu.Command>
<r:RibbonApplicationMenuItem>
<r:RibbonApplicationMenuItem.Command>
<r:RibbonCommand
LabelTitle="_Close"
LabelDescription="Close the Application"
/>
</r:RibbonApplicationMenuItem.Command>
</r:RibbonApplicationMenuItem>
</r:RibbonApplicationMenu>
</r:Ribbon.ApplicationMenu>
Changing the image's printed dimensions fixed it. The button doesn't look at the pixel dimensions.
The WPF Ribbon is full of bugs. This one in particular is because the SmallImageSource Image is hardcoded to 16x16 in the RibbonApplicationMenu's control template. LargeImageSource isn't even used anywhere in the default theme.