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"; }
}
EDIT2:
<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"; }
}
}
}
取得した理由 名前「colors」は名前空間「clr-namespace:proba5」に存在しません。