gpt4 book ai didi

c# - 代码隐藏中的绑定(bind)(转换器)

转载 作者:太空狗 更新时间:2023-10-29 22:15:50 25 4
gpt4 key购买 nike

<local:LabelTemp x:Key="labelTemplate"/>
<DataTemplate x:Key="labelTemp">
<TextBlock Text="{Binding Converter={StaticResource labelTemplate},Path=Item.Items}"/>
</DataTemplate>

任何人都可以帮助我如何将上述 Xaml 代码写入 Code Behind C#。我将此代码用于饼图标签模板。

最佳答案

我不知道绑定(bind)源是什么,也不知道饼图标签模板(转换器)长什么样。我能想到的最好的信息如下:

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);
}
}

并且您的文本 block 的名称为 txtBlock

希望对您有所帮助。

关于c# - 代码隐藏中的绑定(bind)(转换器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33481720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com