<esriSymbols:TextSymbol x:Name="AddTextSymbol" Foreground="Black" FontSize="14" />
GraphicsLayer graphicsLayer = MyMap.Layers["MyAddGraphicsLayer"] as GraphicsLayer;
ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
{
Geometry = e.MapPoint,
Symbol = AddTextSymbol
};
graphicsLayer.Graphics.Add(graphic);
esri:TextSymbol FontFamily="Arial" FontSize="14" Foreground="Black" Text="My Text" > <esri:TextSymbol.ControlTemplate> <ControlTemplate> <TextBlock Text="{Binding Symbol.Text}" FontFamily="{Binding Symbol.FontFamily}" FontSize="{Binding Symbol.FontSize}" Foreground="{Binding Symbol.Foreground}" FontStyle="Italic" FontWeight="Bold"/> </ControlTemplate> </esri:TextSymbol.ControlTemplate> </esri:TextSymbol>
FontStyle is not a property of the TextSymbol.
So, if you want to set the FontStyle, you have to change the template of the TextSymbol:
I need to give a x:name to this textblock and change its fontstyle when combo selection changes?
<esri:TextSymbol FontFamily="Arial" FontSize="14" Foreground="Black" Text="My Text" >
<esri:TextSymbol.ControlTemplate>
<ControlTemplate>
<TextBlock Text="{Binding Symbol.Text}"
FontFamily="{Binding Symbol.FontFamily}"
FontSize="{Binding Symbol.FontSize}"
Foreground="{Binding Symbol.Foreground}"
FontStyle="{Binding Attributes[FontStyle]}
FontWeight="{Binding Attributes[FontWeight]}"/>
</ControlTemplate>
</esri:TextSymbol.ControlTemplate>
</esri:TextSymbol>
Unfortunately it's not that easy to change a template by code.
Depending on your context, I see two options:
- your write your own TextSymbol class (by subclassing MarkerSymbol since TextSymbol is sealed) and add 'FontStyle' and 'FontWeight' dependency properties. Then these properties will be useable like 'FontFamiliy', 'FontSize', ... with TextSymbol
- if the FontStyle is per graphic, you might store it in an attribute of the graphics (by code). Then you can define your textsymbol with a binding to Attributes:
<esri:TextSymbol x:Name="AddTextSymbol" >
<esri:TextSymbol.ControlTemplate>
<ControlTemplate>
<TextBlock Text="{Binding Attributes[Text]}"
FontFamily="{Binding Attributes[FontFamily]}"
FontSize="{Binding Attributes[FontSize]}"
Foreground="{Binding Attributes[Foreground]}"
FontStyle="{Binding Attributes[FontStyle]}"
FontWeight="{Binding Attributes[FontWeight]}"
/>
</ControlTemplate>
</esri:TextSymbol.ControlTemplate>
</esri:TextSymbol>
ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
{
Geometry = e.MapPoint,
Symbol = AddTextSymbol
};
graphic.Attributes["Text"] = AddTextTextBox.Text;
graphic.Attributes["FontFamily"] = AddTextFontCombo.SelectedItem.ToString();
graphic.Attributes["FontSize"] = AddTextSizeCombo.SelectedItem.ToString();
graphic.Attributes["Foreground"] = AddTextColorCombo.SelectedItem.ToString();
if (AddTextStyleCombo.SelectedItem.ToString() == "Italic")
{
graphic.Attributes["FontStyle"] = "Italic";
}
else if (AddTextStyleCombo.SelectedItem.ToString() == "Regular")
{
graphic.Attributes["FontStyle"] = "Normal";
}
else if (AddTextStyleCombo.SelectedItem.ToString() == "Bold")
{
graphic.Attributes["FontWeight"] = "Bold";
}
graphicsLayer.Graphics.Add(graphic);
Hi,
You can use the RenderTransform you mention to apply a RotationTransform to the TextBlock
<TextBlock FontSize="14" Canvas.Left="17" Canvas.Top="100" Foreground="Blue" Text="45 Degree Text" >
<TextBlock.RenderTransform>
<TransformGroup>
<RotateTransform Angle="-45"/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
<esri:TextSymbol x:Name="AddTextSymbol" >
<esri:TextSymbol.ControlTemplate>
<ControlTemplate>
<TextBlock Text="{Binding Attributes[Text]}"
FontFamily="{Binding Attributes[FontFamily]}"
FontSize="{Binding Attributes[FontSize]}"
Foreground="{Binding Attributes[Foreground]}"
FontStyle="{Binding Attributes[FontStyle]}"
FontWeight="{Binding Attributes[FontWeight]}">
<TextBlock.RenderTransform>
<TransformGroup>
<RotateTransform Angle="{Binding Attributes[Angle]}"/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</ControlTemplate>
</esri:TextSymbol.ControlTemplate>
</esri:TextSymbol>