绑定过程路径中可能存在问题。我不知道我是脱衣舞娘,我会感激任何建议:)
当我从WPControls.dll向我的Calendar Control添加此代码ColorConverter="{StaticResource ColorConverter}"
时,我遇到了大问题
ColorConverter.cs是一个类,其任务是为所选日期着色。
当我排除ColorConverter="{StaticResource ColorConverter}"
时
日历工作得很好...重新启动VS2013并重建不起作用
这是我的主页
<phone:PhoneApplicationPage
x:Class="Ap_1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="False"
xmlns:wpControls="clr-namespace:WPControls;assembly=WPControls"
xmlns:local="clr-namespace:Ap_1"
Loaded="PhoneApplicationPage_Loaded" >
<phone:PhoneApplicationPage.Resources>
<local:ColorConverter x:Key="ColorConverter"/>
</phone:PhoneApplicationPage.Resources>
这是我在MainPage中的日历
<!--Panorama item Calendar-->
<phone:PanoramaItem Header="Kalendarz studenta">
<!--Single line list with text wrapping-->
<Grid x:Name="ContentPanel222" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<wpControls:Calendar
x:Name="Cal"
ColorConverter="{StaticResource ColorConverter}"
/>
<Button Grid.Row="1" Content="{Binding ElementName=Cal,Path=SelectedDate}"/>
</Grid>
</phone:PanoramaItem>
这是ColorConverter.cs
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using WPControls;
namespace Ap_1
{
public class ColorConverter : IDateToBrushConverter
{
public Brush Convert(DateTime dateTime, bool isSelected, Brush defaultValue, BrushType brushType)
{
if (brushType == BrushType.Background)
{
if (dateTime == new DateTime(DateTime.Today.Year, DateTime.Today.Month, 5))
{
return new SolidColorBrush(Colors.Yellow);
}
else
{
return defaultValue;
}
}
else
{
if (dateTime == new DateTime(DateTime.Today.Year, DateTime.Today.Month, 6))
{
return new SolidColorBrush(Colors.Red);
}
else
{
return defaultValue;
}
}
}
}
}
这是IDateToBrushConverter.cs
using System;
using System.Windows.Media;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ap_1
{
public interface IDateToBrushConverter
{
Brush Convert(DateTime dateTime, bool isSelected, Brush defaultValue, BrushType brushType);
}
}
这是问题:
例外:类型为&#34; Ap_1.ColorConverter&#34;的对象无法应用于需要类型的属性&#34; WPControls.IDateToBrushConverter&#34;。
堆栈跟踪: 在Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.UpdatePropertyOrChildValue(IInstanceBuilderContext context,ViewNode viewNode,IProperty propertyKey,Int32 childIndex,DocumentNodeChangeAction action,DocumentNode valueNode,ViewNode&amp; childViewNode,IInstanceBuilder&amp; valueBuilder,Boolean&amp; isNewInstance) 在Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.UpdateProperty(IInstanceBuilderContext context,ViewNode viewNode,IProperty propertyKey,DocumentNode valueNode) 在Microsoft.Expression.Platform.InstanceBuilders.DependencyObjectInstanceBuilderBase`1.UpdateProperty(IInstanceBuilderContext context,ViewNode viewNode,IProperty propertyKey,DocumentNode valueNode) 在Microsoft.Expression.SilverlightPlatform.InstanceBuilders.FrameworkElementInstanceBuilder.UpdateProperty(IInstanceBuilderContext context,ViewNode viewNode,IProperty propertyKey,DocumentNode valueNode) 在Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateProperties(IInstanceBuilderContext context,ViewNode viewNode,DocumentCompositeNode compositeNode) 在Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.Initialize(IInstanceBuilderContext context,ViewNode viewNode,Boolean isNewInstance) 在Microsoft.Expression.Platform.InstanceBuilders.ViewNodeManager.InitializeInstance(IInstanceBuilder构建器,ViewNode viewNode,Boolean isNewInstance)
答案 0 :(得分:0)
据我所知,您有2个不同的IDateToBrushConverter
接口。一个位于 WPControls 名称空间中,由wpControls:Calendar.ColorConverter
属性使用,第二个位于 Ap_1 名称空间中,由ColorConverter
类实现,因此出现错误
“Ap_1.ColorConverter”类型的对象无法应用于需要“WPControls.IDateToBrushConverter”类型的属性
而不是在 Ap_1 命名空间中定义第二个接口,而不是使用 WPControls 命名空间中的第二个接口
namespace Ap_1
{
public class ColorConverter : WPControls.IDateToBrushConverter
{
//your code
}
}