How to bind a value to user control property?
Now on,I just got AG_E_PARSER_BAD_PROPERTY_VALUE
.I think this is because I didn't do any thing to my bind property.Is there any thing I can do?
<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>
The commented code is the user control
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 inWid开发者_运维知识库th, Single inHeight, Single& outWidth, Single& outHeight)
The control 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>
the control 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;
}
}
}
}
Insufficient info.
AG_E_PARSER_BAD_PROPERTY_VALUE exception contains exact pointer (i.e. line/position in the Xaml file) where the problem happened. Find it, identify the place in the Xaml code and try to fix it.
Secondly, even if you showed us the Xaml position, we could only check syntactic errors as you hide the semantics - the corresp. C# code.
You say "I am sure Binding expression is correct", but is often something easily overlooked, such as "address" instead of "Address". (Do you really use nonstandard naming conventions?)
精彩评论