WPF Style template with recource dictionary - c#

Im new to this so maybe its a very simple thing that might be wrong...
I try to use a style ResourceDictionary but when I try to use it in my application it doesn't work.
This is the directory:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<LinearGradientBrush x:Key ="DarkBackground" StartPoint ="0,0" EndPoint =" 1,1">
<GradientStop Offset="0" Color =" #FF333344"></GradientStop>
<GradientStop Offset="1" Color =" #FF666677"></GradientStop>
</LinearGradientBrush>
<LinearGradientBrush x:Key="StandardBackground" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFF3F3F3" Offset="0"/>
<GradientStop Color="#FFEBEBEB" Offset="0.5"/>
<GradientStop Color="#FFDDDDDD" Offset="0.5"/>
<GradientStop Color="#FFBBBBBB" Offset="1"/>
</LinearGradientBrush>
The Application.xaml looks like that:
<Application x:Class="MyApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="\src\GUI\MainWindow.xaml">
<Application.Resources>
<ResourceDictionary Source ="StyleTemplates.xaml"> </ResourceDictionary>
</Application.Resources>
</Application>
Entrys in the MainWindow:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
In my MainWindow I want to do something like:
<TabItem Header="Project config" Background="{StaticResource StandardBackground}" Margin="-2,-2,2,0" IsEnabled="{Binding ToolPreference.ProjectLoaded}">
What do I have to do next to get the styles as static recources in my MainWindow.xaml and also in all other availabe windows?
In my MainWindow.xaml I can now see the "StandardBackground" when I try this:
<TabItem Header="Project config" Background="{StaticResource x:StandardBackground}" Margin="-2,-2,2,0" IsEnabled="{Binding ToolPreference.ProjectLoaded}">
When I add the "x:" I get a dropdown with StandardBackground and DarkBackground. But the I get the error:(translated from german to english) "The resource: x:StandardBackground could not be resolved"

There's nothing wrong with your XAML. I suspect your StandardBackground and DarkBackground resources would work fine on other controls. Your issue in this case is that the Background property of a TabItem has no effect. You need to look into styling the TabControl to achieve the look you want.
To verify that your styles are at least accessible, you could try the following XAML change:
<TabItem>
<TabItem.Header>
<TextBox Text="Project config" Background="{StaticResource StandardBackground}" />
</TabItem.Header>
</TabItem>

Try
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source ="StyleTemplates.xaml"> </ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

Related

WPF How to reference color resources in other projects

