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

Bindings in two diferent Datatemplates for the same control

2 Answers 83 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Artur
Top achievements
Rank 1
Artur asked on 05 Aug 2010, 10:29 AM

Hi,

I'm doing a generic controller, right now is one Radbutton with two different datatemplates. Each dataTemplate has an specific key and in code-behind i will change between them.

My problem is i cannot do the binding to my properties. For example:

My Xaml looks like:

<telerik:RadButton x:Class="Itim.Framework.Silverlight.UI.Controls.Button"
                   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:Itim.Framework.Silverlight.UI.Controls"
                   SizeChanged="btnGeneric_SizeChanged">
    <telerik:RadButton.Resources>
 
        <!--Default dataTemplate-->
        <DataTemplate x:Key="Standard">
            <StackPanel DataContext="{Binding}" Orientation="Horizontal">
                <Image Source="{Binding ImageSource}" Visibility="{Binding ImageVisibility}"
                       Stretch="Fill" VerticalAlignment="Stretch" HorizontalAlignment="Right" />
                <TextBlock Text="{Binding Content, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                           TextAlignment="Center" Visibility="{Binding TextVisibility,Mode=TwoWay}" Width="{Binding TextBlockWidth}" />
            </StackPanel>
        </DataTemplate>
 
        <!--Ok button data template-->
        <DataTemplate x:Key="Ok">
            <StackPanel DataContext="{Binding}" Orientation="Horizontal" >
                <Image Source="{Binding ImageOkSource}" Visibility="{Binding ImageVisibility}"
                       Stretch="Fill" VerticalAlignment="Stretch"/>
                <TextBlock Text="{Binding DefaultOkText}" Visibility="{Binding TextVisibility,Mode=TwoWay}"
                           TextAlignment="Center" Width="{Binding TextBlockWidth}"/>
            </StackPanel>
        </DataTemplate>
 
    </telerik:RadButton.Resources>
</telerik:RadButton>
and in c# when i wanna change the datatemplate i do something like this:

this.ContentTemplate = this.Resources["Standard"] as DataTemplate;

My button class will inherit from the RadButton, and every property is defined there (like ImageSource or DefaultOkText of the image binding in the Xaml i post).

But when i use this controller, with for example the Standard datatemplate, the image (from ImageSource) doesn't show, but the Text from the textblock shows. The same happens when i change for the OK datatemplate (in this case will not put anything because the binding of ImageOkSource or DefaultOkText will not do).

What can i do to get this working?

Thanks

2 Answers, 1 is accepted

Sort by
0
Artur
Top achievements
Rank 1
answered on 06 Aug 2010, 06:00 PM
No one knows? i'm working on this problem for two long days (and nights)... i don't know what else i will do!!
0
Miro Miroslavov
Telerik team
answered on 10 Aug 2010, 11:39 AM
Hello Artur,

What is the type and value of ImageSource property? If the text is working, but the Image is not, means that you don't have correct values for Image.Source property.
Can you send us example project, so we will be able to assist you further?
Thank you.

Regards,
Miro Miroslavov
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
Tags
General Discussions
Asked by
Artur
Top achievements
Rank 1
Answers by
Artur
Top achievements
Rank 1
Miro Miroslavov
Telerik team
Share this question
or