WinRT XAML Toolkit NumericUpDown Template - xaml

I am using WinRT XAML Toolkit in Windows Universal Application C#.
I want to change distance between plus(+) and minus(-) buttons and increase size of both buttons.
There are templates available for WPF but not for Universal app.
Here is image
Please advice me how can I achieve it?

The template is in the toolkit here.
You might be able to get what you want by changing these button styles to add the Margin:
<!-- DecrementButtonStyle -->
<Style
x:Key="DecrementButtonStyle"
BasedOn="{StaticResource NumericUpDownButtonStyle}"
TargetType="RepeatButton">
<Setter
Property="Content"
Value="➖" />
<Setter
Property="Margin"
Value="5" />
</Style>
<!-- IncrementButtonStyle -->
<Style
x:Key="IncrementButtonStyle"
BasedOn="{StaticResource NumericUpDownButtonStyle}"
TargetType="RepeatButton">
<Setter
Property="Content"
Value="➕" />
<Setter
Property="Margin"
Value="5" />
</Style>

Related

change barcolor Flyout xamarin xaml

somebody knows how to change the bar color, that I point out in the image
bar flyout
If you want to change the background color of Navigation Bar in shell , we could set the style of Shell navigation bar in Resource Dictionary .
<Shell.Resources>
<ResourceDictionary>
<Color x:Key="NavigationPrimary">#2196F3</Color>
<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="Red" /> // set navigation bar color here
<Setter Property="Shell.ForegroundColor" Value="Blue" />
<Setter Property="Shell.TitleColor" Value="Blue" />
<Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
<Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource NavigationPrimary}" />
<Setter Property="Shell.TabBarForegroundColor" Value="White"/>
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
<Setter Property="Shell.TabBarTitleColor" Value="White"/>
</Style>
<Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
</ResourceDictionary>
</Shell.Resources>
For NavigationPage (I assume your detail page is composed of a NavigationPage and inside your HomePage or CurrentNavigatedPageFromMenu, here is a simple style :
<Style x:Key="NavigationPageStyle" TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="Red" />
<Setter Property="BarTextColor" Value="White" />
</Style>
<Style BasedOn="{StaticResource NavigationPageStyle}" TargetType="NavigationPage" />
I separate them to allow to reuse the style on other Navigation page control I've extended.
In code behind, in the constructor of your page (can be usefull to provide a different color depend on the page you are, exemple : red for error page, green for parameter, blue for others).
((NavigationPage)Application.Current.MainPage).BarBackgroundColor = Color.Red;
((NavigationPage)Application.Current.MainPage).BarTextColor = Color.White;
You can find some usefull tips [Xamarin Forum too][1].

How to add a true corner radius to the menu flyout?

Now it looks like this.
I use MenuFlyoutPresenterStyle in MenuFlyout -
<MenuFlyout x:Name="MenuFlyout"
MenuFlyoutPresenterStyle="{ThemeResource MenuFlyoutAcrilickThemeResources}"
>
<MenuFlyoutItem Icon="Paste" Text="Вставить" Click="MenuFlyoutItemPaste_Click" />
<MenuFlyoutItem Icon="Copy" Text="Скопировать" Click="MenuFlyoutItemCopy_Click" />
</MenuFlyout>
</MenuFlyout>
Style code
<Style x:Key="MenuFlyoutAcrilickThemeResources" TargetType="MenuFlyoutPresenter">
<Setter Property="CornerRadius" Value="10" />
<Setter Property="Padding" Value="0,3" />
<Setter Property="Background" Value="{ThemeResource MenuFlyoutBackgroundAcrylicBrush}" />
</Style>
How to fix this?
Use IsDefaultShadowEnabled to false.
<Button Content="Options">
<Button.Flyout>
<MenuFlyout>
<MenuFlyout.MenuFlyoutPresenterStyle>
<Style TargetType="MenuFlyoutPresenter">
<Setter Property="CornerRadius" Value="20"/>
<Setter Property="IsDefaultShadowEnabled" Value="False"/>
</Style>
</MenuFlyout.MenuFlyoutPresenterStyle>
<MenuFlyoutItem Text="Reset"/>
<MenuFlyoutSeparator/>
<ToggleMenuFlyoutItem Text="Repeat" IsChecked="True"/>
<ToggleMenuFlyoutItem Text="Shuffle" IsChecked="True"/>
</MenuFlyout>
</Button.Flyout>
</Button>
You should add another Setter which affects the default shadow property, like this:
<Setter Property="IsDefaultShadowEnabled" Value="False" />
Also I recommend using a corner radius of 3, since that's what WinUI 3 uses.
You can add another Setter to modify the background property:
<Setter Property="Background" Value="Transparent" />
However, depending on your SDK verison, Microsoft recommends a different approach:
Starting in Windows 10, version 1607 (SDK 14393), generic.xaml includes resources that you can use to modify the colors of a control in different visual states without modifying the control template. In apps that target this software development kit (SDK) or later, modifying these resources is preferred to setting properties such as Background and Foreground. For more info, see the Light-weight styling section of the Styling controls article.

Xamarin Forms Styling using StyleClass vs Style attribute

We're building a Xamarin Forms app we've noticed we could style an element in 2 ways by creating styles in the App.xaml ResourceDictionary
Class and StyleClass option
In App.xaml we'll write
<Style Class="EntryStandard" TargetType="Entry">
<Setter Property="TextColor" Value="#575e62" />
<Setter Property="BackgroundColor" Value="#9facb3" />
<Setter Property="FontSize" Value="14" />
</Style>
Then this gets used in one of the contentpages like this
<Entry StyleClass="EntryStandard" Placeholder="Login Name" Text="{Binding EntryEmailAddress}" />
Key and Style option
This is what we write under App.xaml
<Style x:Key="ButtonMainMenu_Purple" TargetType="Button">
<Setter Property="BackgroundColor" Value="#5d4785" />
<Setter Property="FontSize" Value="14" />
<Setter Property="TextColor" Value="#FFFFFF" />
</Style>
And then we use the following in our contentpages
<Button Style="{StaticResource ButtonMainMenu_Purple}" Text="Friends" Command="{Binding OnFriendsButtonCommand}" />
Both work fine, I just wanted to know which one is better than the other and why?
Regular styles follow the standard, relatively inflexible WPF model. Style classes includes cascade semantics and are part of the new theme support. They are poorly documented, however, and still in beta.

How is it suggested to inherit from an implicit style in Xamarin.Forms XAML?

I am having some issues inheriting from an implicit style defined in an Application ResourceDictionary. I have tried a couple of different approaches, but each has been unsuccessful in one form or another.
Attempt 1: Inherit from implicit style
Application ResourceDictionary
<Style TargetType="Button">
<Setter Property="BackgroundColor" Value="#1386F1" />
<Setter Property="TextColor" Value="White" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="HeightRequest">
<OnPlatform x:TypeArguments="x:Double" iOS="30" Android="50" />
</Setter>
<Style.Triggers>
<Trigger TargetType="Button" Property="IsEnabled" Value="False">
<Setter Property="BackgroundColor">
<OnPlatform x:TypeArguments="Color" iOS="#E8E8E8" />
</Setter>
</Trigger>
</Style.Triggers>
</Style>
Page ResourceDictionary
<Style x:Key="LoginButtonStyle" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="BackgroundColor" Value="#024886" />
<Setter Property="Margin">
<OnPlatform x:TypeArguments="Thickness" iOS="0,5" />
</Setter>
</Style>
Page Control
<Button Style="{StaticResource LoginButtonStyle}" />
Result
Throws exception "StaticResource not found for key {x:Type Button}". This is how I remember doing it in WPF, but I'm assuming this isn't supported in Xamarin XAML.
Attempt 2: Inherit from common explicit style
Application ResourceDictionary
<Style x:Key="DefaultButtonStyle" TargetType="Button">
<!-- Same as Attempt 1 -->
</Style>
<!-- This implicit style causes issues with the inheritence of the Trigger in the above explicit style. When it's commented out, everything works fine. -->
<Style TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}" />
Page ResourceDictionary
<Style x:Key="LoginButtonStyle" TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">
<!-- Same as Attempt 1 -->
</Style>
Page Control
<!-- Same as Attempt 1 -->
Result
Everything works except for the Trigger. However, when I remove the implicit style the Trigger magically starts working again. I'd rather not have to specify the explicit style on every Button, though. I believe this is just a bug, but I wanted to make sure before I take the time to prepare a bug report.
Any ideas?
Question in Xamarin Forums
First of all, thanks for the nice summary!
In my opinion this is a bug, which can be prevented with a little trick:
<!-- Base Style -->
<Style x:Key="BaseButtonStyle" TargetType="Button">
<!-- Define base button style... -->
</Style>
<!-- Implicit Style -->
<Style TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}"></Style>
<!-- Inherited Style -->
<Style x:Key="InheritedButtonStyle" TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}">
<!-- Extend base button style... -->
</Style>
Basically, the idea is to create a common explicit base style, which gets inherited by an implicit style afterwards. Therefore, all buttons are automatically applying the BaseButtonStyle, which is additionally extensible.
Attention: The implicit style has to be created after defining the base style.
EDIT: Apparently this is the same solution as #2 already provided before. So, the Trigger issue is not fixed, which seems to be a bug.

Inheritance in Silverlight 2 Styles

I want to build up styles in XAML, e.g.
<UserControl.Resources>
<Style x:Key="MyStyle" TargetType="TextBlock">
<Setter Property="Margin" Value="2,2,2,2" />
<Setter Property="Foreground" Value="DarkRed" />
</Style>
<Style x:Key="MyBoldStyle" TargetType="TextBlock">
<Setter Property="Style" Value="{StaticResource MyStyle}" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
</UserControl.Resources>
But this does not work. (In Silverlight 2) How can I make one inherit from the other?
June 2010 Update: Style Inheritance is in Silverlight 3, use BasedOn="{StaticResource MyStyle}
Nevermind. I found the answer in MacDonald's Pro Silverlight 2 in C# 2008:
(source: apress.com)
"If you've used styles in WPF, you'll find
that Silverlight styles are
dramatically scaled back ... [for example, you can't]
create styles that inherit from other styles."
Too bad. Maybe in Silverlight 3.