I create a custom control library like this:
enter image description here
Generic.xaml:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/KiwiWPFControl;component/Themes/KiwiButton.xaml"/>
<ResourceDictionary Source="/KiwiWPFControl;component/Themes/KiwiColor.xaml"/>
</ResourceDictionary.MergedDictionaries>
And I create a demo project:
enter image description here
App.xaml:
<Application x:Class="KiwiWPFDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:KiwiWPFDemo"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/LayUI.Wpf;component/Themes/Default.xaml" />
<ResourceDictionary Source="pack://application:,,,/KiwiWPFControl;component/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
MainWindow.xaml:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:KiwiWPFDemo"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:Lay="clr-namespace:LayUI.Wpf.Controls;assembly=LayUI.Wpf"
xmlns:Controls="clr-namespace:KiwiWPFControl.Controls;assembly=KiwiWPFControl" x:Class="KiwiWPFDemo.MainWindow"
mc:Ignorable="d"
Height="800" Width="1000">
<Grid>
<Controls:KiwiButton Content="KiwiButton" FontSize="15" Width="100" Height="50" HorizontalAlignment="Left" Margin="108,191,0,0" VerticalAlignment="Top"/>
<Button Background="{StaticResource HiGreenBrush}" Content="KiwiButton" FontSize="15" Width="100" Height="50" HorizontalAlignment="Left" Margin="108,300,0,0" VerticalAlignment="Top"/>
</Grid>
The code
Background="{StaticResource HiGreenBrush}"
reports : Unable to resolve resource "HiGreenBrush"
Modify App.xaml as follows:
<Application x:Class="KiwiWPFDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:KiwiWPFDemo"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/LayUI.Wpf;component/Themes/Default.xaml" />
<ResourceDictionary Source="pack://application:,,,/KiwiWPFControl;component/Themes/Generic.xaml" />
<ResourceDictionary Source="pack://application:,,,/KiwiWPFControl;component/Themes/KiwiColor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
No change happens
Modify MainWindow.xaml as follows::
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:KiwiWPFDemo"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:Lay="clr-namespace:LayUI.Wpf.Controls;assembly=LayUI.Wpf"
xmlns:Controls="clr-namespace:KiwiWPFControl.Controls;assembly=KiwiWPFControl" x:Class="KiwiWPFDemo.MainWindow"
mc:Ignorable="d"
Height="800" Width="1000">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/KiwiWPFControl;component/Themes/KiwiColor.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Controls:KiwiButton Content="KiwiButton" FontSize="15" Width="100" Height="50" HorizontalAlignment="Left" Margin="108,191,0,0" VerticalAlignment="Top"/>
<Button Background="{StaticResource HiGreenBrush}" Content="KiwiButton" FontSize="15" Width="100" Height="50" HorizontalAlignment="Left" Margin="108,300,0,0" VerticalAlignment="Top"/>
</Grid>
The error is gone
How should I reference the KiwiColor.xaml in App.xaml?
KiwiColor.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Color x:Key="HiGreen">#FF00AAA6</Color>
<SolidColorBrush x:Key="HiGreenBrush">#FF00AAA6</SolidColorBrush>
<Color x:Key="ButtonStepColor">#FF00BB86</Color>
<Color x:Key="HiGreenGradientStep1">#FF00BB88</Color>
<Color x:Key="HiGreenGradientStep2">#FF00AA88</Color>
<Color x:Key="HiBlack">#FF0E0E0E</Color>
<SolidColorBrush x:Key="HiBlackBrush">#FF0E0E0E</SolidColorBrush>
<Color x:Key="HiGray">#FFC0C0C0</Color>
<SolidColorBrush x:Key="HiGrayBrush">#FFC0C0C0</SolidColorBrush>
<SolidColorBrush x:Key="ProgressBar.Background" Color="#C0C0C0"/>
<LinearGradientBrush x:Key="HiBackgroundBrush" EndPoint="1,0" StartPoint="0,0" >
<GradientStop Color="{StaticResource HiGreenGradientStep1}" Offset="0"/>
<GradientStop Color="{StaticResource HiGreenGradientStep2}" Offset="0.5"/>
<GradientStop Color="{StaticResource HiGreen}" Offset="1"/>
</LinearGradientBrush>
I find the point:
1.The "Output type" of the demo project is "Class Library"
2.The "Build Action" of the demo project is "Page"
Then reports : The resource "HiGreenBrush" could not be resolved.
I use another program to start the demo project, so it is set to dll.
And I change the demo project as follows:
1.The "Output type" of the demo project is "Windows Application"
2.The "Build Action" of the demo project is "ApplicationDefinition"
The error is gone.
And this is why #Andy and #mm8 said it should work ok.
How should I reference the KiwiColor.xaml if the demo project is a dll??
I tried replicating this issue.
I have a customcontrol library WpfCustomControlLibrary1 which has my version of kiwibutton in it.
I added a usercontrol library and put a resource dictionary in that.
There's the one brush in that:
<SolidColorBrush Color="Green" x:Key="MyGreen"/>
I merge it in app.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/ColourLibrary;component/ColourDictionary.xaml"/>
<ResourceDictionary Source="pack://application:,,,/WpfCustomControlLibrary1;component/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Have a reference to ColourLibrary and WpfCustomControlLibrary1 in my main project.
In there I have a kiwibutton
<Button Background="{StaticResource MyGreen}"
Content="KiwiButton" FontSize="15" Width="100" Height="50"
HorizontalAlignment="Left" Margin="108,300,0,0" VerticalAlignment="Top"/>
And that works fine for me.
That's one way to implement what you describe.
Ordinarily, I would expect everything that is part of a theme to be in the one theme rather than different projects.
The way custom controls work is rather a complication from that perspective and I rarely use them. I see the reason to have a custom control at all is if you want to completely re template it depending on various themes. Creating a viable all encompassing theme is a lot of work. Very few clients want a full on switchable theme, in my experience. Cost way too much to develop.
I wonder whether there's something subtly wrong with your resource dictionary merging.

