命名空间问题C#和WPF

时间:2015-08-27 04:07:49

标签: c# wpf

C#和WPF n00b在这里。我正在尝试根据单元格的值为GridView中的单元格设置自定义样式。所以我在我的命名空间中定义了一个返回样式的类,在我的xaml中我定义了每个样式的样子。问题是我收到错误

  

命名空间中不存在名称“StatusStyle”   “WpfApplication6”

我确定我正在做一些超级好的事,你能帮我解决一下吗。

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>

1 个答案:

答案 0 :(得分:2)

您必须符合<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> 的资格。

此代码适合您。

mvn archetype:create -DgroupId=com.east.test -DartifactId=helloworld -DarchetypeArtifactId=maven-archetype-webapp