【问题标题】:Silverlight: Define a custom ControlTemplate in C# instead of XAMLSilverlight:在 C# 中而不是 XAML 中定义自定义 ControlTemplate
【发布时间】:2010-01-01 06:27:48
【问题描述】:

我相信我正在使用 Silverlight 3.0...我这周刚刚下载了它。假设图表命名空间引用System.Windows.Controls.DataVisualization assembly in the Silverlight Toolkit,请帮助我使用 C# 创建 DataPointStyle,如下面的 XAML 所示:

<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>

我的目标是构建一个易于使用的模板库,这些模板可以应用于图表中的系列。谢谢!

【问题讨论】:

    标签: silverlight xaml


    【解决方案1】:

    您不能单独在 C# 中定义控件模板。我不知道你为什么想要?

    只需将您的一组控件模板的 XAML 作为资源添加到您的库中。使用XamlReader 将这些模板加载到您可以公开公开的对象中。

    【讨论】:

    • 啊,我明白了 - 谢谢。我会将 XAML 放入资源字典中。
    猜你喜欢
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 2020-02-24
    相关资源
    最近更新 更多