1

C# and WPF n00b here. I'm trying to set a custom style for a cell in a GridView, based on the value of the cell. So I'm defining a class in my namespace which returns the style and in my xaml I'm defining what each style looks like. The problem is I get an error saying

The name "StatusStyle" does not exist in the namespace "WpfApplication6"

I'm sure I'm doing something super n00bie, can you please help me figure it out.

C# Code

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 Answer 1

2

You've to qualify with clr-namespace.

This code will work for you.

<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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.