Binding to this[enum] characteristic of a Class



  • Got it. enum

    namespace namespace1.namespace2{
      enum PropertyObject 
      {
        A=1,
        B=2,
        ...
      }
    }
    

    and class is completely different. namespace

    public class MyClass
    {
      public Object this[namespace1.namespace2.PropertyObject property]
      {
        get
        {
          return ...;
        }
      }
    }
    

    List of copies ItemsSource ListViewThere is also DataTemplate Filled like ItemTemplate Ooh. ListView

    <DataTemplate x:Key="MyTemplate">
      <TextBlock Text="{Binding Path=this[namespace1.namespace2.PropertyObject.A]}"/>
    </DataTemplate>
    

    I'm sure it's true. PropertyObject Eczepsies have been installed, but they say they can't reach this characteristic of how to create a validation. Binding to these properties?

    mistake: System.Windows.Data Error: 40 : BindingExpression path error: '[]' property not found on 'object' ''MyClass' (HashCode=55693485)'. BindingExpression:Path=this[namespace1.namespace2.PropertyObject.A]; DataItem='MyClass'



  • You're using an incorrect syntaxis to get the transfer value. In XAML, the X-ML spaces (namespace in C#) and the X-ML area (xmlns in XML) are put in the file cap. However, even an indication of the exact type may not be necessary: XAML is smart enough to add a line to the listing itself.

    There's no "this" in the bindings either. You probably need a context or a context.Path='.' or simply Path=''or current component(s)RelativeSource='{RelativeSource Self}' and others).

    Let's just say we have the following code:

    namespace HakunaMatata
    {
        public partial class MainWindow
        {
            public MainWindow ()
            {
                InitializeComponent();
                DataContext = new Model();
            }
        }
    
    public class Model
    {
        public string this [Other.Property prop] =&gt; prop.ToString() + " from Indexer";
    }
    

    }

    namespace Other
    {
    public enum Property
    {
    Foo,
    Bar,
    }
    }

    Then all of the ways of applying to the indexer will work correctly:

    <Window x:Class="HakunaMatata.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:HakunaMatata"
    xmlns:other="clr-namespace:Other">
    <StackPanel>
    <TextBlock Text="{Binding Path=[Foo]}"/>
    <TextBlock Text="{Binding Path=[(other:Property)Foo]}"/>
    <TextBlock Text="{Binding Path=.[Foo]}"/>
    <TextBlock Text="{Binding Path=.[(other:Property)Foo]}"/>
    </StackPanel>
    </Window>




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2