数据绑定到TextBlock

时间:2015-10-28 08:52:12

标签: c# wpf charts pie-chart syncfusion

this.PieSeries = new ObservableCollection<RevenueProperties>()
            {
                new RevenueProperties() { Items = "iTunes", Revenue = 6},
                new RevenueProperties() { Items = "Others", Revenue = 4},
                new RevenueProperties() { Items = "iPhone", Revenue = 48},
                new RevenueProperties() { Items = "iPad", Revenue = 21},
                new RevenueProperties() { Items = "Mac", Revenue = 18},
                new RevenueProperties() { Items = "iPod", Revenue = 2},
            };
        this.DataContext = this;

<Window.Resources>
        <DataTemplate x:Key="labelTemplate">
            <Grid>
                <TextBlock Text="{Binding Items}"/>
                <TextBlock Text="{Binding Revenue}"/>
            </Grid>
        </DataTemplate>
    </Window.Resources>

<Grid>
<Chart:PieSeries ExplodeIndex="0" ExplodeRadius="15" ExplodeAll="False" Palette="Custom" LabelPosition="Inside"
                                      ItemsSource="{Binding PieSeries}" XBindingPath="Items" YBindingPath="Revenue">

                    <Chart:PieSeries.AdornmentsInfo>
                        <Chart:ChartAdornmentInfo FontSize="9" ShowLabel="True" SegmentLabelContent="Percentage"
                                                       ShowConnectorLine="True" LabelTemplate="{StaticResource labelTemplate}"/>
                    </Syncfusion:PieSeries.AdornmentsInfo>
</Chart:PieSeries>

我尝试上面的程序textblock值没有绑定任何东西,当我运行这个程序得到空饼图。请帮助解决此绑定问题

1 个答案:

答案 0 :(得分:0)

您是否在课后的窗口代码上实现了INotiFyProperty接口? 如果没有,请在窗口上实现Inotify ...并从PieSeries,Items和Revenue字段的setter中调用OnPropertyChanged方法。

检查以下链接有关INotify的详细说明...界面: http://www.codeproject.com/Articles/41817/Implementing-INotifyPropertyChanged