locked
how to lock the width or height property of custom WPF control. RRS feed

  • Question

  • How can I restrict the user from changing value of width property or height property of my WPF custom control.
    Monday, February 2, 2009 7:29 AM

Answers

  • You can set the MaxWidth and MinWidth properties of the top element in your control to the desired size.
    • Proposed as answer by snez Monday, February 2, 2009 10:09 PM
    • Marked as answer by Hua Chen Friday, February 6, 2009 10:43 AM
    Monday, February 2, 2009 10:09 PM
  • I believe you'd have to set the MinHeight, MaxHeight to same value.  Same with MinWidth, MaxWidth

    <UserControl x:Class="Forums.NoSizeControl" 
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                 MaxHeight="300" 
                 MinWidth="300" 
                 MinHeight='300' 
                 MaxWidth="300" 
                 Background='Red'

    Walt | http://wpfwonderland.wordpress.com
    • Marked as answer by Hua Chen Friday, February 6, 2009 10:43 AM
    Tuesday, February 3, 2009 12:16 AM

All replies

  • MrSid said:

    How can I restrict the user from changing value of width property or height property of my WPF custom control. At design time.



    Monday, February 2, 2009 7:32 AM
  • You can set the MaxWidth and MinWidth properties of the top element in your control to the desired size.
    • Proposed as answer by snez Monday, February 2, 2009 10:09 PM
    • Marked as answer by Hua Chen Friday, February 6, 2009 10:43 AM
    Monday, February 2, 2009 10:09 PM
  • I believe you'd have to set the MinHeight, MaxHeight to same value.  Same with MinWidth, MaxWidth

    <UserControl x:Class="Forums.NoSizeControl" 
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                 MaxHeight="300" 
                 MinWidth="300" 
                 MinHeight='300' 
                 MaxWidth="300" 
                 Background='Red'

    Walt | http://wpfwonderland.wordpress.com
    • Marked as answer by Hua Chen Friday, February 6, 2009 10:43 AM
    Tuesday, February 3, 2009 12:16 AM