From what I know, Expression Blend is the only method to look at a default style for some WPF control. But I find it very unelegant to create a new project, find a directory to save it to, add the element to my empty window designer and find some hidden "edit template copy" command or so.
And it totally fails when I want to get a DataGridCell style because I can't add it to the window.
How is this really correctly and efficiently done?
If Expression Blend is not involved in the better solution, please go ahead and let me know. Something directly available from VS 2010 would be best.
It's not the only method, but it is generally the easiest route since Blend by far makes for a better designing experience.
For you issue, I forget the names of the Default resource dictionaries for WPF. Like with SL you'd just go look into the CoreStyles, SDKStyles, ToolkitStyles (.xaml) files for the full templates. I'm pretty sure the same exists in WPF wherein you could likely locate them with a quick solution search for TargetType="{blah}" or wherever they're referenced to be loaded.
Otherwise you can continue with the right-click "Edit Template" method, and for a child part of a template (like a DataGridCell style) you would instead choose "Edit Additional Templates" and find that part of the template there the same way.
However like I said you can go straight to the templates themselves, just have to find the default dictionaries first. Hope this helps.
Related
In wpf, is it somehow possible to lookup the definition of the default style of a control?
In this question I saw an example thereof, see: "just for a reference, here's the default MenuItem's style". Where did he/she find it?
using Expressin Blend is the best answer for this.
in Expression blend select the control on which you whould like to see the tamplate then right click and select the template then Edit a copy. this will create a copy os used tempalte will explorer the orignal template if you are not using any theme.
On the other hand you can look for http://wpfinspector.codeplex.com/
In Expression Blend 4 the Simple Styles use the following XML namespace:
http://schemas.microsoft.com/expression/interactivedesigner/2006
It frequently uses an attribute from this namespace called IsControlPart which is a boolean. I've googled extensively and can't find any actual documentation on this attribute.
I think I figured it out.
When WPF creates the default templates for its controls, it names some of the elements with the prefix "PART". For example, with a Slider control, it has two parts, PART_Track and PART_SelectionRange. This in itself has nothing to do with Expression Blend.
These parts necessary for the basic functionality of the control. Most simple controls, like a Button, do not have any parts, so they can be fully customized without having any restrictions.
More complex controls rely on parts being present in order for the code-behind to work properly. It doesn't care what the control looks like, or where they are in the visual tree, so long as they exist and are of the right type.
In Expression Blend, there is a "Parts" window which is by default a tab alongside the "Project" and "Assets" tabs. When you are editing a template for a Control, if there are any parts defined for that control it lists them in this Parts window. It shows a check mark if that part exists in the current template, and if not you can double click on it and Blend will create the element for you.
I am still not sure exactly how the d:IsControlPart attribute works. I tried making my own custom Control and creating a element with the IsControlPart tag, and then creating a template for that control to see if it would list the part. It didn't. So this is still not 100% answered.
I am very new to Expression Blend but can't find any solution with google. I would like to style a Menu and it's items. But how can I see the actual look of the PART_Popup? The IsOpen Property is bound to something like {Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}. It seems I am only looking at something complete invisible :). There is also a SystemDropShadowChrome but I actually can't see this thing. The eyes next to all the items are active. And even if I change some background colors all that I see is just a black transparent rectangle.
Is this a toolkit control (dropdownmenu) or a telerik (radmenu) or something? If you've already broken out the template (eg; Right click->Edit Template->Edit Current/Copy) Then there's a couple things you want to try to find it since sometimes they can be oddly embedded.
Go to the root level of the control, try Right Click->Edit Additional Templates->...
If that' doesn't provide your part_ look in your broken out template resource you've created and inspect your object tree. You're looking for embedded controls appearing as objects. Right click the embedded control in your object tree and edit its template (Current or Copy)
You'll potentially sometimes have to drill down multiple layers within a template to expose the objects you wish you to edit. If you specify which control you're working with I'm sure we can tell you exactly how to get to where you need more efficiently. Cheers!
Try exploring the States tab. Most likely some of the parts are only visible in certain states.
I am new to Silverlight, but I couldn't find anything about this when I googled it.
I have a button that I am trying to set the style programatically. I have the style defined in a XAML file and I want to pull the style into C# so I can dynamically create a button and assign it this style. So far, this is what I am trying:
button.Style = (Style)Resources["CloseButtonStyle"];
However, it just makes the button have no style. Is there an easy way to do this? I feel like this should be obvious, but I can't get it to work.
You are assuming that your Resources property on the current object is the one that contains the defined style. However, I assume, given the symptoms of your issue, that CloseButtonStyle is actually defined further up the control hierarchy.
Instead, you need to traverse your control hierarchy until you find the resource (or if you know the object that defines it, just refer directly to that object). Unfortunately, Silverlight doesn't include FindResource call like WPF, but it's not too difficult to implement your own.
I can call button1.Style = (Style)Resources["NonExistentKey"]; and it makes my button have no style at all as well, point being that the resource is probably not being found, you won't get an exception.
You directly access the Resources property, but is the style really in the immediate resource dictionary of your Window/UserControl/whatever-you-have?
I wanted to know which one amongst Style and UserControl would be better to use in WPF?
For example:
I have created an image button in two different ways.
One uses Style and ContentTemplate property is set.
It uses one other class with dependency properties.
The other way is I have created a UserControl which has a button and its content property is set.
The file UserControl.xaml.cs also contains the dependency properties.
For Code details see the answers of this question:
Custom button template in WPF
Which one would be better to use? In which scenario should one go for Style or UserControl or any CustomControl?
Styles are limited to setting default properties on XAML elements. For example, when I set the BorderBrush , I can specify the brush but not the width of the border. For complete freedom of a control’s appearance, use templates. To do this, create a style and specify the Template property.
Styles and templates still only allow you to change the appearance of a control. To add behavior and other features, you’ll need to create a custom control.
For example,
To create a button like a play button use styles and templates, but to create a a play button which will change its appearance after pausing it use UserControl.
For this type of thing I would go with Style, even though I'm not really adept with graphical tools. I tend to produce a basic, boring style that I can get started with and then prettify it once the application functionality has been verified.
The nicest thing about WPF is being able to distance much of the graphical look, feel and behaviour away from the code.
This allows you to change the style of your application without revisiting the code and indeed means that you can change styles on the fly at runtime.
There is an awkward line to tread with regards to how much behaviour is placed within the XAML and how much is placed within the code. A rough guide would be to decide on what behaviour must always be present within the UI and place that in the code, everything else place within the XAML.
Think of the code as being an abstract class with defined interfaces and the XAML Styles as being classes based on that class and you'll get an idea of what I mean.
Conversely, I know that people who are far more adept at the GUI work prefer to put more functionality in the XAML and others who prefer the code side, because they find the GUI work slow or difficult.
When thought of that way you'll see that there's never really a right or wrong answer, just better solutions that suit your skills.