2011-01-07 73 views
0

我不確定這是否可以完成,但是我已經爲DataPointStyle使用了一個自定義ControlTemplate的BubbleSeries。我想添加一些文字到泡泡,但我似乎無法獲得數據綁定的工作。我想將一個TextBlock綁定到我綁定的對象中的「Name」值。希望這些代碼應解釋:Silverlight圖表數據綁定到ControlTemplate

<Style x:Key="BubbleItemTemplate" TargetType="toolkit:BubbleDataPoint"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="toolkit:BubbleDataPoint"> 
        <Viewbox x:Name="viewbox"> 
         <Border> 
          <Grid> 
           <TextBlock Text="{TemplateBinding Name}" /> 
          </Grid> 
         </Border> 
        </Viewbox> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

和的ItemSource是

public void AddData(List<ChartItem> items) 
    { 
     List<Dictionary<string, object>> gridData = new List<Dictionary<string, object>>(); 
     foreach (var i in items) 
     { 
      gridData.Add(CreateBubbleEntry(i.XAxis, i.YAxis, i.ZAxis, i.Title)); 
     } 
     _bubbleView.ItemsSource = gridData; 
    } 

    private Dictionary<string, object> CreateBubbleEntry(double independent, double dependent, double size, string title) 
    { 
     var item = new Dictionary<string, object>(); 
     item.Add("independent", independent); 
     item.Add("dependent", dependent); 
     item.Add("size", size); 
     item.Add("Name", title); 
     return item; 
    } 

感謝

回答

0

嘗試更換:{TemplateBinding Name}{Binding Name}

這應該做的伎倆。