How do I change a button's background image in a Metro Style app using VS 2012?
In Windows Forms, a button has a BackgroundImage property that you can set.
Is this feature available for Metro Style apps?
In Windows Forms, I can do the following in C#:
btnImage.BackgroundImage = System.Drawing.Image.FromFile("...\Pictures\flower.png");
How can you programmatically change the button's background image in Metro Style apps ?
Pretty straightforward, actually, just modify the Button's XAML to include a closing tag, and drop an image control in between, like so:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button HorizontalAlignment="Left" Margin="532,285,0,0" VerticalAlignment="Top" Height="135" Width="283">
<Image Source="Assets/Logo.png" />
</Button>
</Grid>
In the snippet above, I'm pointing the image source to the Logo.png file that is part of the built-in templates for C#/XAML apps.
Another way to do it is to open the project in Blend for Visual Studio, drag the image from the Assets tab onto the design surface (making sure you have the desired container selected in the Objects and Timeline pane), and then right-click the image and select Make into Control..., and choose the Button control.
The only downside to this technique is that you don't get the default VisualStates that the built-in Button control has. Instead, Blend defines a style for you with empty VisualStates which you can style as desired.
Hope that helps.
Related
I'm using Microsoft.UI.Xaml.Controls.NavigationView. For some reason, I have to change NavigationView's pane background.
So I changed in XAML.
<Page.Resources>
<SolidColorBrush x:Key="NavigationViewDefaultPaneBackground" Color="{StaticResource ViuPageBackgroundColor1}" />
</Page.Resources>
But now I want to achieve this in cs code, how to do that.
The NavigationViewDefaultPaneBackground brush is used for a property called PaneBackground of the Splitview control. The Splitview control called RootSplitView is one of the components of Navigationview.
If you want to change the PaneBackground property in code-behind, you need to search in the NavigationView's template and find the Splitview control by name -RootSplitView. Then when you get the Splitview control, you could change the PaneBackground as you want.
I am trying to add a Backdrop blur in my Windows 10 UWP app, however the blur effect doesn't work. I am using the code from Windows UILabs Github, but the blur effect simply doesn't show. I also tried making my own simplified code, but that didn't work either (didn't throw any exceptions though). In the XAML, I am using
<Grid x:Name="grid_blur" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="0,0,0,55" Height="100" Background="Transparent">
<local:BackDrop BlurAmount="40" TintColor="Red"/>
</Grid>
to add the Backdrop control itself.
I am using VS2015 Community Update 2, project target version is build 14295.
Does anyone have the same problem or am I simply missing something (or should I stop copy & pasting from github?). Thanks in advance.
Don't know UILabs but you can also use Win2D to apply a blur effect. Please check the following article https://www.eternalcoding.com/?p=1911. In next version of UWP SDK, Windows Composition will provide you also a native way to perform Blur, Drop Shadow and Light effects.
For example in browsers I can manipulate DOM from JS.
Are there any analogue API?
Is it possible at all?
Update:
We define UI using XAML while developing UWP application.
Can I change UI defined by XAML or is it fixed forever?
You can absolutely change the UI at run time.
Add controls, remove controls, change properties, apply transforms or behaviours, restyle things. It's all possible.
As a simple example.
Given this XAML:
<Page
x:Class="SO33419586.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="TheGrid"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock>bye bye</TextBlock>
</Grid>
</Page>
we can do the following in code behind:
this.TheGrid.Background = new SolidColorBrush(Colors.Chartreuse);
this.TheGrid.Children.Clear();
this.TheGrid.Children.Add(new Button {Content = "click me"});
When run this creates a view with a green (chartreuse) background and containing a button but no textblock.
The key part here is the x:Name assigned in XAML as that makes it simple to reference controls created that way.
<Button Content="Reset" Click="ResetResalePrice_Click">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border>
<Image Source="Assets/Reset.png"/>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
Hey guys! I have been searching like crazy , how do I set the style to this button to act as a default button , I mean to change the background for example , to react on click , just like default template. I searched , but everywhere says that I should use and it seems that there is no Triggers property. Thanks in advance!
EDIT 1 : I just tried setting the content of the button to a border/grid/stackpanel and then set the image there but it looks horrible , a big gray square with an image in the middle.
EDIT 2: Well I just removed the brush for the background of the button , exactly what I wanted , but I there any way I can add a Zoom effect?
Trigger property is not available on Windows Store App, if you need something similar like trigger, ref to this doc: Button styles and templates, there are several visual states and modify into them will bring you the surprise.
For example if you need click trigger, look into the "Pressed" visual state.
This is the XAML code for a simple toggle button in Windows Phone 8.1.
<ToggleButton Content="Text_Here" />
How can we show an icon for the same Toggle Button??
ToggleButton has ContentPresenter inside - you can put most of things into it for example icon:
<ToggleButton>
<SymbolIcon Symbol="Message"/>
</ToggleButton>
or Image if you want:
<ToggleButton>
<Image Source="image.jpg"/>
</ToggleButton>
or any Panel, Button another ToggleButton and so on.
You can also play with its Style and Enabled/Disabled Content.
First you can try if the AppBarToggleButton fits your needs. It toggles an Icon.
Else, you have to edit the ControlTemplate for the ToggleButton. (In Designer: Right click it, got Edit Template -> Edit a Copy).
The default Template features two content presenters for enabled and disabled content, which you can replace to display your icons.