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

  • Home
  • SEARCH
  • 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 7848169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:06:22+00:00 2026-06-02T18:06:22+00:00

I am working on a custom wpf control which is derived from a ListBox

  • 0

I am working on a custom wpf control which is derived from a ListBox and am trying to apply some formatting to a custom property.
When a particular custom property is false, I want to apply some formatting to the ListBox.
I am using the following code to attempt to apply the styling –

var t = new Trigger();                

var BackgroundSetter = new Setter {Property = BackgroundProperty, Value = null};
var BrushSetter = new Setter { Property = BorderBrushProperty, Value = null };

t.Setters.Add(BackgroundSetter);
t.Setters.Add(BrushSetter);

var s = new Style(typeof(ListBox));
s.Triggers.Add(t);

editor.ItemContainerStyle.Triggers.Add(t);

I have also tried the following with no luck –

editor.ItemContainerStyle = s;

I am getting an error that indicates that some object was not initialized and stepping through shows that editor.ItemContainerStyle is null.
The actual error message just says Exception has been thrown by the target of an invocation.

Does anyone have any idea what I might be doing wrong?
Thanks

  • 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-02T18:06:25+00:00Added an answer on June 2, 2026 at 6:06 pm

    I was able to get this working – below is the code that I actually ended up using –

    public bool IsSelectable
    {
        get { return (bool)GetValue(IsSelectableProperty); }
        set { SetValue(IsSelectableProperty, value); }
    }
    
    public static DependencyProperty IsSelectableProperty = DependencyProperty.Register("IsSelectable", typeof(bool), typeof(ListEditor), new FrameworkPropertyMetadata(true, new PropertyChangedCallback(IsSelectablePropertyChanged)) { BindsTwoWayByDefault = true });
    
    private static void IsSelectablePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        var editor = sender as ListEditor;
    
        var s = new Style(typeof(ListBoxItem));                
        var enableSetter = new Setter {Property = IsEnabledProperty, Value = editor.IsSelectable};
        s.Setters.Add(enableSetter);
    
        editor.ItemContainerStyle = s;                                       
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working in WPF, writing a custom user control. I am trying to change the
I'm working on a WPF custom control. The control has a property that is
In a WPF app I have objects, derived from a custom control: ... <MyNamespace:MyCustControl
I'm working on porting an app from WPF to Silverlight. The app uses custom
I'm working on Expression Blend and I'm currently designing a custom control which has
I'm working on my first WPF application and I'm testing out a custom control
I am working on a WPF datagrid custom control, where i have a Day
I did a custom button control in WPF and I am trying to implement
I am working on a custom control for WPF and Silverlight. This control has
I'm trying to create a custom control in WPF to display the game tree

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.