<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.Resources>
<local:EnumBooleanConverter x:Key="enumBooleanConverter"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Vertical">
<RadioButton GroupName="week" Content="China" IsChecked="{Binding Path=Country,Converter={StaticResource enumBooleanConverter}
,ConverterParameter=China}"/>
<RadioButton GroupName="week" Content="Japan" IsChecked="{Binding Path=Country,Converter={StaticResource enumBooleanConverter}
,ConverterParameter=Japan}"/>
</StackPanel>
</Grid>
</Grid>
namespace Demo1
{
public partial class Page3 : PhoneApplicationPage
{
public Page3()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
PersonInfo p = new PersonInfo { Name = "tony", Sex = 1, BirthDay = DateTime.Now, Country = CountryEnum.Japan };
this.DataContext = p;
}
}
}
------------------------------------------------------------------------------
EnumBooleanConverter
namespace Demo1
{
public class EnumBooleanConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
{
return DependencyProperty.UnsetValue;
}
if (Enum.IsDefined(value.GetType(), value) == false)
{
return DependencyProperty.UnsetValue;
}
object parameterValue = Enum.Parse(value.GetType(), parameterString, true);
return parameterValue.Equals(value);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;
return Enum.Parse(targetType, parameterString,true);
}
}
}
--------------------------------------------
namespace Demo1
{
public enum CountryEnum
{
China,
Japan,
UK,
Ireland,
USA
}
}