如何将值绑定到用户控件属性?

时间:2011-02-10 10:56:37

标签: silverlight data-binding windows-phone-7

现在,我刚刚得到AG_E_PARSER_BAD_PROPERTY_VALUE。我认为这是因为我没有对我的绑定属性做任何事情。我有什么可以做的吗?

                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Name="imgSvrIco" Source="{Binding pic}"/>
                                <StackPanel Orientation="Vertical" Margin="2,2,2,10" Tag="{Binding tag}" MouseLeftButtonUp="StackPanel_MouseLeftButtonUp_1">
                                    <TextBlock Name="lbTitle"  Text="{Binding title}" Margin="0,0,0,0" FontWeight="Bold" />
                                    <TextBlock Text="{Binding text}" Visibility="{Binding textVisibility}"/>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding time}"/>
                                        <TextBlock Text=" By " />
                                        <!--<my:UserBrand Address="{Binding address}" />-->
                                    </StackPanel>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>

评论的代码是用户控件

   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
   at MS.Internal.XcpImports.MeasureNative(IntPtr element, Single inWidth, Single inHeight)
   at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureChild(UIElement child, Size layoutSlotSize)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
   at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
   at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

控制xaml

<UserControl x:Class="Shisoft_Express_Communicate_mobile.controls.UserBrand"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="34" d:DesignWidth="395">
        <StackPanel HorizontalAlignment="Stretch" Name="stackPanel1" VerticalAlignment="Stretch" Orientation="Horizontal" Margin="0,0,0,-1">
            <Image Name="image1" Stretch="Uniform" Width="32" Height="32" VerticalAlignment="Center" />
            <TextBlock Name="textBlock1" Text="TextBlock" TextWrapping="NoWrap" Margin="3,0,0,0" />
        </StackPanel>
</UserControl>

控制cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;
using Shisoft_Express_Communicate_mobile.userinfos;
using System.Windows.Media.Imaging;

namespace Shisoft_Express_Communicate_mobile.controls
{
    public partial class UserBrand : UserControl
    {
        public UserBrand()
        {
            InitializeComponent();
        }
        private String _address;
        public String address
        {
            get { return _address; }
            set
            {
                _address = value;
                //sinat:shisoftgenius@hot...shisofttester:::shisoft
                String[] strs = Regex.Split(_address, ":::");
                String imgCode;
                String labText;
                if (strs[0] != "user" && strs[0] != "contact")
                {
                    imgCode = strs[0].Split(':')[0];
                }
                else
                {
                    imgCode = strs[0];
                    if (imgCode == "contact")
                    {
                        if (global.ContactIDTomName.ContainsKey(long.Parse(strs[1])))
                        {
                            strs[1] = global.ContactIDTomName[long.Parse(strs[1])];
                        }
                    }
                }
                labText = strs[1];
                ImageSource imgsrc1 = new BitmapImage(new Uri(SEC_Services.Httprequest.BaseURL + "images/svr-icons/" + imgCode + ".png"));
                this.image1.Source = imgsrc1;
                this.textBlock1.Text = labText;
            }
        }


    }
}

1 个答案:

答案 0 :(得分:0)

信息不足。

AG_E_PARSER_BAD_PROPERTY_VALUE异常包含问题发生的确切指针(即Xaml文件中的行/位置)。找到它,识别Xaml代码中的位置并尝试修复它。

其次,即使你向我们展示了Xaml的位置,我们也只能在你隐藏语义时检查语法错误 - 对应。 C#代码。

你说“我确定绑定表达式是正确的”,但通常容易被忽视,例如“地址”而不是“地址”。 (你真的使用非标准命名约定吗?)