简体   繁体   English

使用转换器绑定数据时在 Xaml 中出错

[英]Getting Error in Xaml while Binding data with Converter

I am getting an "Invalid XAML" error while Binding data with a Converter.使用转换器绑定数据时出现“无效 XAML”错误。 See this screenshot:看这个截图:

在这里出错

This is my Xaml code:这是我的 Xaml 代码:

<DataTemplate>
                        <Border BorderBrush="#cbc6c0"
                                BorderThickness="3"
                                CornerRadius="3"
                                Background="#FFF9F6F4">
                            <Grid Margin="5">
                                <ContentControl Content="{Binding   Converter={StaticResource Groupdetails}}" />
                            </Grid>
                        </Border>
                    </DataTemplate>

... and the C# code for my converter: ...以及我的转换器的 C# 代码:

public class ListDetailsConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        Model_Detail ObjDetail = value as Model_Detail;

        TextBlock TbInfo = new TextBlock();
        TbInfo.Margin = new Thickness(5, 5, 5, 5);
        TbInfo.TextWrapping = TextWrapping.Wrap;
        TbInfo.Foreground = new SolidColorBrush(Colors.Black);

        Bold TbTitle = new Bold();
        string StrTitle = ObjDetail.QuestionTitle;
        TbTitle.Inlines.Add(StrTitle);

        string StrDetails = " : " + ObjDetail.Detail;

        TbInfo.Inlines.Clear();
        TbInfo.Inlines.Add(TbTitle);
        TbInfo.Inlines.Add(StrDetails);
        return TbInfo;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

At the top of the Page xaml I have declared:在页面 xaml 的顶部,我已经声明:

 xmlns:MyConverter="clr-namespace:Magnitude_Gold.MGConverter"

<phone:PhoneApplicationPage.Resources>
        <MyConverter:ListDetailsConverter x:Key="Groupdetails" />
 </phone:PhoneApplicationPage.Resources>

What is wrong with this..?这有什么问题..?

使用这个,用你的实体或对象替换 Model_Detail

<ContentControl Content="{Binding  Path=Model_Detail Converter={StaticResource Groupdetails}}" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM