This is a migrated thread and some comments may be shown as answers.
ContentTemplate
1 Answer 20 Views
This is a migrated thread and some comments may be shown as answers.
Voss Grose
Top achievements
Rank 1
Voss Grose asked on 20 Oct 2009, 10:12 PM
I changed the example DragAndDrop (first look) a little and have everything working great, but I want to be able to update the ContentControl.ContentTemplate(DataTemplate).

I re-dedinfed the DataTemplate (below) and I'm trying to get a reference to TextBlock defined in the the DataTemplate during the execution of OnDragQuery so I can set the .Text of the TextBlock.

DataTemplate defined (which has a TextBlock):
<DataTemplate x:Key="ApplicationDragTemplate">
            <StackPanel>
                <Border BorderBrush="DarkGray" BorderThickness="1" Width="40" Height="40">
                    <Canvas>
                        <Rectangle Width="38" Height="38" Canvas.Left="0" Canvas.Top="0" Stroke="DarkGray" Margin="0, 0, 0, 0" HorizontalAlignment="Center" VerticalAlignment="Center" UseLayoutRounding="False" RadiusY="0" RadiusX="0">
                            <Rectangle.Fill>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                    <GradientStop Color="#00000000" Offset="1"/>
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <TextBlock Text="401" FontWeight="Bold" Foreground="DarkGray" Width="35" Canvas.Left="3" Canvas.Top="2" />
                    </Canvas>
                </Border>                    
            </StackPanel>
        </DataTemplate>

1 Answer, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 23 Oct 2009, 01:02 PM
Hello Voss Grose,

My advice here is to bind the Text property of the TextBlock in the DataTemplate, something like:

Text="{Binding MyProperty}"

Then you will have to assign as Content of the ContentControl an object that has a property named MyProperty and afterwards you only need to change this object. If you want to change just this string, you can assign a string as the content:

dragCue.Content = "402"

and then use the empty binding in the template:

Text="{Binding}"

Hopefully this will work for you,

All the best,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Asked by
Voss Grose
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Share this question
or