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

Problem with Binding

2 Answers 160 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
George Bill
Top achievements
Rank 1
George Bill asked on 03 Jun 2010, 08:30 AM
Hello,

I've already created a topic in this forum, and I need your help once again.
I work with the same configuration (it's the same application) : Telerik + MS Prism
Link : Close tabs - RadTabControl + Prism

I have a problem with the Binding and RadTabControl.
I have a button to add a RadTabItem in my RadTabControl, and the content of the RadTabItem work with a ContentTemplate.
The content is a form with some TextBox and each textbox has a Binding with an Object in my Model.

CODE :
So, here the XAML code of my RadTabControl :
<telerik:RadTabControl Name="RadTabControlAddress" SelectionChanged="RadTabControlAddress_SelectionChanged"
                    <telerik:RadTabControl.ItemContainerStyle> 
                        <Style TargetType="{x:Type telerik:RadTabItem}"
                            <Setter Property="ContentTemplate"
                                <Setter.Value> 
                                    <DataTemplate> 
                                        <Grid Name="Grid"
                                            <Grid.ColumnDefinitions> 
                                                <ColumnDefinition Width="100" /> 
                                                <ColumnDefinition Width="*"/> 
                                            </Grid.ColumnDefinitions> 
                                            <Grid.RowDefinitions> 
                                                <RowDefinition /> 
                                            </Grid.RowDefinitions> 
                                            <TextBlock Text="{Loc address1}" Grid.Row="0" Grid.Column="0"></TextBlock> 
                                            <TextBox Grid.Row="0"  Grid.Column="1" Text="{Binding Adresse.Adresse1 }" Height="30" Margin="5"></TextBox> 
                                        </Grid> 
                                    </DataTemplate> 
                                </Setter.Value> 
                            </Setter> 
                        </Style> 
                    </telerik:RadTabControl.ItemContainerStyle> 
                 
                </telerik:RadTabControl> 
(I deleted some field for a short version)

I have a simple RadButton with this event :
private void AddAddressTab() 
        { 
            _model.AddAddress(); 
            RadTabItem itemToAdd = new RadTabItem() 
            { 
                Header = "New Tab" 
            }; 
            RadTabControlAddress.Items.Add(itemToAdd); 
            RadTabControlAddress.SelectedIndex = RadTabControlAddress.Items.Count - 1; 
        } 

The constructor in my XAML.cs is :
public AjouterView(AjouterViewModel model) 
        { 
            InitializeComponent(); 
            // Sauvegarde du model dans un attribut de la classe. 
            _model = model; 
            // On se sert de notre model en tant que DataContext. 
            this.DataContext = model; 
 
            //AddAddressTab(); 
        } 

In my Model I have two attribute :
private IAdresse _adresse = null
        public IAdresse Adresse 
        { 
            get { return _adresse; } 
            set 
            { 
                _adresse = value; 
                OnPropertyChanged("Adresse"); 
            } 
        }
My Model implement INotifyPropertyChanged - (And sorry for french name...)

The AddAddress() Method (in the model) :
public void AddAddress() 
        { 
            IAdresse address = new Adresse("Just a test"); 
            ListAdresse.Add(address); 
            Adresse = address; 
        } 

I not include the system to change the address when we select an other Tab.

PROBLEM :
The first time we add an address (add a Tab in the TabControl), the binding doesn't work. I need to add two address for work. I don't find why ! The binding work only if I click the Button (to add an other address) if there is already a Tab in the TabControl.

ATTACHED FILE :
You can download a demo here : Download

If you need more informations, please tell me.
Thank you in advance for your answer.

Regards,
G.B.

[EDIT] : Nobody shall have the beginning of solution ? I don't find how to fix this problem !

2 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Tsvetkov
Telerik team
answered on 08 Jun 2010, 12:26 PM
Hello George Bill,

Thank you for contacting us. Attached you can find a modified version of your project. Could you please have a look at it and let me know how it works for you. I'd be glad to further assist you.

Greetings,
Viktor Tsvetkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
George Bill
Top achievements
Rank 1
answered on 08 Jun 2010, 02:30 PM
Hello,

It's perfect,  thank you !
I learnt WPF a few months ago and some techniques are not evident for me. So thanks again for this reply.
I also had think to use ItemSource but I had not used it correctly.
Now the code is simpler.

(I mark your Reply as Answer)

Thanks Telerik Team and Best Regards,
Telerik rocks,
B.G.
Tags
TabControl
Asked by
George Bill
Top achievements
Rank 1
Answers by
Viktor Tsvetkov
Telerik team
George Bill
Top achievements
Rank 1
Share this question
or