I have a RadGridView and for one column/Cell of Grid, I want to change it's default "Part_CellBorder" style. I tried many things but I am not getting the proper way to do that.
Can anyone suggest what would be the proper way to dynamically change the style of Part_CellBorder (BorderThickness). Because I don't want to create separate style for this.
I'm afraid you can't modify the PART_CellBorder element without creating a complete custom ControlTemplate for the cell, i.e. you will have copy the entire default ControlTemplate and then edit it as per your requirements.
The other option would be to try to programmatically get a reference to the PART_CellBorder element at runtime and then modify it by setting any of its properties. But there is no way to override only a part of a ControlTemplate:
WPF: Is there a way to override part of a ControlTemplate without redefining the whole style?
Related
I have often bemoaned the fact that the WPF ToggleButton does not have properties for AlternateContent and AlternateContentForeground. I'm curious if there's any advantage to creating a DependencyObject with attached properties, or deriving a custom control from ToggleButton?
My assumption is that attached properties are advantageous if they are useable on more than one control. So in my case I'm leaning towards a derived control since those properties are unique to the togglebutton.
AttachedProperties are useful in a couple scenarios:
You want to use them as attached behaviors on things that interact with another Control, like Grid.Row
You want to add properties to a control but you don't want to force clients that get that behavior to be derived from your specific type. E.g. if you had a behavior that you wanted on Buttons rather than ToggleButton, then you may want to go with that approach so you could get that new property on ToggleButton and RadioButton, rather than forcing someone to derive from MyCoolButton.
For what you're describing just subclassing ToggleButton seems to make sense.
Actually, this kind of styling should be done with a trigger, or using the VisualStateManager.
I've got a ListView, whose View is switched dynamically in runtime between an Icon mode and a Grid mode (the latter implemented with a GridView).
The problem is, as I described here, that when I add ListView.GroupStyle in my ListView definition, the Icon mode gets screwed. Hence, I'd like to reset/disable GroupStyle for that mode.
So, my question: is there a way to apply/reset the GroupStyle dynamically (via a Trigger?) when I switch the ListView into the Grid mode?
I tried to do that (e.g. <Setter Property="ListView.GroupStyle" Value="{x:Null}"/>) for the Icon View, but this doesn't compile because "The Property Setter 'GroupStyle' cannot be set because it does not have an accessible set accessor."
Any suggestions will be cordially welcome :-)
There could be two ways to do this...
Instead of setting the GroupStyle to x:Null keep the existing set GroupStyle as it is, but reset its inner template using DataTriggers that use TemplateBinding.
Use bottom up approach, remove your GroupDescriptions from your CollectionView based on the mode.
Assume a custom control in Silverlight that has three TextBlock elements named Left, Middle and Right. I want to place the control inside of a grid that has three columns, and I would like the position of those elements to be the same as if I had defined them inline using Grid.Column="x" syntax, with the Grid.Row attached property being set on the custom control itself.
Or if I am completely off-base, what is the best way to achieve a similar result.
I think its likely that you are way "off-base". The purpose of a custom control is to present data in a unique way. If you want to hand out the the layout to an external grid then I would suggest that you don't have call for a custom control.
It seems more likely that you would want a class that has three properties to which you are simply binding three TextBlocks. Without further particulars its hard to give better advice.
To answer your actual question, you can't. You would need to add individual elements directly to the Children collection of the Grid in order for the grid to take charge of their layout. This means that these elements cannot appear as child visual elements inside your custom control.
My first thought was that you are off-base :) but you must have a good reason for seeking that solution.
In your CustomControl you override OnApplyTemplate. In this method you can find the three TextBlocks and set the Grid.Column value using SetValue.
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
/// Find TextBlock named "Left"
var left = GetTemplateChild("Left") as TextBlock;
left.SetValue(Grid.ColumnProperty, 0);
...
}
I am creating a custom control derived from the one of the Standard WPF controls. The control has several constituent parts,and I am only modifying one of those parts.
Here's my question: If I am modifying only one part of a control, do I have to declare the control as lookless and reproduce the entire control template for the modified control in Generic.xaml, or can I omit the lookless declaration (found in the static constructor provided by Visual Studio) and simply modify the control template for the part I am extending?
I have tried the latter approach, and my control template is being ignored. I would like to get confirmation before I reproduce the entire control template, since what I am extending is the WPF Calendar. Thanks for your help.
It sounds like your best bet is to paste the entire template and modify the parts you need, although you didn't say exactly what you want to do or post any code.
Obviously if what you want to change about the calendar has a property you can modify in xaml, then that is easier. The opposite extreme would be to create a custom control (subclass).
I wanted to change the color or the ComboBox arrow the other day and the easiest way to do that was to past the entire template into a style and apply as needed, after changing one single part of the template (the arrow color, of course). There is no exposed DP to change for this and I didn't need anything more complicated than that.
HTH,
Berryl
The declaration that's generated for you by default is simply allowing for a default implicit Style to be defined for your control instead of just taking on the default Style of the base type.
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl), new FrameworkPropertyMetadata(typeof(MyControl)));
What makes a control lookless isn't any specific declaration but rather it's definition in a code file which will then have some ControlTemplate applied to it at runtime. The alternative is the UserControl style of declaring a XAML+code-behind class which compiles into a single class with both UI and logic.
A simple example: Button is not the thing you see on the screen and click on; Button is a control that can take a single piece of Content and translate a user click into a Click event or Command call. What you see on the screen is just a visual template on top of Button's inherent behavior and state.
Hey all, I've noticed that if I have a style setup for a treeview, and a different one setup for the treeviewitem, it gets overridden once I put the item in the tree. Does anyone have suggestions for how to control the style of each treeviewitem individually while mantaining a default style that is applied to the whole treeview? Basically I want to make the text of my treeviewitem red depending on a data field in the item. Otherwise I want it to be black. Thanks
DataTemplateSelector is not in Silverlight. Try below link
http://blog.timmykokke.com/archive/2009/09/28/datatemplateselector-in-silverlight.aspx
Thanks, turns out it was TreeViewItem.Style CAN be set to an ItemContainerStyle if you use the objects as references.