I have a windows 8.1 XAML application. I want to allow users to customize the theme of the app themselves - for example, I want to give them a color picker where they can set various colors in the app, which would set various resources used across my app.
The issue though, is I cant find out how to dynamically change the value of a resource. I know in 8.1 they added the concept of a theme resource, which allows me to change from light to dark theme at runtime and what not. But my issue is that I'd like to say 'the backgroundColor resource is now going to be orange, and all items using this resource will reflect this change'
I believe the DynamicResource XAML element is what I needed, but that seems to be from WPF and not supported in Win8. Does anyone have suggestions?
In short - I want to be able to easily provide dynamic resource brushes.
Unfortunately I do not believe that there is a nice built in way of doing this so any solution is likely to be a little bit hacky or unpleasant.
This question has some good answers of which this answer is my personal favourite. The downside is that it results in the ViewModel taking on a bit more responsibility for the view than is ideal.
You can actually dynamically access the attributes of the elements you wish to change upon the user's choice.
Related
With the latest Update from Groove Music Microsoft introduced a new styling theme called "Neon". As far as I know MS is planning to Update at least some more of their UWP-Apps, so that they also make use of this new Design Style, which has semi-transparent navigation bars.
Here is an example of how it looks like:
So I was wondering "Is it possible to create an Application that looks similar?"
As far as I can tell, MS should be using some mix of transparency and Gaussian-Blur-Effects. That's not really the problem, the interesting part starts by making the Window transparent itself, while keeping the Window-Control-Buttons.
When I search for tutorials and How-To's to make an WPF-Application transparent they all set two properties on the window-object.
AllowTranparency="True"
and
WindowStyle="None"
With the latter one removing the Title Bar.
So my question is, is there a "new" way of adding opacity to your window, without setting the WindowStyle to None?
And if yes, how?
Otherwise, is it more likely that MS used DWM to give the illusion of transparency, while actually projecting the overlapped part of the window behind the navigation?
I hope that my question is not to widespread about the topic and clearly asked. If not, I'm going to rewrite it and try to clear things up.
Thanks in advance for any answers and hints.
How can i manage Autorotation Windows 8 Apps.
I have gone through the "Rotation" Sample from MSDN but it is hell lot confusing, what I need to do is , I need to have completely different view when in Portrait and a diiferent one in Landscape.
I have designed my view for Landscape when I need to make changes for Portrait View. I need a way to dynamically switch between to views of re-shuffle the views.
By far the easiest way to deal with this is to inherit your page from LayoutAwarePage instead of Page and leverage the Visual State Manager inside of Expression Blend to do all of the work for you.
I have a full article with lots of pictures and a downloadable sample application here:
http://jaredbienz.wordpress.com/2012/04/22/wp-to-w8-view-states-using-visual-state-manager/
You're definitely going to want to use a FlipView control here. I don't know if you're using JavaScript/HTML5 or C#/XAML, but it is available in either case.
There's a great sample on MSDN to show you how to do it, but without more context on your issue, I don't know how much more I can assist.
http://code.msdn.microsoft.com/windowsapps/FlipView-control-sample-18e434b4
You can handle orientation changes in two basic ways...
1) The brute force approach. Wire into the orientationchanged event...
Windows.Graphics.Display.DisplayProperties.OrientationChanged += DisplayProperties_OrientationChanged;
In the event handle, check the orientation and navigate to a page that has been specifically layout out for that orientation...
if (Windows.Graphics.Display.DisplayProperties.CurrentOrientation == DisplayOrientations.Portrait)
this.Frame.Navigate(typeof(PortraitPage));
Pros... easy to design pages optimized for given orientations
Cons... need to handle navigation and state data between pages
2) Create a single page that changes its layout using visual states. You would still wire into the orientationchanged event, but make calls to VisualStateManager.GoToState(this,"Portrait",true).or something similar depending on how you name your visual states.
Pros... change layout without navigation and you can add cool animations easily
Cons... more complex layout could be harder if you are not comfortable with advanced xaml layouts and viewStates
If you look at the sample templates (besides blank) they include a LayoutAwarePage that handles the viewstate transitions for you, simplifying things a bit.
I want to use same xaml files for silverlight and wpf version of applications.
Only difference that i need is in styling. I have used styles in xaml. But for silverlight i dont want to use any styling in my xaml files, as styling is defined a application level in the form of themes.
Is there any other way to use same xaml file for silvelight and wpf versions? Otherwise I am forced to maintain separate xaml files.
you can reuse quite a bit of xaml for both, I have projects where I'm linking all the same files, xaml and code behind and it works decently.
A couple of things to be weary of is certain things don't always match up well, for example wpf has a template selector for a itemscontrol and silverlight doesn't.
Using SizeToContent tends to produce different behaviours in the two, I recommend avoiding it, I don't think it buys you anything.
I recommend having a seperate 'base' resource where you can keep your difference in the two files. things like event triggers for example aren't nearly as filled out in silverlight. you would have a base class for each version and they would abstract their differences, you could then mark the keys the same and use them as a static resource in your linked files.
Another big gotcha is you want to watch out for the order events happen for uielements, loaded,layout and apply template events get applied in different orders so if you were to make a templated control you have to be careful there, its not a deal breaker you can work around it, just be aware.
other things to be aware of
-silverlight commands take a little more effort, you have to implement ICommand, this isn't always the case in wpf, I use my implementation to help with sharing the code though.
-wpf is the superset, it has a lot of functions that silverlight doesn't have, Usually they are convienient ways of doing things, you just want to avoid those. Good Examples would be Preview events, not there for silverlight but you can usually find an event to match the behaviour.
Ive been working on a C# project for a while now and I fell it needs change its look.
I have found a UI kit that I really like, which can be seen below:
http://medialoot.com/item/transparent-ui-kit/
Does anyone know how to do this?
Thanks
EDIT: Im using WinForms
EDIT2: Maybe I should convert over to WPF? Is this doable?
You can subclass most common controls and draw their appearance yourself. However, unless for novelty applications I doubt your users will thank you for doing so.
Your example is a library of controls. For you to have an appearance such as that you'll have to create or acquire a similar library of controls and replace all your controls in your project to get that appearance.
If you want to update colors (background, foreground, etc.) and such you can make a class that recurses through controls and sets the settings using reflection and a switch statement to process each control. Then just run this on each form before you show it. One word of caution about this, some controls don't respect your changes and get overridden with themes from the OS (datetimerpicker being the biggest culprit). You'll also need to consider whether your users will appreciate the extra work put in for color/appearance changes.
If you don't have very good design skill and have a good know how about creating such templates, its better to buy them.
And C# is just a language. You're looking to create templates and skins for either for ASP.NET website/application or for windows forms.
Have a look at DevExpress Skins
If you can afford it.
I am working on windows phone apps. When I was reading about improving the performance of an app, I came across this msdn blog which is concentrated on silver light performance for ListBox in windows phone. It suggests that we should not use User Controls in data template. (I have marked the text in the link in two areas. which i felt doubtful)
Now my question is can I create a list of user control objects and add to a ItemsControl say ListBox which is in the view.? Will the control's XAML be considered as a Resource and parse it every time ? (like it is told in the blog). How can I test that? I asked in the same blog a week ago but the question did not get published there.
I've used ListBox some times and in fact, its performance is poor. However, I use to create DataTemplateItem instead of UserControls since I have not needed UserControl.
About your questions: You can create a list of UserControls and add them to ListBox, however consider using DataTemplates instead. I guess that control's XAML is parsed every time (but not sure). To test it, just check this link.
cheers,