【发布时间】:2014-10-11 22:18:46
【问题描述】:
我有一个自定义方法,它返回将用作背景的 Brush:
class ListBoxBackgroundSelector : BackgroundBrushSelector
{
public Brush fondo1 { get; set; }
public Brush fondo2 { get; set; }
private static bool usado = false;
public override Brush SelectBrushStyle(object item, DependencyObject container)
{
Brush fondo = null;
if (usado)
{
fondo = fondo1;
}
else
{
fondo = fondo2;
}
usado = !usado;
return fondo;
}
从抽象类扩展而来
public abstract class BackgroundBrushSelector : ContentControl
{
public abstract Brush SelectBrushStyle(object item, DependencyObject container);
protected override void OnContentChanged(object oldContent, object newContent)
{
base.OnContentChanged(oldContent, newContent);
Background = SelectBrushStyle(newContent, this);
}
}
我在下面的 XAML 声明中使用它
<Grid.Background>
<local:ListBoxBackgroundSelector Background="{Binding}" fondo1="#19001F5B" fondo2="#FFFFFFFF" />
</Grid.Background>
但 Visual Studio 突出显示 local:ListBoxBackgroundSelector 行并显示错误提示
无法分配特定值。期望值为“刷子”
但是该方法返回一个Brush!它的返回值被分配给背景,它确实需要一个画笔。
项目编译并运行,但当它到达包含所有这些东西的页面时,它只是以“未处理的异常”中断,没有其他可看的东西。
中间有一些我不知道的东西。有人可以帮忙吗?
【问题讨论】:
标签: c# xaml windows-phone