Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I develops a project in vb.net using wpf. in this project i only use the USER CONTROL but when i run my project the design is too bing, even i already assign a small value to the designheight and designwidth, the display is still too big.

can someone help me with this matters. thank you very much experts!!
i am still new in this wpf.

Thank you very much!

The Xaml Code look like this:

<usercontrol x:class="UserRoleTreeViewUC" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:userRoleManagement="clr-namespace:UserRoleManagement"
d:DataContext="{d:DesignInstance Type=userRoleManagement:UserRoleTreeViewVM,
IsDesignTimeCreatable=False}"
d:DesignHeight="259.271"
d:DesignWidth="514.135"
mc:Ignorable="d">
<usercontrol.resources>

<datatemplate x:key="TreeContent">
<textblock text="{Binding Title}">


<hierarchicaldatatemplate x:key="SubTree">
ItemTemplate="{StaticResource TreeContent}"
ItemsSource="{Binding SubModules}">
<textblock fontweight="Medium" text="{Binding Title}">


<Style x:Key="ExpanderStyle" TargetType="{x:Type ToggleButton}">
<setter property="IsEnabled" value="True">
<setter property="IsTabStop" value="False">
<setter property="Cursor" value="Hand">
<setter property="Template">
<setter.value>
<controltemplate targettype="{x:Type ToggleButton}">
<grid>
<grid x:name="ButtonOver">
Width="16"
Height="16"
Margin="0,4,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Opacity="0">
<rectangle width="Auto">
Height="Auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
RadiusX="3"
RadiusY="3"
Stroke="DeepPink">
<rectangle.fill>
<lineargradientbrush startpoint="0.5,0" endpoint="0.5,1"> <gradientstop offset="0" color="#FF00BCFF">
<gradientstop offset="1" color="#FF027BA6">
<gradientstop offset="0.5" color="#FF00A5E0">
<gradientstop offset="0.501" color="#FF005674">


<rectangle x:name="CollapsedVisualOver">
Width="2"
Height="8"
Margin="7,4,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Fill="#FFFFFFFF"
RadiusX="0"
RadiusY="0" />
<rectangle width="8">
Height="2"
Margin="4,7,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Fill="#FFFFFFFF"
RadiusX="0"
RadiusY="0" />

<grid x:name="Button">
Width="16"
Height="16"
Margin="0,4,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Top">
<rectangle width="Auto">
Height="Auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Fill="#FF00A2DC"
RadiusX="3"
RadiusY="3"
Stroke="#FF027BA6" />
<rectangle x:name="CollapsedVisual">
Width="2"
Height="8"
Margin="7,4,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Fill="#FFFFFFFF"
RadiusX="0"
RadiusY="0" />
<rectangle width="8">
Height="2"
Margin="4,7,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Fill="#FFFFFFFF"
RadiusX="0"
RadiusY="0" />



<controltemplate.triggers>
<trigger property="IsMouseOver" value="True"> <trigger.enteractions> <beginstoryboard>
<storyboard>
<doubleanimation storyboard.targetname="ButtonOver">
Storyboard.TargetProperty="(UIElement.Opacity)"
To="1" />
<doubleanimation storyboard.targetname="Button">
Storyboard.TargetProperty="(UIElement.Opacity)"
To="0" />


<trigger.exitactions> <beginstoryboard>
<storyboard>
<doubleanimation storyboard.targetname="ButtonOver">
Storyboard.TargetProperty="(UIElement.Opacity)"
To="0" />
<doubleanimation storyboard.targetname="Button">
Storyboard.TargetProperty="(UIElement.Opacity)"
To="1" />


<trigger property="IsChecked" value="True"> <trigger.enteractions> <beginstoryboard>
<storyboard>
<doubleanimation storyboard.targetname="CollapsedVisualOver">
Storyboard.TargetProperty="(UIElement.Opacity)"
To="0" />
<doubleanimation storyboard.targetname="CollapsedVisual">
Storyboard.TargetProperty="(UIElement.Opacity)"
To="0" />


<trigger.exitactions> <beginstoryboard>
<storyboard>
<doubleanimation storyboard.targetname="CollapsedVisualOver">
Storyboard.TargetProperty="(UIElement.Opacity)"
To="1" />
<doubleanimation storyboard.targetname="CollapsedVisual">
Storyboard.TargetProperty="(UIElement.Opacity)"
To="1" />






</Style>

<grid>
<grid.columndefinitions>
<columndefinition width="Auto"> <columndefinition width="*">

<telerik:radtreeview grid.column="0" xmlns:telerik="#unknown">
ExpanderStyle="{StaticResource ExpanderStyle}"
Loaded="RadTreeView_Loaded_1 ">
<telerik:radtreeviewitem dropposition="Inside" header="Role">
<telerik:radtreeview x:name="treeRoles">
DisplayMemberPath="Title"
ItemsSource="{Binding RoleCollection}" />


<telerik:radtreeviewitem dropposition="Inside" header="User">
<telerik:radtreeview x:name="treeUsers">
DisplayMemberPath="Username"
ItemsSource="{Binding UserCollection}" />


<telerik:radtreeviewitem dropposition="Inside" header="Modules">
<telerik:radtreeview x:name="treeModules">
ItemTemplate="{StaticResource SubTree}"
ItemsSource="{Binding ModuleCollection}" />



Posted
Updated 6-Mar-15 16:10pm
v2
Comments
Kenneth Haugland 20-Feb-15 5:35am    
Sounds like a job for a value converter.
JOE Heart Under Blade 21-Feb-15 0:49am    
i don't get it. why the size during runtime didn't follow like the value that we already set in xaml?
Kenneth Haugland 21-Feb-15 4:49am    
Sounds like you need to alter the size you get, and for that you need a ValueConverter.
Subramanyam Shankar 6-Mar-15 6:01am    
Can you post your xaml code?

1 solution

WPF is not designed so primitively (and, ultimately, not so unreliably and inconveniently) to allow you to just set the size of control. All rendered sizes are defined by the general layout of the window.

First of all, everything comes from or to the size of the windows, separately by horizontal and vertical dimension. It's either the sizes of all UI elements inside a window are defined by the total size of the window, explicitly chosen, or the size of the window is defined by the size of content. This is defined by the SizeToContent property: https://msdn.microsoft.com/en-us/library/system.windows.window.sizetocontent(v=vs.110).aspx[^].

And then, the size of each and every control is defined by its content and properties, such as Control.Padding and FrameworkElement.Margin, as well as related factors, such as Grid.ColumnDefinitions and , and other controls' properties. Please see:
https://msdn.microsoft.com/en-us/library/system.windows.controls.control.padding%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.margin%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.controls.grid.columndefinitions(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.controls.grid.rowdefinitions(v=vs.110).aspx[^].

I referenced these properties just for illustration, not pretending for complete explanation. You can get this understanding if you study WPF layout model: https://msdn.microsoft.com/en-us/library/ms745058%28v=vs.110%29.aspx[^].

So, what to do? Rethink your design. You don't need to try to arbitrary change the size of some separate control. Probably WPF layout model is more rational that you thought. It's better to embrace in instead of fighting it.

—SA
 
Share this answer
 
v2
Comments
JOE Heart Under Blade 6-Mar-15 23:52pm    
Sergey Alexandrovich Kryukov... Thank you very much sir.

u know what. every time i ask a question u always help me out to solve my problem here. thank you very much sir. it's solve my problem.
Sergey Alexandrovich Kryukov 6-Mar-15 23:53pm    
My pleasure.
Good luck, call again.
—SA
JOE Heart Under Blade 7-Mar-15 1:20am    
thank you sir. for sure for that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900