I am trying to make an InkToolbar whose ballpens and pencils' size can't be changed. Basically, the actual appearance is this one (the button has a slider with a "size" text) and I want to remove it so it looks like this, without that slider. I've read the whole tutorial about custom ink toolbars, but I haven't been able to find the property that I want to remove. In fact, I'm not sure if I can do so.
Is there any way to prevent users from seeing and using this size property?
You can custom InkToolbarPenConfigurationControl located in Generic.xaml in your pc.
For details.
Step 1, open Generic.xaml, find text <Style TargetType="InkToolbarPenConfigurationControl">, copy out the whole Style, you can also see on my gist.
Step 2, paste the style code to your App.xaml. Note this will override all your InkToolbarPen button.
<Application
x:Class="App2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App2">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/FavoriteButtonStyle.xaml"/>
<ResourceDictionary Source="/BorderlessGridViewItem.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!--Paste your style code here-->
</ResourceDictionary>
</Application.Resources>
</Application>
Step 3, find the Slider control, set Visibility to Collapsed. Done!!!
Related
I'm working on a UWP project, and I need to change the button's background and foreground colors as the app is running. I have managed to do that, but I also have a piece of code that let me disable the annoying hover effect present in all UWP buttons.
There is my App.xaml code:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="ButtonForegroundPointerOver" Color="White"/>
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="Gray"/>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Application.Resources>
I was wondering how can I change the "color" property to match each button's state (they have different colors and backgrounds). Is there an option to set the color to the ButtonBackground property by default. If not, how can I change each button's style at runtime?
You have many ways to change button's style in the runtime, as you code mentioned above, you have place the ButtonForegroundPointerOver SolidColorBrush in the ThemeDictionaries and give them light dark or default key, when you change the app's theme, it will apply the matched ButtonForegroundPointerOver for button control that used the default style.
how can I change each button's style at runtime?
Button's style property could be set at runtime, you could make different button style with key name, and load it from page or application resource then apply to button style.
For more info please refer XAML styles document.
I work on C# WPF
I have more than one DataGridView all of them has the same style (Background, row width, column height...etc) but each one has different numbers of columns
So my question is Can I make one style for these grids and share between them?
like css in Web
You can create a resource file in wpf where you can store all your style and template. Don't confuse it with the resource file in the Properties directory. You can add a Resource file by right clicking your project in visual studio and adding an existing xaml file or creating a new one.
After that, define all your styles and templates. Then you only need to include it in your available resources
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="UsingResourceDictionaries.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="myDirectory/myDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Don't forget to give a key to each one of your style and template, so that you can use them in your User controls
i am Using the Fluent-Ribbons to create my view in wpf.
to have a better organisation of my code i wanted to put the different RibbonTabItems into their own files.
The problem is:
the designer does not show the content of the ribbontab.
I only see the a blank page.
Is there a way to make the RibbonTab visible in the designer?
If anyone else lands here from google, I was having this situation where the ribbon was not only invisible in the designer, but also not showing at runtime. After spending some time, I found that you have import generic fluent ribbon theme resources into your Window or Application Resources section, like this:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Fluent;component/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
After this my ribbon started showing in the designer as well as at runtime.
You can also use other themes in the same way. Just override the generic theme like this:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Fluent;component/Themes/Generic.xaml" />
<!-- change "Cobalt" to the color you want -->
<ResourceDictionary Source="pack://application:,,,/Fluent;component/Themes/Themes/Dark.Cobalt.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
Hope this helps someone down the road.
Credit to the project documentation at github.
I have a prism application and various modules. I am wondering where is the best place to locate resources such as styles, brush, controltemplates, datatemplates?
Should I make one single resource dictionary and put everything there? Should each module have their own resources? Or each view? I would like to follow the Prism goal of keeping everything modular, but also I dont see the point in re-declaring the same resources in every module...
I develop application with Prism, and I use technique very close to described in Prism's manual. There is YourApplication.Infrastructure project, where you usually place all your shared interfaces etc. So:
I just add project YourApplication.Resources
Create there folder Themes
Create separate xaml file in Themes folder for each group of resources (like Generic.WPF.xaml for standard WPF controls' styles, Generic.Brushes.xaml for brushes etc.)
Create file Themes\Generic.xaml (exactly with this name, it will add huge benefits in the future) with content like
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Generic.Brushes.xaml"/>
<ResourceDictionary Source="Generic.WPF.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Now you can add those resources in any module (you have separate project for it, right?) by adding reference to YourApplication.Resources to that project and adding to your view's xaml:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/YourApplication.Resources;component/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!-- Put your not shared resource here -->
</ResourceDictionary>
</UserControl.Resources>
I don't know, maybe this way has some problems, but it works, and works well for me. If anybody can comment somehow this way (pros/cons) - I will be very happy to hear it!
Application-wide resources I usually put in a ResourceDictionary, which is added to either App.xaml or StartupWindow.xaml
Resources for a specific View are usually located with the View. For example, a UserControl that is being used for a CalendarView will contain any custom resources for the Calendar, such as calendar-specific brushes, styles, templates, etc.
I usually don't see a reason to make module-wide resources, but if I ever do I'd have a ResourceDictionary for the Module which can be loaded into the app's merged dictionaries at runtime, or included in individual Views in the Module.
I would like to share some new knowledges. I am using #chopikadze approach. And it is really cool approach. Thanks to you!
However, if you do not want write every time for each control these piece of code:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/YourApplication.Resources;component/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!-- Put your not shared resource here -->
</ResourceDictionary>
</UserControl.Resources>
Then you can just declare <ResourceDictionary/> in App.xaml of your Bootstrapper like that:
<Application.Resources>
<ResourceDictionary Source="pack://application:,,,/YourApplication.Resources;component/Themes/Generic.xaml"/>
</Application.Resources>
I'm working on a semi-large windows application using wpf and C# in VS 2010. While working on the xaml, I added a tag so that all buttons and datagrids are styled in the same way. I've copied and pasted this block into several of my .xaml files and that works fine. Of course the problem I'm running into now is that I've added to and changed the style several times.
What is the best way to keep style consistent between my different Windows? Is it subclassing, using Resources.resx, or another way enirely?
If you define the style in the Application level ResourceDictionary (App.xaml), then it will automatically be inherited by your other XAML Windows/Controls.
yeah, if you were to create a new file called Resources.xaml and then add this to your Application.xaml file:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
then you should be able to reference the styles in the Resources.xaml from all the windows in your application.