How to change a SystemParameter on the OS level? - wpf

I learned to in order to pick up System Parameter one should use dynamic resources. I take this XAML as an example:
<Grid
Background="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey} }"
>
<Button
Width="100" Height="50"
Content="{DynamicResource {x:Static SystemParameters.IconWidthKey} }"
/>
</Grid>
How would I change these values, e.g. WindowFrameBrushKey in Windows 10 to see the effect on my program? I tried Settings -> Personalize -> Colors -> Choose accent color, but no success.

The WindowFrameBrushKey is getting its value from the Windows registry. I'm writing this solution from this post:
Open the Registry Editor (regedit)
Go to the Registry key: "HKEY_CURRENT_USER\Control Panel\Colors" and search the string value WindowFrame
The value is in the "Red[space]Green[space]Blue" format. Change to the value you need.
Sign out and then sign in to make the changes apply.

Related

Can I use a ViewBox as a Source for an Image in WPF?

I have an icon that's defined in XAML and the root element is Viewbox. I would like to set that as a Source of an Image element.
I tried to set it directly as a source for an Image like...
<Button Margin='5'>
<Image Source='{StaticResource IconKey}'></Image>
</Button>
But I get an exception. Is there a way to do that?
This is kind of a big subject and tricky for beginners because there's so much "stuff" you need to get your head round.
I'll try and cover a few things around the subject. Hopefully that might reduce your confusion a little.
A Path uses data which looks a bit weird what with all that strange co-ordinate stuff. This can go directly in a path, or in a Geometry ( or a stream geometry ). If you use a geometry then that is re-usable for a red-whatever blue-whatever etc. It is also not a visual so you don't get caught out by visuals only being able to have the one parent - ie one use in any ui.
The way I'd usually go about this sort of thing is to obtain a single geometry.
Often out of syncfusion metro studio ( which is a free library ) but sometimes I use inkscape ( free ) to trace a bitmap or I get a path out a svg.
You can however combine two geometries.
In a resource dictionary merged by app.xaml you could have a geometry:
<CombinedGeometry x:Key="TwoGeometriesInOne">
<CombinedGeometry.Geometry1>
<Geometry>
M3,1.6675c0,-0.1795..... and the rest of your first geometry data
</Geometry>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<Geometry>
M15.9289,7.776L5.285,....
</Geometry>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
Huge long strings mess up the site, but those two geometries should just have the M... through to the z of that data you're using for each path.
Use that in a button ( or any other content control )
<Button Height="40" Width="40">
<Path Fill="#3E79B4" Data="{StaticResource TwoGeometriesInOne}"
Height="16"
Width="16"
Stretch="Fill"/>
</Button>
Note that a path can just be used on it's own rather than in a canvas and sized, it can also be stretched to fit it's size or whatever the parent allows.
Consider also:
<Button Height="40" Width="40">
<Path Fill="#3E79B4" Data="{StaticResource TwoGeometriesInOne}"
Stretch="UniformToFill"
Margin="5"
/>
</Button>
With a path you have fill and stroke. Stroke is the outline. If you want different coloured shapes in one "icon" then a drawingimage with multiple geometrydrawing would be more suitable because each geometryimage can have it's own brush.
I found an alternative. Instead of Using an Image inside the button I used Button's Content attribute.
<Button Content='{StaticResource IconKey}' />

How to make custom close button in wpf?

