wpf telerik user control databinding problem

2 posts, 0 answers
  1. OLeksiy
    OLeksiy avatar
    1 posts
    Member since:
    Jun 2013

    Posted 13 Jun 2013 Link to this post

    Hi I am trying to create teleric propertygrid-based user control that contains a multiline textbox, but I can't configure data-bindig.
    exactly i can't call set for property
    public UserControl1()
       {
           InitializeComponent();
           this.DataContext = this;
           Rad.Item = new object() { };
       }
       public string longStringVal_
       {
           get
           {
               return (string)GetValue(longStringVal);
           }
           set
           {
               SetValue(longStringVal, value);
           }
       }
    public static readonly DependencyProperty longStringVal =
       DependencyProperty.Register(
           "longStringVal_",
           typeof(string),
           typeof(TextBox)
       );

    <Grid>
        <telerik:RadPropertyGrid x:Name="Rad" >
            <telerik:RadPropertyGrid.PropertyDefinitions>
                <telerik:PropertyDefinition DisplayName="LongStr" OrderIndex="-1" >
                    <telerik:PropertyDefinition.EditorTemplate>
                        <DataTemplate>
                            <TextBox MinLines="3" MaxLines="3" 
                                     TextWrapping="Wrap"
                                     VerticalScrollBarVisibility="Visible"
                                     AcceptsReturn="true"
                                     x:Name="longStringValue"
                                     Text="{Binding Path = longStringVal_, Mode=TwoWay}"                                    
                                     />
                        </DataTemplate>
                    </telerik:PropertyDefinition.EditorTemplate>
                </telerik:PropertyDefinition>
              </telerik:RadPropertyGrid.PropertyDefinitions>
        </telerik:RadPropertyGrid>
    </Grid>
    Any help is much appreciated!

  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 18 Jun 2013 Link to this post

    Hello,

    The editors' DataContext is their parent PropertyGrid's Item. As the Object type does not have a longStringVal_ property your code results in a BindingExpressionPath error. The longStringVal_ is a member of the UserControl class, so that you should be using RelativeSource AncestorType binding to make it work.

    Regards,
    Ivan Ivanov
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top