Binding(Converter) in Code Behind

前端 未结 1 2014
暗喜
暗喜 2020-12-31 18:12

        
            

        
相关标签:
1条回答
  • 2020-12-31 18:37

    I don't what is the binding source, or how the Pie Chart LabelTemplate (converter) look like. The best I can come up with that much information is the following:

    public class LabelTemplate : IValueConverter
    {
    
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //...
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //...
        }
    }
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            LabelTemplate labelTemplateConverter = new LabelTemplate();
            Binding binding = new Binding("Item.Items");
            binding.Converter = labelTemplateConverter;
            txtBlock.SetBinding(TextBlock.TextProperty, binding);
        }
    }
    

    and Your textblock have the Name txtBlock

    I hope this helps.

    0 讨论(0)
提交回复
热议问题