what to do to begin my c# uwp animation in onclik?

my code in xml is self explanatory to the seniors in uwp
Unsccestful search of several hours in inet
and very few and complex (beyond my need) animation/layout/components found
its a simple qwestion but i am to totally unable to seize this problem
tried and so but no way to get the thing working
<Page
x:Class="App3.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Width="800" Height="800" >
<Page.Resources>
<LinearGradientBrush x:Key="mibrush">
<GradientStop Color="Red" Offset="0"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="btnbrush">
<GradientStop Color="Yellow" Offset="0"/>
<GradientStop Color="Orange" Offset="1"/>
</LinearGradientBrush>
</Page.Resources>
<Grid Background="{StaticResource mibrush}" BorderThickness="10">
<Button x:Name="miboton" Content="Button" Click="Button_Click" Height="150"
Margin="444,598,0,0" Width="200">
<Button.Resources>
<Storyboard x:Key="buttonAnimation" x:Name="buttonAnimation">
<DoubleAnimation Storyboard.TargetName="miButton"
Storyboard.TargetProperty="(Canvas.Left)" To="200" Duration="0:0:5" AutoReverse="True"
/>
</Storyboard>
</Button.Resources>
</Button>
</Grid>
</Page>
now my cs part of the mainpage
namespace App3{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs args)
{
buttonAnimation.Begin();
}
}
}
crash componets with not installed exception.i can do keyframes animation,an other ones
but the book treats this chapters as standalone not telling me where to start a how to start animations .
In fact i have to idea how to treat event simplest tiggers of animations.Pls some patience with me im nooby in this language.
You need to check the TargetName and Button Name.
These two should be the same.
<Button x:Name="miboton"
<DoubleAnimation Storyboard.TargetName="miButton"

Template10 code works on blank app, but not in an existing project

I just tried Template10 RingSegment, and it worked with a new blank app.
<Page
x:Class="RingSegmentExample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RingSegmentExample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Template10.Controls"
mc:Ignorable="d">
<Grid>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<RelativePanel>
<controls:RingSegment
x:Name="MyRing" Radius="150" InnerRadius="100" StartAngle="-90" EndAngle="90"
>
<controls:RingSegment.Fill>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,1">
<GradientStop Color="#FF727272"/>
<GradientStop Color="Yellow" Offset="0.238"/>
<GradientStop Color="Lime" Offset="0.59"/>
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
</controls:RingSegment.Fill>
</controls:RingSegment>
<Ellipse Width="25" Height="25" RelativePanel.AlignHorizontalCenterWith="MyRing" RelativePanel.AlignVerticalCenterWith="MyRing" Fill="SteelBlue"/>
</RelativePanel>
</Grid>
This was my blank app's code. This is working fine. I installed Template10 and Template10-validation the same way to my existing project with NuGet. In my existing project, even if i only add this to the page:
xmlns:controls="using:Template10.Controls"
And this with a RelativePanel in the same spot in the XAML:
<controls:RingSegment x:Name="MyRing" Radius="150" InnerRadius="100" StartAngle="-90" EndAngle="90" />
I cannot even see anything about the RingSegment in the designer, and the app is crashing at startup at this line:
this.InitializeComponent();
I did everything in the same way like in the blank app. I even tried to replace my MainPage.xaml to the working one and the problem is still the same. It doesnt show any problem in the code, and i cant see the RingSegment in the designer.
Do you have any idea about this problem? I could not find anything about this.
EDIT:
This is the error when i run it:
Exception thrown: 'System.TypeInitializationException' in mscorlib.ni.dll
Exception thrown: 'System.TypeInitializationException' in Template10Library.dll
'CustomSerialDeviceAccess.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\Readdeo\Documents\Visual Studio 2015\Projects\Samples\AACustomSerialDeviceAccess\cs\bin\x64\Debug\AppX\System.Resources.ResourceManager.dll'. Module was built without symbols.
Exception thrown: 'Windows.UI.Xaml.Markup.XamlParseException' in CustomSerialDeviceAccess.exe

