I have a diagram with multiple types of shapes that are bound to a view-model heirarchy that inherits from NodeViewModelBase similar to the following:
nd there are other view model shapes that derive from ColorViewModel and I used a NodeTemplateSelector and NodeStyleSelector to specify the data templates and style templates of each type of node. So far so good. But I also need to allow the user to add text annotations to the diagram. So the user can set the active tool to the TextTool and they are able to draw text. But, I need to be able to bind the text items the user adds to a corresponding view model and do two-way binding of the text. When the active tool is the TextTool, and a user adds a text shape to the diagram, the content of the shape is bound to an instance of a ColorViewModel. I can set a style template for the text shapes that the user adds, but when I bind the text to the underlying view model, things get borked.
Here is an example of the data template I have tried (and multiple variations of it):
and here is the style template:
Both templates are being correctly applied but when the data template is applied, the text is bound to the view model but I cannot change certain properties of the text using the SettingsPane and I cannot get the text box to act like the default text box of the RadDiagramTextShape. For example, the text box does not scale with the shape, and the forground color does not change when the SettingsPane is used.
Can anyone provide any advice on how to bind a view model to a RadDiagramTextShape and allow that shape to be edited using the SettingsPane and to have that shape act as like the default text shape?
Much thanks in advance,
Mike
public class RainbowViewModel : ObservableGraphSourceBase<
ColorViewModel
, inkViewModelBase<ColorViewModel>>
{ }
public class ColorViewModel : NodeViewModelBase
{
protected string mLabel;
public string Label
{
get
{
return mLabel;
}
set
{
if (mLabel != value)
{
mLabel = value;
OnPropertyChanged("Label");
}
}
}
}
nd there are other view model shapes that derive from ColorViewModel and I used a NodeTemplateSelector and NodeStyleSelector to specify the data templates and style templates of each type of node. So far so good. But I also need to allow the user to add text annotations to the diagram. So the user can set the active tool to the TextTool and they are able to draw text. But, I need to be able to bind the text items the user adds to a corresponding view model and do two-way binding of the text. When the active tool is the TextTool, and a user adds a text shape to the diagram, the content of the shape is bound to an instance of a ColorViewModel. I can set a style template for the text shapes that the user adds, but when I bind the text to the underlying view model, things get borked.
Here is an example of the data template I have tried (and multiple variations of it):
<
DataTemplate
x:Key
=
"annotationTemplate"
>
<
Grid
VerticalAlignment
=
"Stretch"
HorizontalAlignment
=
"Stretch"
>
<
TextBox
Text
=
"{Binding Label, Mode=TwoWay}"
TextWrapping
=
"Wrap"
AcceptsReturn
=
"True"
VerticalScrollBarVisibility
=
"Auto"
HorizontalScrollBarVisibility
=
"Auto"
VerticalAlignment
=
"Stretch"
HorizontalAlignment
=
"Stretch"
/>
</
Grid
>
</
DataTemplate
>
and here is the style template:
<
Style
x:Key
=
"annotationShapeStyle"
TargetType
=
"telerik:RadDiagramTextShape"
>
<
Setter
Property
=
"Visibility"
Value
=
"{Binding Visibility, Mode=TwoWay}"
/>
<
Setter
Property
=
"Position"
Value
=
"{Binding Position, Mode=TwoWay}"
/>
<
Setter
Property
=
"IsResizingEnabled"
Value
=
"True"
/>
<
Setter
Property
=
"IsRotationEnabled"
Value
=
"True"
/>
<
Setter
Property
=
"IsEditable"
Value
=
"True"
/>
<
Setter
Property
=
"IsConnectorsManipulationEnabled"
Value
=
"False"
/>
<
Setter
Property
=
"Background"
Value
=
"LightGray"
/>
</
Style
>
Both templates are being correctly applied but when the data template is applied, the text is bound to the view model but I cannot change certain properties of the text using the SettingsPane and I cannot get the text box to act like the default text box of the RadDiagramTextShape. For example, the text box does not scale with the shape, and the forground color does not change when the SettingsPane is used.
Can anyone provide any advice on how to bind a view model to a RadDiagramTextShape and allow that shape to be edited using the SettingsPane and to have that shape act as like the default text shape?
Much thanks in advance,
Mike