You must Sign In to post a response.
  • Category: WPF

    How to resize hight width of the User control at loading time.


    Are you looking for a way to resize hight width of the User control at loading time in wpf ? then read this thread to know more about it



    Hi,
    I have a user control. Below the XMAL Code

    <vw:ViewBase x:Class="ToDoMainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:igDP="http://infragistics.com/DataPresenter"
    xmlns:infraEditor="http://infragistics.com/Editors"
    xmlns:igWindows="http://infragistics.com/Windows"
    xmlns:vm="clr-namespace:WPF.ViewModel;assembly=ViewModel"
    xmlns:acb="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior"
    xmlns:utils="clr-namespace:CommonUtilities;assembly=CommonUtilities"
    xmlns:vw="clr-namespace:WPF"
    Cursor="{Binding CurrentCursor}" Loaded="UserControl_Loaded"
    acb:CommandBehavior.Command="{Binding ToDoViewScreenGotFocus}"
    acb:CommandBehavior.Event="GotFocus"
    KeyDown="ToDoWindowKeyDown"
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    FocusManager.FocusedElement="{Binding todoDataGrid}"
    MinHeight="620"
    MinWidth="808">
    </vw:ViewBase>

    XMAL.cs Code


    namespace WPF
    {
    public partial class ToDoMainView : ViewBase
    {
    public ToDoMainViewSE()
    {
    InitializeComponent();
    }
    }
    }

    Viewbase is inherited from a User control.

    Suppose User clicks on a button control and this user control is displayed.
    I need to set the user coontrol location and hight width at run time. Currently the MINheight and width is set in XMAL but my requirenment i need to resize at run time and loaction also set accordingly.

    Many Thanks In Advance Please help.
  • #755993
    To set dynamic height and width to user control, follow the below steps
    1. You need to make sure your usercontrol hasn't set it's width in the usercontrol's xaml file
    2. Just delete the Width="..." from it.
    following link will help you lot
    http://stackoverflow.com/questions/462390/how-to-stretch-in-width-a-wpf-user-control-to-its-window

    Remove the Height and Width of the UserControl and also the Grid.
    Set the Margin or Size Property for UserControl where you call it.

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments