[英]Namespace issue C# and WPF
C#和WPF n00b在这里。 我试图根据单元格的值为GridView中的单元格设置自定义样式。 因此,我在名称空间中定义了一个返回样式的类,在xaml中,我定义了每种样式的外观。 问题是我说错了
名称“ StatusStyle”在名称空间“ WpfApplication6”中不存在
我确定我正在做某事超级n00bie,请您帮我弄清楚。
C#代码
namespace WpfApplication6
{
public class StatusStyle : StyleSelector
{
public override Style SelectStyle(object item, DependencyObject container)
{
// returns the style..
}
}
// ...
}
WPF
<Window
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"
xmlns:local="clr-namespace:WpfApplication6"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="WpfApplication6.Window1"
xmlns:my="WpfApplication6"
mc:Ignorable="d"
Title="Window1" Height="500" Width="500">
<Grid>
<Grid.Resources>
<my:StatusStyle x:Key="statusStyle">
<my:StatusStyle.greenStyle>
<Style TargetType="telerik:GridViewCell">
<Setter Property="Background" Value="Green"/>
</Style>
</my:StatusStyle.greenStyle>
<my:StatusStyle.redStyle>
<Style TargetType="telerik:GridViewCell">
<Setter Property="Background" Value="Red" />
</Style>
</my:StatusStyle.redStyle>
</my:StatusStyle>
</Grid.Resources>
...
<Grid>
</Window>
您必须具有clr-namespace
资格。
该代码将为您服务。
<Window
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"
xmlns:my="clr-namespace:WpfApplication6"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="WpfApplication6.Window1"
mc:Ignorable="d"
Title="Window1" Height="500" Width="500">
<Grid>
<Grid.Resources>
<my:StatusStyle x:Key="statusStyle">
<my:StatusStyle.greenStyle>
<Style TargetType="telerik:GridViewCell">
<Setter Property="Background" Value="Green"/>
</Style>
</my:StatusStyle.greenStyle>
<my:StatusStyle.redStyle>
<Style TargetType="telerik:GridViewCell">
<Setter Property="Background" Value="Red" />
</Style>
</my:StatusStyle.redStyle>
</my:StatusStyle>
</Grid.Resources>
...
<Grid>
</Window>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.