Silverlight:用C#而不是XAML定义自定义控件模板
我相信我正在使用Silverlight 3.0。。。我这周刚下载的。假设图表名称空间引用,请帮助我使用C#创建DataPointStyle,如下所示:Silverlight:用C#而不是XAML定义自定义控件模板,silverlight,xaml,Silverlight,Xaml,我相信我正在使用Silverlight 3.0。。。我这周刚下载的。假设图表名称空间引用,请帮助我使用C#创建DataPointStyle,如下所示: <charting:Chart Title="Simple Column Annotations - Bottom"> <charting:ColumnSeries DependentValuePath="Value" IndependentValuePath="Key"
<charting:Chart
Title="Simple Column Annotations - Bottom">
<charting:ColumnSeries
DependentValuePath="Value"
IndependentValuePath="Key"
ItemsSource="{Binding}">
<!-- HERE IS WHAT I WANT TO CREATE IN C#: -->
<charting:ColumnSeries.DataPointStyle>
<Style TargetType="charting:ColumnDataPoint">
<Setter Property="Background" Value="Yellow"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:ColumnDataPoint">
<Grid>
<Rectangle
Fill="{TemplateBinding Background}"
Stroke="Black"/>
<Grid
Background="#aaffffff"
Margin="0 -20 0 0"
HorizontalAlignment="Center"
VerticalAlignment="Bottom">
<TextBlock
Text="{TemplateBinding FormattedDependentValue}"
FontWeight="Bold"
Margin="2"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</charting:ColumnSeries.DataPointStyle>
<!-- END -->
</charting:ColumnSeries>
</charting:Chart>
我的目标是构建一个易于使用的模板库,这些模板可以应用于图表中的系列。谢谢 不能仅用C#定义控件模板。我不知道你为什么要这么做
只需将控件模板集的XAML添加为库中的资源。使用
XamlReader
将这些模板加载到对象中,然后您可以公开这些对象。啊,我明白了-谢谢。我将把XAML放入资源字典中。