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
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
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>
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