Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7752769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:53:00+00:00 2026-06-01T11:53:00+00:00

I have a MVVM application that contains multiple views with some complex IsReadOnly rules

  • 0

I have a MVVM application that contains multiple views with some complex IsReadOnly rules based on user permissions, view/edit mode and object state.

I would like to set IsReadOnly and/or IsEnabled properties for entire groups of controls in the same container (GroupBox / StackPanel / Grid / UserControl / etc.). The value of this property will be defined in ViewModel.

I’ve got 3-6 different SomeGroupIsReadOnly properties per UserControl (with a large number of input controls like TextBox, RadioButtons, ComboBoxes and some DataGrids) and I’m looking for a generic, MVVM-friendly solution, that will allow me to reuse Bindings on per-container basis, instead of specifying them for each individual control separately.

How can I set IsReadOnly / IsEnabled on all controls inside container like Panel or GroupBox using XAML?

It doesn’t seem that WPF supports this out of the box…

EDIT

I forgot to mention that setting IsEnabled for a container disables an important feature of TextBoxes – being able to copy their contents. I need them to be in IsReadOnly=true state. If there was a workarond for that, then my problem would be solved.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:53:01+00:00Added an answer on June 1, 2026 at 11:53 am

    Something that’s worked well for us is to define a view model that represents the permission structure of your application (YourPermissionsViewModel in my example below).

    Then you could create a custom panel control that extends any panel of your choice (StackPanel in this example). That way you can add in the IsReadOnly property bindings and persist them to the panel’s children.

    Here’s what the panel in XAML could look like:

    <local:PanelExtension IsEnabled="{Binding YourPermissionsViewModel.IsEnabled}" 
                          IsReadOnly="{Binding YourPermissionsViewModel.IsReadOnly}">
        <TextBox Text="eeny" Width="100" />
        <TextBox Text="meeny" Width="100"/>
        <TextBox Text="miny" Width="100"/>
        <TextBox Text="mo" Width="100" />
        <Label Content="coolio" Width="100" />
    </local:PanelExtension>
    

    And here is the StackPanel extension control containing all of StackPanel’s features as well as attaching a custom IsReadOnly dependency property that updates the corresponding property value on any child controls who possess that property:

    public class PanelExtension : StackPanel
    {
        public bool IsReadOnly
        {
            get { return (bool)GetValue(IsReadOnlyProperty); }
            set { SetValue(IsReadOnlyProperty, value); }
        }
        public static readonly DependencyProperty IsReadOnlyProperty =
            DependencyProperty.Register("IsReadOnly", typeof(bool), typeof(PanelExtension),
            new PropertyMetadata(new PropertyChangedCallback(OnIsReadOnlyChanged)));
    
        private static void OnIsReadOnlyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((PanelExtension)d).OnIsReadOnlyChanged(e);
        }
    
        protected virtual void OnIsReadOnlyChanged(DependencyPropertyChangedEventArgs e)
        {
            this.SetIsEnabledOfChildren();
        }
    
        public PanelExtension()
        {
            this.Loaded += new RoutedEventHandler(PanelExtension_Loaded);
        }
    
        void PanelExtension_Loaded(object sender, RoutedEventArgs e)
        {
            this.SetIsEnabledOfChildren();
        }
    
        private void SetIsEnabledOfChildren()
        {
            foreach (UIElement child in this.Children)
            {
                var readOnlyProperty = child.GetType().GetProperties().Where(prop => prop.Name.Equals("IsReadOnly")).FirstOrDefault();
                readOnlyProperty.SetValue(child, this.IsReadOnly, null);
            }
        }
    }
    

    With this approach you could add as many customized properties you need, it really lends you a great deal of flexibility and enables you to account for a multitude of scenarios you might encounter when you have to set your complex permissions on various elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a silverlight mvvm application that loads main view with 2 user controls
In a MVVM WPF application, I have a master-detail View that is used to
General context : MVVM application. I have a View called JobView. Its DataContext is
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
in my MVVM application (in wpf) i have two view and I want to
I have an MVVM Silverlight 4 application that holds a list of modules (a
I have an application that uses MVVM. I have several items on the main
I have a WPF application that mostly follows MVVM, which I am trying to
I have an MVVM setup with a mainwindow that contains a ContentControl. I set
I am creating a page-based WPF application using MVVM. I have created a custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.