I want to create following form but problem is there when I'm setting the margin with negative value then it will not work and hide my cross image. Is this possible to create as it is? or any other way to create this form.
My need:
(in below image black area is transparent)
But now show my form like below image:-
Please let me know appropriate way.
You can't draw outside of your application, without using Adorners or Popups, as Akku says in the comments.
But what you can do is to, instead of making margins negative, make them positive. So that your content (the gradient background), have a margin of 10 or 20 (or whatever number that produces the right amount of spacing.
<Window (.....) AllowsTransparency="True" WindowStyle="None">
<Grid>
<Button VerticalAlignment="Top" HorizontalAlignment="Right" Height="15" Width="15"/>
<Border Margin="15">
<YOUR_CONTENT>
</Border>
</Grid>
</Window>

Path.Data styling works only on first instance of styled object

A have a ListBox of items, every ListBoxItem contains an icon in the form of a Path object, like so:
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ...>
...
<Path Margin="4" Style="{StaticResource ErrorIconPath}"
Stretch="Uniform" Width="26" Height="26"
RenderTransformOrigin="0.5,0.5" Grid.Column="1" Grid.Row="1"
UseLayoutRounding="False"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
The Path's style is contained in Appl.xaml (Application.Resources section) and is the following:
<Style x:Key="ErrorIconPath" TargetType="Path">
<Setter Property="Data" Value="F1M874.094,289.369L854.3,254.63C854.028,254.151 853.515,253.856 852.958,253.856 852.403,253.856 851.89,254.151 851.617,254.63L831.824,289.369C831.555,289.84 831.559,290.416 831.835,290.883 832.111,291.348 832.618,291.634 833.165,291.634L872.752,291.634C873.299,291.634 873.805,291.348 874.081,290.883 874.357,290.416 874.361,289.84 874.094,289.369 M855.653,287.189L850.264,287.189 850.264,282.745 855.653,282.745 855.653,287.189z M855.653,279.41L850.264,279.41 850.264,266.077 855.653,266.077 855.653,279.41z" />
</Style>
The trouble is that only the first item in the ListBox binds the Data property as expected, the other ones don't bind it at all (hence they appear as blank space, but match the size of the Path). Also when I use the style anywhere else (i.e. outside the ListBox), only the first instance that occurs will bind.
The weird thing is that if I define for example the Fill property in the Style instead of inline, it works just fine and doesn't exibit the same problems as the Path property.
My guess is that is has something to do with Data not being a primitive type, but I haven't found any fixes.
EDIT: Interestingly, when I bind the Data property directly to System.String resource, it works. I would still like to be able to define this property via a Style though.
EDIT 2: I've just came across the same issue in WPF, when setting Path to a Content of a Button via a Style that is used across more buttons. The path shows up in just one buttons, the others are blank.
Path.Fill is a DependencyProperty, while Path.Data isn't. Instead do:
<DataTemplate>
<Grid ...>
...
<ContentPresenter Content="{StaticResource MyPath}"/>
</Grid>
</DataTemplate>
ContentPresenter.Content is a DependencyProperty so this should work:
<Path x:Key="MyPath" Margin="4" Style="{StaticResource ErrorIconPath}"
Stretch="Uniform" Width="26" Height="26" VerticalAlignment="Center"
RenderTransformOrigin="0.5,0.5" Grid.Column="1" Grid.Row="1"
UseLayoutRounding="False" HorizontalAlignment="Center"
Data="F1M874.094,289.369L854.3,254.63C854.028,254.151 853.515,253.856 852.958,253.856 852.403,253.856 851.89,254.151 851.617,254.63L831.824,289.369C831.555,289.84 831.559,290.416 831.835,290.883 832.111,291.348 832.618,291.634 833.165,291.634L872.752,291.634C873.299,291.634 873.805,291.348 874.081,290.883 874.357,290.416 874.361,289.84 874.094,289.369 M855.653,287.189L850.264,287.189 850.264,282.745 855.653,282.745 855.653,287.189z M855.653,279.41L850.264,279.41 850.264,266.077 855.653,266.077 855.653,279.41z"/>
I am guessing that Geometry cannot be shared. Have you tried setting the x:Shared= "false" to:
<Style x:Key="ErrorIconPath" TargetType="Path">
I've experienced the same behavior in Silverlight and asked a similar question here on StackOverflow.com
( https://stackoverflow.com/q/13426198/1796930), but as I'm writing this, it's been 1 month and I've yet to get even a single answer.
However, as you mentioned in your first edit, I too was able to perform a workaround by creating a resource with my geometry data as a string and then binding the Data property of the Path objects to the string resource resource.
I also had to create two instances of the Path objects that were identical other than each one using a different resource (i.e. two different icons) and then binding the visibility of each to a property in my ViewModel to display the appropriate one.
I am very sure that you did not forgot the stroke here in Path style
<Setter Property="Stroke" Value="Red"/>
I have tested you code on my machine , it worked fine if above line added in style
My first tought was your Path would be broken or not valid. But then I saw you are using the Syncfusion Metro Studio. I tried it with exactly the same code you have and it worked very well. In a Data Template of 5 Items or as a single Path Item.
Have you tried to set the Fill statically to Red or something?
Also maybe try this for the Style definition
<Style x:Key="ErrorIconPath" TargetType="{x:Type Path}">
Third suggestion would be to move the style definition from the App to your Page or even to your Control itself.
To be sure there will be no default styles applied, try
OverridesDefaultStyle="True"
Hope this helps :)

How to reuse icons (xaml-paths) in a large project?

I am part of the development of a larger-scale Silverlight 4 project, where we will have a set of symbols that should be used across different parts of the GUI (see the example below).
These icons are made from multiple paths directly in Blend, and will be used, either singly or as different visual states in usercontrols (with the same icon used in more than one context). In order to facilitate changing the design of a single icon, and having it propagate throughout the application, what is the best way to store these?
I have tried creating styles from them (right click -> edit style..), but this only allows me to create an empty style, without any path data. manually putting the xaml code for the grid containing the paths into a dictionary hasn't helped either, what am I missing?
How do I save the path and style (colour, stroke, fill, etc) information in an easy way, preferably in a resource dictionary, so I can easily reuse them in usercontrols and elsewhere, while maintaining the easy updating?
Example of the icons I'm trying to reuse:
<Style x:Key="MyIcon" TargetType="ContentControl">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Path Stretch="Fill" Fill="Red" Data="F1 M 24,13C 27.1521,13 29.9945,14.3258 32,16.4501L 32,11L 35,14L 35,22L 27,22L 24,19L 29.5903,19C 28.217,17.4656 26.2212,16.5 24,16.5C 20.1969,16.5 17.055,19.3306 16.5661,23L 13.0448,23C 13.5501,17.3935 18.262,13 24,13 Z M 24,31.5C 27.8031,31.5 30.945,28.6694 31.4339,25L 34.9552,25C 34.4499,30.6065 29.738,35 24,35C 20.8479,35 18.0055,33.6742 16,31.5499L 16,37L 13,34L 13,26L 21,26L 24,29L 18.4097,29C 19.783,30.5344 21.7787,31.5 24,31.5 Z "/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
And then use style with contentcontrol type (or derivates):
<ContentControl Style="{StaticResource MyIcon}" Width="20" Height="20" Grid.Row="0"/>
All styles can be inside some resource dictionary:
This is quite informative article:
http://blogs.infosupport.com/tips-for-effective-usage-of-resource-dictionaries-in-silverlight-and-wpf/

Making an image control invert its colors depending on theme

I'm trying to work out how to have an Image control in my Windows Phone application invert its colors based on the global background setting (either "Dark" or "Light") chosen by the user in Settings->Themes->Background.
There is no built-in way to invert image colors within the framework.
Instead, because of the overhead of doing this on the phone, you should create both versions of the image at design/build time and then choose which version to display from your code by detecting Theme Visibility and Opacity.
I must add that what i did in the end was a continuation of what Matt wrote.
create two different images that have different versions of the image (dark and light) and place them in the exact same position
set their visibility based on the theme resource
the code looks like this:
<Image Height="30" HorizontalAlignment="Center" Margin="0,0,0,220" Name="imgDark" Stretch="Fill" Visibility="{StaticResource PhoneLightThemeVisibility}" VerticalAlignment="Center" Width="30" Source="/MyApplication;component/imageDarkTheme.png" />
<Image Height="30" HorizontalAlignment="Center" Margin="0,0,0,220" Name="imgLoading" Stretch="Fill" Visibility="{StaticResource PhoneDarkThemeVisibility}" VerticalAlignment="Center" Width="30" Source="/MyApplication;component/imageLightTheme.png" />
This Question is 1.5 years old now. But here is the easiest way to do what you want. The example given there is very simple like
<Button>
<Image Stretch="None" Source="{Binding Converter={StaticResource ThemedImageConverter}, ConverterParameter={StaticResource PhoneBackgroundColor} }"
DataContext="/WP7SampleProject4;component/Images/{0}/appbar.feature.camera.rest.png" />
</Button>

Resources