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 8523137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:19:23+00:00 2026-06-11T07:19:23+00:00

When I try to bind a ResourceDictionary item against Rectangle.Child , I get an

  • 0

When I try to bind a ResourceDictionary item against Rectangle.Child, I get an exception:

ArgumentException: Value does not fall within the expected range.

Here is an example:

<UserControl.Resources>
    <local:PersonConverter x:Key="MyConverter"/>
</UserControl.Resources>

<ListBox ItemsSource="{Binding Persons}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border Child="{Binding Gender, Converter={StaticResource MyConverter}}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

And the code behind:

public class MainViewModel : ViewModelBase
{
    public MainViewModel()
    {
        Persons = new List<Person> {new Person("Female"), new Person("Male")};
    }

    public List<Person> Persons { get; private set; }
}

public class PersonConverter : IValueConverter
{
    private ResourceDictionary Items { get; set; }

    public PersonConverterRes()
    {
        Items = new ResourceDictionary
            {
                {"Male", new Canvas() {
                                 Background = new SolidColorBrush(Colors.Blue),
                                 Height = 100, Width = 100}},
                {"Female", new Canvas() {
                                 Background = new SolidColorBrush(Colors.Magenta),
                                 Height = 100, Width = 100}}
            };
    }

    public object Convert(object value, Type targetType, object parameter,
                          System.Globalization.CultureInfo culture)
    {
        return Items[value.ToString()];
    }

    ...
}

public class Person
{
    public Person(String gender)
    {
        Gender = gender;
    }

    public String Gender { get; private set; }
}

But if I replace the ResourceDictionary with a plain Dictionary<String, UIElement> the binding works fine:

public class PersonConverter : IValueConverter
{
    private Dictionary<String, UIElement> Items { get; set; }

    public PersonConverterRes()
    {
        Items = new Dictionary<String, UIElement>
            {
                {"Male", new Canvas() {
                                 Background = new SolidColorBrush(Colors.Blue),
                                 Height = 100, Width = 100}},
                {"Female", new Canvas() {
                                 Background = new SolidColorBrush(Colors.Magenta),
                                 Height = 100, Width = 100}}
            };
    }

    ...
}

Does anybody know what is causing this exception?

Note:
I have tried this under WinRT as well. There, the code doesn’t throw an exception, but the binding still doesn’t work if I use a ResourceDictionary. I guess it’s probably failing silently.

  • 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-11T07:19:24+00:00Added an answer on June 11, 2026 at 7:19 am

    You can not use databinding to bind to the Child property of a Border since it is not a DependencyProperty. This is why your ResourceDictionary approach does not work.

    Also, databinding in WPF/Silvelight/WinRT fails silently by design (it’s a feature, and a very useful one if used correctly), so your guess would be right on that.

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

Sidebar

Related Questions

I get null pointer exception at line mService.start() when i try to bind to
I try to bind a NSString value into my SQL query but its not
I try to bind value from input select to attribute selectedValue in controller. This
When I try to bind socket to port 80 from program I get error,
I try to bind an IPv6 server socket in Java 1.6 on Windows 7,
I am try to bind the dropdowmlist using jquery. But is showing some error.
I'm trying to bind a function with a non-existent class. I will try to
try: recursive_function() except RuntimeError e: # is this a max. recursion depth exceeded exception?
I have some problems when I try to bind the height and width of
I am new to c# and try to bind a datagridview to a mssql

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.