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.
Related
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.
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.
I would like to disable all navigation on my FlipView (scrolling horizontally) from user's input (e.g. mouse wheel and touch screen).
The only way the flipview is supposed to change its selected index is programatically, I have already removed the side buttons in the FlipView's style.
I tried changing some of the ScrollViewer's properties in its style but I can't manage to block everything. Anybody can hint me the correct and clean way to do this?
I found the solution by overriding the ControlTemplate and changing ManipulationMode in ItemsPresenter. Just place this code inside your FlipView:
<FlipView.Template>
<ControlTemplate>
<ItemsPresenter ManipulationMode="None"></ItemsPresenter>
</ControlTemplate>
</FlipView.Template>
In my opinion it shouldn't be that difficult to do something simple like disabling user interaction. There should be a property to do that.
You can set IsEnabled property of the FlipView to False.
Hope this help!
I'm trying to style the ComboBox control in XAML but haven't managed to style the colors in the dropdown/popup. The ComboBox seem to contain a ScrollViewer so I'm trying to style that. The items in the ScrollViewer is generated using a ContentTemplate and I guess I need to style it somehow.
Check this default system brush. You can customize these colors by adding below line in resource dictionary.
<SolidColorBrush x:Key="ComboBoxArrowForegroundThemeBrush" Color="MY_COLOR_HEX_CODE"/>
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.