System.Windows.StaticResourceExtension 无法应用 属性
System.Windows.StaticResourceExtension cannot aplied property
可能是绑定进程路径有问题。我不知道我是一个 stripling,如果有任何建议,我将不胜感激 :)
当我从 WPControls.dll 添加此代码 ColorConverter="{StaticResource ColorConverter}"
到我的日历控件时,我遇到了大问题
ColorConverter.cs 是一个 class,其任务是为选定的日期着色。
当我排除 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);
}
}
这是问题:
Exception: An object of the type "Ap_1.ColorConverter" cannot be applied to a property that expects the type "WPControls.IDateToBrushConverter".
Stack Trace:
at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.UpdatePropertyOrChildValue(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, Int32 childIndex, DocumentNodeChangeAction action, DocumentNode valueNode, ViewNode& childViewNode, IInstanceBuilder& valueBuilder, Boolean& isNewInstance)
at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
at Microsoft.Expression.Platform.InstanceBuilders.DependencyObjectInstanceBuilderBase`1.UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
at Microsoft.Expression.SilverlightPlatform.InstanceBuilders.FrameworkElementInstanceBuilder.UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateProperties(IInstanceBuilderContext context, ViewNode viewNode, DocumentCompositeNode compositeNode)
at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.Initialize(IInstanceBuilderContext context, ViewNode viewNode, Boolean isNewInstance)
at Microsoft.Expression.Platform.InstanceBuilders.ViewNodeManager.InitializeInstance(IInstanceBuilder builder, ViewNode viewNode, Boolean isNewInstance)
这是我的屏幕
据我所知,您有 2 个不同的 IDateToBrushConverter
界面。一个在 WPControls 命名空间中,由 wpControls:Calendar.ColorConverter
属性 使用,第二个在 Ap_1 命名空间中由 ColorConverter
class 实现,因此错误
An object of the type "Ap_1.ColorConverter" cannot be applied to a property that expects the type "WPControls.IDateToBrushConverter
不要在 Ap_1 命名空间中定义第二个接口,而是使用 WPControls 命名空间
中的一个
namespace Ap_1
{
public class ColorConverter : WPControls.IDateToBrushConverter
{
//your code
}
}
可能是绑定进程路径有问题。我不知道我是一个 stripling,如果有任何建议,我将不胜感激 :)
当我从 WPControls.dll 添加此代码 ColorConverter="{StaticResource ColorConverter}"
到我的日历控件时,我遇到了大问题
ColorConverter.cs 是一个 class,其任务是为选定的日期着色。
当我排除 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);
}
}
这是问题:
Exception: An object of the type "Ap_1.ColorConverter" cannot be applied to a property that expects the type "WPControls.IDateToBrushConverter".
Stack Trace: at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.UpdatePropertyOrChildValue(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, Int32 childIndex, DocumentNodeChangeAction action, DocumentNode valueNode, ViewNode& childViewNode, IInstanceBuilder& valueBuilder, Boolean& isNewInstance) at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode) at Microsoft.Expression.Platform.InstanceBuilders.DependencyObjectInstanceBuilderBase`1.UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode) at Microsoft.Expression.SilverlightPlatform.InstanceBuilders.FrameworkElementInstanceBuilder.UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode) at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateProperties(IInstanceBuilderContext context, ViewNode viewNode, DocumentCompositeNode compositeNode) at Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.Initialize(IInstanceBuilderContext context, ViewNode viewNode, Boolean isNewInstance) at Microsoft.Expression.Platform.InstanceBuilders.ViewNodeManager.InitializeInstance(IInstanceBuilder builder, ViewNode viewNode, Boolean isNewInstance)
这是我的屏幕
据我所知,您有 2 个不同的 IDateToBrushConverter
界面。一个在 WPControls 命名空间中,由 wpControls:Calendar.ColorConverter
属性 使用,第二个在 Ap_1 命名空间中由 ColorConverter
class 实现,因此错误
An object of the type "Ap_1.ColorConverter" cannot be applied to a property that expects the type "WPControls.IDateToBrushConverter
不要在 Ap_1 命名空间中定义第二个接口,而是使用 WPControls 命名空间
中的一个namespace Ap_1
{
public class ColorConverter : WPControls.IDateToBrushConverter
{
//your code
}
}