Whenever I press and hold the button I can see a blue color background till I release the button
I tried to reset it white by using the key ButtonPressedBackgroundThemeBrush
Here is my button code
<Button Content="Submit" BorderThickness="0" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1" FontSize="21" Height="85" BorderBrush="White" Command="{Binding testCommand}" Foreground="{StaticResource Green}">
<Button.Resources>
<SolidColorBrush x:Key="ButtonPressedBackgroundThemeBrush" Color="White" />
</Button.Resources>
</Button>
But its not working for some reason.
Try defining the brush in your application resources:
<Application.Resources>
<SolidColorBrush x:Key="ButtonPressedBackgroundThemeBrush" Color="White" />
</Application.Resources>
This will change the button press background for ALL buttons however. If you want specific buttons to have different backgrounds, you'll need to edit the Button template for each. One simple way to do that is to define a style for each and set the Background to whatever you like during the IsPressed Trigger
<Button>
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
Related
I would like to change ComboBox placeholder color in my demo UWP app. So I tried to create static resources:
<UserControl.Resources>
<Style x:Key="ComboBoxStyle" TargetType="ComboBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<ContentControl x:Name="PlaceholderTextContentPresenter"
Content="{TemplateBinding PlaceholderText}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
Using:
<ComboBox Grid.Row="1" Foreground="White" HorizontalAlignment="Stretch" Background="Transparent"
PlaceholderText="Выбор оператора" Style="{StaticResource ComboBoxStyle}">
<x:String>iPhone 11</x:String>
<x:String>iPhone 12</x:String>
<x:String>Xiaomi Red Mi</x:String>
<x:String>Samsung Galaxy 10</x:String>
<ComboBox.Resources>
<Style TargetType="ContentControl">
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="15" />
</Style>
</ComboBox.Resources>
</ComboBox>
Foreground in placeholder changed correctly but ComboBox is disappeared. How can I will change ComboBox placeholder foreground?
How to change ComboBox placeholder foreground in UWP
UWP ComboBox contains PlaceholderForeground propety, if you want to chage the default one, you just need to give it specific value like the following. And please not the property avaiable in version 16299 or higher.
<ComboBox
Grid.Row="1"
HorizontalAlignment="Stretch"
Background="Transparent"
Foreground="White"
PlaceholderText="Выбор оператора"
PlaceholderForeground="DarkBlue">
<x:String>iPhone 11</x:String>
<x:String>iPhone 12</x:String>
<x:String>Xiaomi Red Mi</x:String>
<x:String>Samsung Galaxy 10</x:String>
</ComboBox>
I have a quick (and most likely) easy question for which I unfortunately do not find a suitable solution. My requirements are as follows:
For the purpose of creating a navigation bar, I want to stack some buttons. For this purpose, I am using a stack panel.
Between each of the buttons, I want to have some space. I could of course set the margin for every button, however I find this solution not very robust and instead want to define the margin centrally.
What I therefore did is I defined a style within the stack panel and set the margin once. This works great with one issue: For the button I would love to use a style provided by Materialdesigninxaml. When I however set the style to the button, the margin style gets ignored.
Has anyone an idea or do I need to make use of a workaround?
Thank you guys for your help.
Here is my sample code which works as no Materialdesigninxaml style is defined:
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Margin" Value="0 10 0 0"/>
<Setter Property="Height" Value="50"/>
<Setter Property="Width" Value="150"/>
</Style>
</StackPanel.Resources>
<Button>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Database" VerticalAlignment="Center"/>
<TextBlock Text="BUTTON 1"/>
</StackPanel>
</Button>
This is my code with a specified Materialdesigninxaml style which does not work:
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Margin" Value="0 10 0 0"/>
<Setter Property="Height" Value="50"/>
<Setter Property="Width" Value="150"/>
</Style>
</StackPanel.Resources>
<Button Style="{DynamicResource MaterialDesignFlatButton}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Database" VerticalAlignment="Center"/>
<TextBlock Text="BUTTON 1"/>
</StackPanel>
</Button>
How can I display a textbox beside a button like in this picture?
A Flyout would be suitable here.
<Button Content="Edit">
<Button.Flyout>
<Flyout Placement="Right">
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="Padding" Value="0"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
</Flyout.FlyoutPresenterStyle>
<TextBox Width="250" Height="100" TextWrapping="Wrap"/>
</Flyout>
</Button.Flyout>
</Button>
Play around with the styles to get the appearance you want.
I'd like to have page headers in my app with either an icon or text centered in a 50px high bar at the top of the page. Optionally with a back-button.
For this reason I use a UserControl on each page which gets either one of those styles applied: PageHeaderStyle or PageHeaderBackStyle.
My implementation of one of those is the following (style definition in my App.xaml):
<Style x:Key="PageHeaderBaseStyle" TargetType="UserControl">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Height" Value="50" />
<Setter Property="Width" Value="NaN" />
<Setter Property="Background" Value="{StaticResource CDColor}" />
</Style>
<Style x:Key="PageHeaderStyle" TargetType="UserControl" BasedOn="{StaticResource PageHeaderBaseStyle}">
<Setter Property="Content">
<Setter.Value>
<Grid Background="{StaticResource CDColor}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DataContext="{StaticResource MainPageModel}">
<TextBlock Style="{StaticResource PageHeaderTextBlockStyle}" Text="{Binding Title}" Visibility="{Binding TitleVisibility}" />
<Image Style="{StaticResource PageHeaderIconStyle}" Source="{Binding Icon}" Visibility="{Binding IconVisibility}" />
</Grid>
</Setter.Value>
</Setter>
</Style>
Applied like it should be:
<UserControl Style="{StaticResource PageHeaderStyle}" />
Now first I had used "Template" and applied a DataTemplate with the grid component. But this didn't work. Then I changed it to directly set the Content of the UserControl. This does work: After building the designer shows the page header (before it showed only the blue selection border, but no content - it was transparent).
But as soon as I start debugging the app on the emulator it disappears and the running app only shows a blank spot where it should be.
Why is this so? I mean after all the designer already shows it, why does it disappear then, though?
FYI: I do not get any binding exceptions nor any other. It just doesn't show up.
PS: I tried setting the Background in the base style while setting the grid's background to transparent. This didn't work either - only a blank spot.
Solved the problem: Best approach is probably to use a ContentControl. Using the Content property did not work, though. You have to use the ContentTemplate property. Using that one does work just fine.
I have three buttons, one on top of the other in XAML like so:
<Grid>
<Button
Width="50"
Height="50"
Background="Red"/>
<Button
Margin="10"
Width="50"
Height="50"
Background="Blue"/>
<Button
Margin="20"
Width="50"
Height="50"
Background="Green"/>
</Grid>
How do I change their Z-Order when the mouse is over them?
Put this to the Grid.Resources
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Panel.ZIndex" Value="99999"/>
</Trigger>
</Style.Triggers>
</Style>
when IsMouseOver is false the button instances gets back its original zindex value