Hi,
The ClassDiagram example defines the class shape inside <style> definition. I need now dynamically access one TextBlock inside the definition as I need to set the text according to user input. I'm having hard time to do this as following does not work:
private void NewClass_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
ClassShape newClass= new ClassShape() { Content = "Class1", Position = new Point(300, 120) };
//newClass.ApplyTemplate();
var textBlock = newClass.FindName("TypeName") as TextBlock;
newClass.Loaded += this.OnNewClassLoaded;
this.diagram.Items.Add(newClass);
}
This is absolutely driving me crazy, so any help would be much appreciated.
The definition of ClassShape is something like:
<
Window.Resources
>
<
Style
TargetType
=
"local:ClassShape"
>
<
Setter
Property
=
"IsCollapsible"
Value
=
"True"
/>
<
Setter
Property
=
"IsResizingEnabled"
Value
=
"False"
/>
<
Setter
Property
=
"MinHeight"
Value
=
"100"
/>
<
Setter
Property
=
"MinWidth"
Value
=
"100"
/>
<
Setter
Property
=
"Padding"
Value
=
"15 5"
/>
<
Setter
Property
=
"Width"
Value
=
"150"
/>
<
Setter
Property
=
"Height"
Value
=
"Auto"
/>
<
Setter
Property
=
"HorizontalContentAlignment"
Value
=
"Left"
/>
<
Setter
Property
=
"Template"
>
<
Setter.Value
>
<
ControlTemplate
TargetType
=
"local:ClassShape"
>
<
Grid
x:Name
=
"RootPanel"
>
<
VisualStateManager.VisualStateGroups
>
<
VisualStateGroup
x:Name
=
"MouseStates"
>
<
VisualState
x:Name
=
"Normal"
/>
<
VisualState
x:Name
=
"MouseOver"
/>
</
VisualStateGroup
>
<
VisualStateGroup
x:Name
=
"CollapsedStates"
>
<
VisualState
x:Name
=
"Expanded"
/>
<
VisualState
x:Name
=
"Collapsed"
/>
</
VisualStateGroup
>
<
VisualStateGroup
x:Name
=
"ActiveConectionStates"
>
<
VisualState
x:Name
=
"NormalActiveConnectionState"
/>
<
VisualState
x:Name
=
"ActiveConnectionInsideShape"
>
<
Storyboard
>
<
ObjectAnimationUsingKeyFrames
Duration
=
"0"
Storyboard.TargetName
=
"ActiveSelectedBorder"
Storyboard.TargetProperty
=
"Visibility"
>
<
DiscreteObjectKeyFrame
KeyTime
=
"0"
>
<
DiscreteObjectKeyFrame.Value
>
<
Visibility
>Visible</
Visibility
>
</
DiscreteObjectKeyFrame.Value
>
</
DiscreteObjectKeyFrame
>
</
ObjectAnimationUsingKeyFrames
>
</
Storyboard
>
</
VisualState
>
</
VisualStateGroup
>
<
VisualStateGroup
x:Name
=
"ConnectorsAdornerVisibilityStates"
>
<
VisualState
x:Name
=
"ConnectorsAdornerCollapsed"
/>
<
VisualState
x:Name
=
"ConnectorsAdornerVisible"
>
<
Storyboard
>
<
ObjectAnimationUsingKeyFrames
Duration
=
"0"
Storyboard.TargetName
=
"ConnectorsControl"
Storyboard.TargetProperty
=
"Visibility"
>
<
DiscreteObjectKeyFrame
KeyTime
=
"0"
>
<
DiscreteObjectKeyFrame.Value
>
<
Visibility
>Visible</
Visibility
>
</
DiscreteObjectKeyFrame.Value
>
</
DiscreteObjectKeyFrame
>
</
ObjectAnimationUsingKeyFrames
>
</
Storyboard
>
</
VisualState
>
</
VisualStateGroup
>
<
VisualStateGroup
x:Name
=
"SelectionStates"
>
<
VisualState
x:Name
=
"Selected"
/>
<
VisualState
x:Name
=
"SelectedInGroup"
/>
<
VisualState
x:Name
=
"Unselected"
/>
<
VisualState
x:Name
=
"SelectedAsGroup"
/>
</
VisualStateGroup
>
<
VisualStateGroup
x:Name
=
"EditMode"
>
<
VisualState
x:Name
=
"NormalMode"
/>
<
VisualState
x:Name
=
"NormalEditMode"
>
<
Storyboard
>
<
ObjectAnimationUsingKeyFrames
Duration
=
"0"
Storyboard.TargetName
=
"TextContent"
Storyboard.TargetProperty
=
"Visibility"
>
<
DiscreteObjectKeyFrame
KeyTime
=
"0"
>
<
DiscreteObjectKeyFrame.Value
>
<
Visibility
>Collapsed</
Visibility
>
</
DiscreteObjectKeyFrame.Value
>
</
DiscreteObjectKeyFrame
>
</
ObjectAnimationUsingKeyFrames
>
<
ObjectAnimationUsingKeyFrames
Duration
=
"0"
Storyboard.TargetName
=
"EditContent"
Storyboard.TargetProperty
=
"Visibility"
>
<
DiscreteObjectKeyFrame
KeyTime
=
"0"
>
<
DiscreteObjectKeyFrame.Value
>
<
Visibility
>Visible</
Visibility
>
</
DiscreteObjectKeyFrame.Value
>
</
DiscreteObjectKeyFrame
>
</
ObjectAnimationUsingKeyFrames
>
</
Storyboard
>
</
VisualState
>
<
VisualState
x:Name
=
"TextBoxEditMode"
>
<
Storyboard
>
<
ObjectAnimationUsingKeyFrames
Duration
=
"0"
Storyboard.TargetName
=
"TextContent"
Storyboard.TargetProperty
=
"Visibility"
>
<
DiscreteObjectKeyFrame
KeyTime
=
"0"
>
<
DiscreteObjectKeyFrame.Value
>
<
Visibility
>Collapsed</
Visibility
>
</
DiscreteObjectKeyFrame.Value
>
</
DiscreteObjectKeyFrame
>
</
ObjectAnimationUsingKeyFrames
>
<
ObjectAnimationUsingKeyFrames
Duration
=
"0"
Storyboard.TargetName
=
"EditTextBox"
Storyboard.TargetProperty
=
"Visibility"
>
<
DiscreteObjectKeyFrame
KeyTime
=
"0"
>
<
DiscreteObjectKeyFrame.Value
>
<
Visibility
>Visible</
Visibility
>
</
DiscreteObjectKeyFrame.Value
>
</
DiscreteObjectKeyFrame
>
</
ObjectAnimationUsingKeyFrames
>
</
Storyboard
>
</
VisualState
>
</
VisualStateGroup
>
<
VisualStateGroup
x:Name
=
"DropStates"
>
<
VisualState
x:Name
=
"DropNormal"
/>
<
VisualState
x:Name
=
"DropComplete"
/>
<
VisualState
x:Name
=
"DragOver"
/>
</
VisualStateGroup
>
</
VisualStateManager.VisualStateGroups
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"*"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
Border
x:Name
=
"ContainerBorder"
Grid.RowSpan
=
"3"
Background
=
"{TemplateBinding Background}"
BorderBrush
=
"{TemplateBinding BorderBrush}"
BorderThickness
=
"{TemplateBinding BorderThickness}"
CornerRadius
=
"8"
/>
<
Grid
x:Name
=
"NormalContent"
MinHeight
=
"50"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
Width
=
"Auto"
/>
</
Grid.ColumnDefinitions
>
<
Border
Grid.ColumnSpan
=
"2"
BorderBrush
=
"{TemplateBinding BorderBrush}"
BorderThickness
=
"1 1 1 0"
CornerRadius
=
"8 8 0 0"
>
<
Border.Background
>
<
LinearGradientBrush
StartPoint
=
"0, 0.5"
EndPoint
=
"1, 0.5"
>
<
LinearGradientBrush.GradientStops
>
<
GradientStop
Color
=
"#FFD4DDEF"
/>
<
GradientStop
Offset
=
"1"
Color
=
"#FFFFFFFF"
/>
</
LinearGradientBrush.GradientStops
>
</
LinearGradientBrush
>
</
Border.Background
>
</
Border
>
<
StackPanel
x:Name
=
"TextContent"
Margin
=
"{TemplateBinding Padding}"
HorizontalAlignment
=
"{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment
=
"{TemplateBinding VerticalContentAlignment}"
>
<
TextBlock
FontSize
=
"12"
FontWeight
=
"Bold"
Text
=
"{TemplateBinding Content}"
/>
<
TextBlock
x:Name
=
"TypeName"
Grid.Row
=
"1"
Margin
=
"5 0 0 0"
FontSize
=
"9"
Text
=
""
/>