This is a migrated thread and some comments may be shown as answers.

Binding between elements are not working

3 Answers 318 Views
Wizard
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Patrick asked on 10 Feb 2020, 01:28 PM

Hello,

If I write the following XAML code in a wizard page:

<Label Target="{Binding ElementName=txt_Code}"
            Text="Code:" />

<TextBox Name="txt_Code" />

The binding is not made between the Label and the TextBox and VS shows the following error:

Cannot find source for binding with reference 'ElementName=txt_Code'. BindingExpression:(no path); DataItem=null; target element is 'Label' (Name=''); target property is 'Target' (type 'UIElement').

 

PS: Sorry for the formatting, but the formatting options are not working on this page...

 

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 12 Feb 2020, 12:13 PM

Hello Patrick,

I've tested this, but the binding works on my side. Can you check the attached project and let me know if I am missing anything?

Regards,
Martin Ivanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
answered on 12 Feb 2020, 04:33 PM

Hello Matin,

Add a second page to the wizard and looik what happens on this second page!
It's very rare that a wizard only contains a single page!

That gives the following for MainWindow.xaml (why the formatting options don't work on your site!!!!!):

<Window x:Class="TelerikWpfApp10.MainWindow"                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"         xmlns:local="clr-namespace:TelerikWpfApp10"         Title="MainWindow" Height="350" Width="525">   <Grid>     <telerik:RadWizard>       <telerik:RadWizard.WizardPages>         <telerik:WizardPage>           <telerik:WizardPage.Content>             <StackPanel>               <Label Target="{Binding ElementName=txt_Code}" Content="_code." />               <TextBox Name="txt_Code" />             </StackPanel>           </telerik:WizardPage.Content>         </telerik:WizardPage>         <telerik:WizardPage>           <telerik:WizardPage.Content>             <StackPanel>               <Label Target="{Binding ElementName=txt_Code2}" Content="_code." />               <TextBox Name="txt_Code2" />             </StackPanel>           </telerik:WizardPage.Content>         </telerik:WizardPage>       </telerik:RadWizard.WizardPages>     </telerik:RadWizard>   </Grid></Window>

0
Accepted
Martin Ivanov
Telerik team
answered on 13 Feb 2020, 12:53 PM

Hello Patrick,

Thank you for the code. We will check the formatting options in the forum's editor.

I was able to reproduce the reported behavior in the second page. This happens because of the optimization implemented in RadWizard. Basically, a wizard page will be loaded in the visual tree, only when it is the currently visible page. Otherwise, it is not present in the visual tree. The binding doesn't work because the second page is defined in the logical tree but it is not loaded visually when the XAML parser reads the elements in the file. The ElementName binding is evaluated, but the TextBox with Name="txt_Code2" is not found because it is not added in the visual tree yet. 

To achieve your requirement, you can set ContentTemplate instead of the Content property.

<telerik:WizardPage.ContentTemplate>
	<DataTemplate>
		<StackPanel>
			<Label Target="{Binding ElementName=txt_Code2}" Content="_code." />
			<TextBox Name="txt_Code2" />
		</StackPanel>
	</DataTemplate>
</telerik:WizardPage.ContentTemplate>

Or you can use x:Reference instead of ElementName binding. 

<telerik:WizardPage.Content>
	<StackPanel>
		<Label Target="{Binding Source={x:Reference txt_Code2}}" Content="_code." />
		<TextBox Name="txt_Code2" />
	</StackPanel>
</telerik:WizardPage.Content>

Regards,
Martin Ivanov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Wizard
Asked by
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Martin Ivanov
Telerik team
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or