XAML:
<Rectangle Fill="{Binding Gray}" />
C#:
public class colors
{
public string Gray
{
set {}
get{ return "#FF22262a";}
}
}
我编译时没有错误。但是矩形没有填写“#FF22262a”
编辑:此代码也不起作用:
MainPage.xaml
<TextBlock Text="{Binding MyGray2}"></TextBlock>
MainPage.xaml.cs
public String MyGray2
{
set { }
get { return "gjnuegheugheog"; }
}
编辑2:
<phone:PhoneApplicationPage
x:Class="FlagLib.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:FlagLib"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
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 Grid.Column="0" Tap="onToggleHorizontal" DataContext="{StaticResource vmColors}">
<Rectangle Fill="{Binding Gray}" />
...
EDIT3:
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>
颜色.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"; }
}
}
}
为什么我得到 命名空间“clr-namespace:proba5”中不存在名称“colors”。