I wan to change style myButton
so but when I come to add, a message show: the resource "AppBarButtonStyle" could not be resolved.
and I discover that it just support three templates:
NavigationBackButtonNormalStyle
NavigationBackButtonSmallStyle
TextBlockButtonStyle
How can I add app bar button styles or some element the same AppBarButtonStyle in Express 2013 for windows
Verify that the ResourceDictionary holding your Style is Visible in the Controls Scope;
Try this :
<Button x:Name="myButton" Style="{StaticResource AppBarButtonStyle}">
<Button.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/YourAssembly;component/Resources/ButtonStyles.xaml"/> <!--Basically your path to the ResourceDictionary-->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Button.Resources>
</Button>
Change the YourAssembly to your your assembly's name which holds the style.
Hope it helps :)
Related
Is there a way to reference a local ResourceDictionary from within the same FrameworkElement's property?
I tried the following
<TextBlock Text="{StaticResource txt}">
<TextBlock.Resources>
<x:String x:Key="txt">asdf</x:String>
</TextBlock.Resources>
</TextBlock>
but get the error
The resource "txt" could not be resolved.
Moving the txt resource from the TextBlock to the Page resources would work but that seems messy and i was hoping that it's possible to reference a FrameworkElements local ResourceDictionary.
Using CustomResource instead of StaticResource at least allows to auto complete to txt, but it doesn't work because then invoking Initializecomponent throws an exception: "No custom resource loader set" and i'm not sure if implementing and setting a custom loader would solve that at all.
Is there a way to do this using the local resource dictionary?
UWP FrameworkElement resource lookup looks for parent control resources, not child control resources.
This document details how Resources works.
Edit
It is recommended to use Resource Dictionary file.
Right click on your project
Choose Add
Choose Resource Dictionary.
You can put your all your resource in this file.
Then add a resource file reference in App.xaml.
Dictionary1.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="txt" TargetType="TextBlock">
<Setter Property="Text" Value="asdf"/>
</Style>
</ResourceDictionary>
App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Page.xaml
<TextBlock Style="{StaticResource txt}" ></TextBlock>
I'm using custom MessageBox in my application and I need to apply my app style to it. So I use WPF Toolkit to create my MessageBox and I'm applying a MessageBoxStyle to my MessageBox :
C#:
Result = Xceed.Wpf.Toolkit.MessageBox.Show(
message,
title,
messageBoxButtons,
messageBoxImage,
(Style)resourceDictionary["MessageBoxStyle"]
);
XAML:
<Style x:Key="MessageBoxStyle" TargetType="{x:Type xctk:MessageBox}">
<!-- My Setters -->
</Style>
The problem is that it displays the basic Windows Vista window theme. I'd like my MessageBox to get the actual Windows theme of the machine (mine is Windows Server 2008 R2 E, but it might change if the application is run on another computer).
Is there a way to set this Windows theme "by default"?
WPF comes with the standard Windows themes on all Windows versions. You can have Aero theme with following steps:
Source: http://mrpmorris.blogspot.com/2008/05/using-vista-aero-theme-in-xp-wpf-apps.html
Add PresentationFramework.Aero to your application's references list as a requires
Edit your App.xaml
<Application.Resources>
<ResourceDictionary>
<!-- Put your stuff here instead -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Other options are :
<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Classic;component/themes/Classic.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Royale;component/themes/Royale.NormalColor.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna.Homestead;component/themes/Luna.Homestead.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna.Metallic;component/themes/Luna.Metallic.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Zune;component/themes/Zune.NormalColor.xaml"/>
I am using the Telerik Windows 8 theme in my WPF application. However, I do not like the way the checkbox checked state is indicated using a colored square rather than an actual checkmark as in the Windows 7 theme. It was very simple to copy the checkbox template and modify it to use the checkbox checkmark from the Windows 7 theme checkbox template.
However, I am having trouble finding a way to add the style that contains this modified template to my Application.Resources in such a way as to apply it to all checkboxes in my application. For some reason, the template in the Telerik Windows 8 theme continues to be the one that is applied.
I have tried a few different approaches, yet nothing seems to work. My latest approach is to add the following style to my Application.Resources resource dictionary:
<Style BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:Windows8Theme, ElementType=CheckBox}}" TargetType="CheckBox" >
<Setter Property="Template">
....
</Setter>
</Style>
Does anyone know the answer to this question? Is what I am trying to do possible?
Thanks,
Craig
Make sure you are ferencing the DLLs from the NoXaml folder of your Telerik install
Don't add any reference to any of the Theme DLLs
In your Telerik WPF install location, go into Themes.Implicit > WPF40 > Windows8 > Themes
Put the .xaml files from there into your solution
Reference them in your App.xaml resource dictionary:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Office2016/System.Windows.xaml" />
<ResourceDictionary Source="Themes/Office2016/Telerik.Windows.Controls.xaml" />
<ResourceDictionary Source="Themes/Office2016/Telerik.Windows.Controls.GridView.xaml" />
etc...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Now you can go into the System.Windows.xaml file, and find the style for the checkbox and edit the style to change the square to a tick
(I think it's the Rectangle called CheckVisual in the Checkbox Template which you need to change)
Like for my other windows phone 8 projects I wanted to use a custom font. But with the new Universal app architecture I struggle to put that in place.
I have created a "Fonts" folder in the shared project, I added the fonts files with the property Build Action to "Content".
I also created a "Themes" folder in the shared project and I added a ResourceDictionnary to it ("Generic.xaml").
I added a FontFamily resource :
<FontFamily x:Key="RexBoldFontFamily">/Fonts/Rex Bold.otf#Rex Bold</FontFamily>
I referenced it in the App.xaml like that:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="true" />
</ResourceDictionary>
</Application.Resources>
In my MainPage.xaml on my Windows Phone project I tried to use it like this:
<TextBlock Text="{Binding HelloWorld}" Foreground="{ThemeResource RedBrush}" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="{StaticResource RexBoldFontFamily}" FontSize="22"/>
I know for sure that this is the name of the font because this works on one of my windows phone app. And all of this is well wired because it works well with a color resource.
Any one succeded to share the font and use it,
You're doing it all right, except for the font name (part after the '#'). It seems to be Rex, not Rex Bold.
<FontFamily x:Key="RexBoldFontFamily">/Fonts/Rex Bold.otf#Rex</FontFamily>
Use this code in ur xaml
<TextBlock x:Name="txtblk" HorizontalAlignment="Left" TextWrapping="Wrap" FontFamily="Assets/filename.ttf#Font Name"/>
I am writing a style for a custom control derived directly from Control. Visual Studio places the style for a "Custom Control (WPF)" in the Themes\generic.xaml file. My style contains an image which I can't get displayed, seems there's something special about how to set the Source for an image from within the generic.xaml file.
I managed to reproduce the issue with a simpler scenario. Create a "WPF Custom Control library" then add a style for buttons like so, in the themes\generic.xaml . Here's my complete generic.xaml:
<ResourceDictionary
...
<Style TargetType="{x:Type Button}">
<Setter Property="Content">
<Setter.Value>
<Image Source="SmallHandle.png"></Image>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
After this I have create a UserControl (in the same project) containing just a button (for the sake of testing out the style) like so:
<UserControl x:Class="BlendControls.UserControl1"
...
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Button/>
</UserControl>
I have added the SmallHandle.png in the root project directory, in the themes directory, I have added it also to the good old Resources page, tried changing the build action to resource, embedded resource, tried copying the image manually to the build directory, but to no effect. The image is never displayed.
This must be related to the generic.xaml file, because copying the entire style to the same file where the Button is placed works fine. That is, the following works as expected:
<UserControl x:Class="BlendControls.UserControl1"
...
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Content">
<Setter.Value>
<Image Source="SmallHandle.png"></Image>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Button></Button>
</UserControl>
So, how should I set the Source of images from generic.xaml? Or alternatively, where should I put the styles/templates for custom controls?
---- Solution ----
As pointed out by Sheridan, I have to use the "full" pack URI notation as:
pack://application,,,/MyAssembly;components/SmallHandle.png
This looks strange to me, as the image is in the same assembly. Not sure, looks like I am referencing from outside the dll.
There's nothing unusual about accessing an image in Generic.xaml, you're just not referencing it correctly. You can reference a resource file in the project assembly using this format:
<Image Source="/AssemblyName;component/Subfolder/SmallHandle.png" />
If your images are directly inside the project root (which is not recommended), then you can access them like this:
<Image Source="/AssemblyName;component/SmallHandle.png" />
If your images are in a folder in another project, then you can access it like this:
<Image Source="/ReferencedAssembly;component/Subfolder/SmallHandle.png" />
See the Pack URIs in WPF page on MSDN for more information.
UPDATE >>>
In .NET 4, the above Image.Source values would work. However, Microsoft made some horrible changes in .NET 4.5 that broke many different things and so in .NET 4.5, you'd need to use the full pack path like this:
<Image Source="pack://application:,,,/AssemblyName;component/Images/image_to_use.png">
If you don't feel as though your generic.xaml is being picked up, you can reference it from your App.cs.xaml like this:
<App.Resources>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MY.NAMESPACE;component/Themes/generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</App.Resources>
Your generic.xaml file should be marked as "Resource".
Also, your image file should be marked as "Resource".
Finally, reference your ImageSource like this:
<Image Source="Themes/IMAGE.png" />
or try
<Image Source="../Themes/IMAGE.png" />
Personally, I like to put my style templates in their own .xaml file, and reference them all as MergedDictionaries.
Typed base style in Themes\Generic style is automatically applied only to Custom Control.
If you need use typed based style in your user control you need add generic.xaml to user control resources.
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Also change Image Source URI to
<Image Source="pack://application:,,,/WpfCustomControlLibrary1;component/SmallHandle.png" />