매우 쉽게 처리해야하는 문제가 있습니다. Windows phone 8에 대한 홍수 경고 응용 프로그램을 만들고 있습니다. 정수가 Severity
인데, 이는 JSON 피드에서 가져온 1에서 4까지의 숫자가 될 수 있습니다. 단순히 int를 심각도에 해당하는 문자열로 변경 한 다음 문자열을 사용하여 바인딩을 통해 텍스트 블록을 채 웁니다. 여기에 다음 코드JSON에 의해 생성 된 변수를 C로 변경하는 방법 #
namespace FloodAlertsApp
{
public class RootObject
{
public int Severity { get; set; }
public string AreaDescription { get; set; }
public string Raised { get; set; }
public string severityTxt;
public string getsevText()
{
switch (Severity)
{
case 1:
severityTxt = "Severe";
break;
case 2:
severityTxt = "Warning";
break;
case 3:
severityTxt = "Alert";
break;
case 4:
severityTxt = "";
break;
}
return severityTxt;
}
}
그리고 난 다음과 같이 바인딩이 사용하고있어 XAML,
<phone:PhoneApplicationPage
x:Class="FloodAlertsApp.ListView"
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:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<!--<RowDefinition Height="Auto"/>-->
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Width="Auto" HorizontalAlignment="Center" Margin="10,10,10,10">
<Image Width="Auto" Source="/nrw_logo_linear.png" Stretch="Fill"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0">
<ListBox Name="listBoxBeaches" SelectionChanged="listBoxBeaches_SelectionChanged" Margin="10,10,10,0" Padding="0,0,0,100" Height="{Binding ElementName=ContentPanel, Path=ActualHeight}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Grid.Row="0" x:Name="TemplateLayout" Margin="0,5,0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="60" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" x:Name="Stackpnl">
<TextBlock Foreground="Black" FontSize="28" Margin="5,0,5,0" Text="{Binding Path=AreaDescription}"></TextBlock>
Here be the binding----> <TextBlock Foreground="Black" FontSize="28" Margin="5,0,5,0" Text="{Binding Path=SeverityTxt}"></TextBlock>
<TextBlock Foreground="Black" FontSize="22" Margin="5,0,5,0" Text="Raised at "></TextBlock>
<TextBlock Foreground="Black" FontSize="22" Margin="5,0,5,0" Text="{Binding Path=Raised}"></TextBlock>
</StackPanel>
<Ellipse Grid.Row="0" Grid.Column="1" Margin="5,0,5,0" x:Name="StatusEllipse" Height="50" Width="50" Fill="{Binding Path = Colour}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
</phone:PhoneApplicationPage>
이 다른 바인딩이 잘 작동하지만,의 I는 int에서 String으로 변경하려고하면 바인딩은 아무 것도 아닌 것처럼 보입니다.
열거 형을 사용하지 않는 이유는 무엇입니까? –
이 경우 Enum을 어떻게 사용할 수 있습니까? – Marushiru