Yaroslav Shabanov
Yaroslav Shabanov

Reputation: 283

The name does not exist in the namespace

I try to set color of rectangle from C# code. In other topic help me to use DataContext but can not bind class colors and key vmColors

MainPage.xaml:

<phone:PhoneApplicationPage
    x:Class="proba5.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:vm="clr-namespace:proba5" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <phone:PhoneApplicationPage.Resources>
        <vm:colors x:Key="vmColors"/>
    </phone:PhoneApplicationPage.Resources>


    <Grid x:Name="LayoutRoot" Background="Transparent">


        <Grid DataContext="{StaticResource vmColors}">
            <Rectangle Fill="{Binding Gray}" />
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

colors.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace proba5
{
    public class colors
    {
        public string Gray
        {
            set { }
            get { return "#FF22262a"; }
        }
    }
}

Why i got The name "colors" does not exist in the namespace "clr-namespace:proba5".

Upvotes: 0

Views: 2495

Answers (2)

Volker Voecking
Volker Voecking

Reputation: 5573

Sometimes Visual Studio is not able to resolve names in XAML files if there are other compilation errors in the project or solution.

Try to fix all the other errors (and warnings). Then do a rebuild.

Upvotes: 1

Yaroslav Shabanov
Yaroslav Shabanov

Reputation: 283

Change property of colors.cs "Copy to Output Directory" to "Copy Always" and it's work!

Upvotes: 1

Related Questions