Setting Design Time Size for Custom Control - c#

How do you set the Design Time Width and Height of a custom control?
I have created a custom ItemsControl, i.e. (contents of generic.xaml)
<Style TargetType="{x:Type MyItemsControl}" >
<Setter Property="Height" Value="24" />
<Setter Property="Width" Value="160" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MyItemsControl}" >
<Grid>
...
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
...
</Style>
And it works all nicely and all, however if I drag the control from the ToolBox onto my window the default size of my control is: Height = 100 and Width = 200. How do I set the design time size so that when I drag the control from the Toolbox to window the default size is 24 and 160 respectively?

May b it helps u..........
for that firstly u have to make ur own controls by inheriting it with
original controls and set Hieght,width and whatever you want in your
custom control .........after this when u drag ur own made control
form toolbox to ur form it will set by ur way whatever u wanted.......

This is a setting within Visual Studio itself, and there doesn't seem to be a way to change it, nor is Microsoft planning on changing it.
Source: A user reported this issue to Microsoft online and a Microsoft employee responded and marked the issue as "Won't Fix".

Related

How to change visual behavior of a button in WPF?

I noticed that on Windows 10, the appearance of controls shown by the OS looks much more appealing than the defaults on Winforms/WPF. For example, The selected OS button has a thicker blue border, and a more interactive "feel" to it, while the default WPF button appears as a simple grey box:
OS:
WPF:
Is there a way to somehow change the "theme" of a button in WPF to behave similarly to the most OS-displayed buttons, without having to implement this behaviour manually?
You can get similar button styles using Windows UWP.
In WPF, you can check out the Modern UI(MUI) in MSDN site.
It can produce similar results. I have been working with mui for a couple of months and it really helped me to satisfy my client who wanted to have a Windows 10 like UI experience. I had to create tiles like in start menu also. MUI did a great job for me.
Get the MUI from Github. Modern UI for WPF
Also I had tried devexpress and telerik controls. Have a look at them too.
You can use DevExpress to get themes for your form. Or you can implement your own by adding borders around every button and change its Color/Visibility on MouseDown and MouseUp event handlers
Define a Style within Window.Resources with TargetType="Button" so that it affects all the buttons in that window. For example, although the default WPF button has mouseover colour change and a focus rectangle, it does not move "inwards" on MouseDown, so this example shows how to do this:
<Window.Resources>
<!--A Style that affects all Buttons-->
<Style TargetType="Button">
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property= "RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleX="0.99" ScaleY="0.99"/>
<TranslateTransform X="2" Y="2"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness">
<Setter.Value>
<Thickness Left="2" Right="2" Top="2" Bottom="2"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
Insert this after the Window attributes and before the Grid or other container tag.

Change the control property globally in wpf

I have a back button which is copied almost to all the Controls in my application.
I have set the styles and properties of the button on each individual control (usercontrol)
Now I want to change the text property of the button of all the control (usercontrol).
I don't want to go and change the property of each control.
Please help me setting a global property which sets the property in one place.
Since the style is common to all pages. Create the style without a key/name, just the target type would do.
<Style TargetType="{x:Type Button}">
Then do either of the following -
Add it to the App.XAML for visibility throughout the app
Better approach would be to define a resource dictionary file and import it, wherever you need it.
<Style TargetType="{x:Type Button}">
<Setter Property="Text" Value="{Binding text}" />
<Setter Property="...." Value="{Binding ....}"/>
</Style>
Add this to App.xaml file as you want it to be global style for all your user controls.

Losing adorner layer after ListView had no items

I'm using attached behavior to add sorting to GridView columns from here: http://www.thomaslevesque.com/2009/08/04/wpf-automatically-sort-a-gridview-continued/
It is working fine, if I don't use following code:
<ListView.Style>
<Style TargetType="ListView">
<Style.Triggers>
<Trigger Property="HasItems" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.Style>
Problem appears, using this sequence of steps:
1) fill list with items, click on header to sort it, sorting glyph appears
2) clear list
3) fill list again, sorting glyph is not visible
I subscribed to SizeChanged event in attached behavior, to catch the moment, when list goes from empty to full, to redraw sorting glyph, but GetAdornerLayer(columnHeader) returns null, I guess it is not rendered yet and does not have adorner layer yet.
Question is, how to catch right moment to redraw missing glyph (or to get adorner layer, when it exists)?
I've sorted it out, problem was, that GridViewSort had property SortedColumnHeaderProperty which was holding reference to sorted column header.
So when list would be cleared and would be filled again, column headers were recreated and that reference was not used in rendering anymore.

How to work with control inheritance

I use Telerik as a WPF library. We can apply a theme on Telerik controls using application Theme (i.e. theme manager). For Microsoft controls we can set a property to make the theme apply.
The problem is : I don't want to write this line :
<Style TargetType="{x:Type CheckBox}">
<Setter Property="telerik:StyleManager.Theme" Value="{Binding Source={StaticResource Settings}, Path=Default.Theme}" />
</Style>
for every type: CheckBox, TextBlock, TextBox etc.. for maintenance purpose.
If I target <Style TargetType="{x:Type Control}"> inheritance doesn't work well.
Base class of CheckBox is Control but when I set property on every control it doesn't set property on every child of control too. Any idea how i can do this?

Border thickness for Telerik's RadMaskedInputBaseStyle in Silverlight when content is invalid

How do I increase border thickness for RadMaskedInputBaseStyle (or RadMaskedDateTimeInput by Telerik) in Silverlight only WHEN it is red indicating that the input contains invalid entry.
My XAML looks like this
<Style TargetType="telerik:RadMaskedDateTimeInput">
<Setter Property="IsValidationHintVisible" Value="True" />
</Style>
In general, if a style isn't available as a property of the control, then you will find it buried somewhere in the control template (as Chris W alludes to in the comments).
To see the source for a proprietary control template like one of Telerik's, open up Expression Blend and click "Edit Template" on an instance of the control. If you do that for the RadMaskedDateTimeInput, you will notice the validation-related visual states making reference to an element named "ErrorElement". Scroll down, in the control template source, and you will see that is declared as follows:
<Telerik_Windows_Controls_Chromes:ValidationTooltip x:Name="ErrorElement" Opacity="0" TooltipPlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" telerik:StyleManager.Theme="{StaticResource Theme6}" TooltipContent="{TemplateBinding DisplayErrorMessage}" TooltipContentTemplate="{TemplateBinding ErrorMessageTemplate}" />
Ok, so it's another control called ValidationTooltip. This control does have a BorderThickness property exposed, so if you like, you should be able to simply set that property in a targeted global style. Something like this should go in your resource dictionary:
<Style xmlns:Telerik_Windows_Controls_Chromes="clr-namespace:Telerik.Windows.Controls.Chromes;assembly=Telerik.Windows.Controls"
TargetType="Telerik_Windows_Controls_Chromes:ValidationTooltip">
<Setter Property="BorderThickness" Value="2" />
</Style>

Categories