XAML: How to bind over 2 properties to a DynamicResourceExtension

I have a ResourceDictionary for Colors:
<ResourceDictionary>
<Color x:Key="Ori">#000000</Color>
</ResourceDictionary>
Then use DynamicResource to reference them:
<DynamicResource x:Key="Ref", ResourceKey="Ori" />
When over 2 properties bind to Ref:
<SomeControl1.Background>
<SolidColorBrush Color="{StaticResource Ref}">
</SomeControl1.Background>
<SomeControl2.Background>
<SolidColorBrush Color="{StaticResource Ref}">
</SomeControl2.Background>
It would cause when running:
"Ref" is not a valid value for property "Color"
I guess that's because they're both TwoWay Bindings.
Any method to fix?
You can simply do it in that way:
<ResourceDictionary>
<Color x:Key="Ori">#000000</Color>
</ResourceDictionary>
Your controls:
<SomeControl1.Background>
<SolidColorBrush Color="{DynamicResource Ori}">
</SomeControl1.Background>
<SomeControl2.Background>
<SolidColorBrush Color="{DynamicResource Ori}">
</SomeControl2.Background>
Using also StaticResource is weird.

Change slider bar color

It should be very easy to do this but I haven't found the information that I need. What I want is as simple as changing the color of the slider bar:
I'm using ModernUI and the default bar color is very similar to my background and I want to make it a bit lighter.
You should be able to change it editing the template.
Right click your Slider, Edit Template -> Edit Copy.;.
A new window will appear asking you where VS should put the XAML code for the ControlTemplate and Styles. Chek the tags and such.
Good luck!
Edit:
Ok, here it goes.
Assuming that you already have a ModernUI App, create a new folder called Assets, right click it Add -> New Item... -> ModernUI Theme. Call it whatever you like it.
Inside the newly created XAML file insert these SolidColorBrush under the AccentColor Color tag:
<SolidColorBrush x:Key="SliderSelectionBackground" Color="Red" />
<SolidColorBrush x:Key="SliderSelectionBorder" Color="Red" />
<SolidColorBrush x:Key="SliderThumbBackground" Color="Red" />
<SolidColorBrush x:Key="SliderThumbBackgroundDisabled" Color="Red" />
<SolidColorBrush x:Key="SliderThumbBackgroundDragging" Color="Red" />
<SolidColorBrush x:Key="SliderThumbBackgroundHover" Color="Red" />
<SolidColorBrush x:Key="SliderThumbBorder" Color="Red" />
<SolidColorBrush x:Key="SliderThumbBorderDisabled" Color="Red" />
<SolidColorBrush x:Key="SliderThumbBorderDragging" Color="Red" />
<SolidColorBrush x:Key="SliderThumbBorderHover" Color="Red" />
Each one of these represents a state of the Thumb (the slider "rectangle"). After that open your App.xaml file and include your theme there (this is what my file looks like):
<Application x:Class="ModernUIApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
<ResourceDictionary Source="/Assets/ModernUI.Theme1.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
The <ResourceDictionary Source="/Assets/ModernUI.Theme1.xaml" /> bit represents my theme.
Setting all the colors to Red, this is what it looked like:
I guess that's more clear!
Hope you like it.
EDIT:
It will change when you apply your theme. But, as you're familiar with styles, I'm sending the complete template. What you can do is create a UserDictionary with only this template and when you you want to use it, change the slider Template property. You'll want to change only the Thumb Tags. Pastebin code
And if you want to change only THIS one put the template between <Windows.Resources> or <Slider.Resources> - Another option would be create your own control
I found two approaches:
You can customize your slider by insert corresponding brushes in
appropriate Slider.Resources section.
You can add brushes to separate xaml file with dictionary and then
merge it with corresponding slider in the Slider.Resources. In some cases it fits better because you can change colors of few controls at once.
Any does not need to changing of the control's template.
Both approaches are presented below:
Page1.xaml
<Grid Style="{StaticResource ContentRoot}">
<StackPanel>
<!-- Slider with default theme and colors from ModernUI -->
<Slider/>
<!-- Slider with custom colors from approach 1 -->
<Slider>
<Slider.Resources>
<SolidColorBrush x:Key="SliderSelectionBackground" Color="Green" />
<SolidColorBrush x:Key="SliderSelectionBorder" Color="Green" />
<SolidColorBrush x:Key="SliderThumbBackground" Color="Green" />
<SolidColorBrush x:Key="SliderThumbBackgroundDisabled" Color="Green" />
<SolidColorBrush x:Key="SliderThumbBackgroundDragging" Color="Green" />
<SolidColorBrush x:Key="SliderThumbBackgroundHover" Color="Green" />
<SolidColorBrush x:Key="SliderThumbBorder" Color="Green" />
<SolidColorBrush x:Key="SliderThumbBorderDisabled" Color="Green" />
<SolidColorBrush x:Key="SliderThumbBorderDragging" Color="Green" />
<SolidColorBrush x:Key="SliderThumbBorderHover" Color="Green" />
</Slider.Resources>
</Slider>
<!-- Slider with custom colors from approach 2 -->
<Slider>
<Slider.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Slider.Resources>
</Slider>
</StackPanel>
</Grid>
Dictionary1.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="SliderSelectionBackground" Color="Blue" />
<SolidColorBrush x:Key="SliderSelectionBorder" Color="Blue" />
<SolidColorBrush x:Key="SliderThumbBackground" Color="Blue" />
<SolidColorBrush x:Key="SliderThumbBackgroundDisabled" Color="Blue" />
<SolidColorBrush x:Key="SliderThumbBackgroundDragging" Color="Blue" />
<SolidColorBrush x:Key="SliderThumbBackgroundHover" Color="Blue" />
<SolidColorBrush x:Key="SliderThumbBorder" Color="Blue" />
<SolidColorBrush x:Key="SliderThumbBorderDisabled" Color="Blue" />
<SolidColorBrush x:Key="SliderThumbBorderDragging" Color="Blue" />
<SolidColorBrush x:Key="SliderThumbBorderHover" Color="Blue" />
</ResourceDictionary>
As result you get following:
Foreground property is used to fill the "completed" part of the slider with a particular color. (Background does the uncompleted part.)
<Slider Value="40" Maximum="100" Foreground="Red" />
Here you have the templates you should use: Slider Styles and Templates
The property you are looking to edit is the TrackBackground.BackGround.
If you define a style for this control template and put it either in you app.xaml or in the window.resources or in any other file, as long as you give it a key you can use it in a specific slider through the "Style" property of that slider using that same key.
Windows 8.1 Store/Phone Apps.
Add this to the App.xaml and change the color values to your liking:
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="SliderTrackDecreaseBackgroundThemeBrush" Color="#FFFF0000" />
<SolidColorBrush x:Key="SliderTrackDecreasePointerOverBackgroundThemeBrush" Color="#FF00FF00" />
<SolidColorBrush x:Key="SliderTrackDecreasePressedBackgroundThemeBrush" Color="#FF0000FF" />
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrastBlack">
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrastWhite">
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
You probably only want to change the slider for the default theme and probably only the three color values shown above. For all colors / resources that you can change, see this link at MSDN: Slider styles and templates.
For what it's worth, the only way I could change the Slider Thumb color on Win10 UWP for Phone was to overwrite the System Foreground brush. (You can also apparently completely re-template the whole Slider)
So, I put into my App.xaml
<Application
x:Class="App1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
RequestedTheme="Dark">
<Application.Resources>
<SolidColorBrush x:Key="SystemControlForegroundAccentBrush" Color="White" />
</Application.Resources>
</Application>
The addition to Application.Resources is the really important thing here. It's where we're overwriting the Foreground color for ALL common elements, like Checkbox, ContentDialog, ProgressRing, etc.... So, that's the downside to this method too.
Changing the Thumb color on a Slider is a known problem point for XAML UWP. Microsoft has plans to make it easier in the immediate future.

Categories