2012-04-25 3 views
1

그래서 간단한 RSS 리더가 있는데, 앱이 시작될 때 피드가 업데이트됩니다. 읽지 않은 새 항목을 다른 색상으로 유지하는 기능을 어떻게 추가합니까? 마지막으로 사용자가 게시물을 볼 수 있도록하고 싶습니다. 마지막으로 앱을 열 때부터입니다.읽지 않은 항목을 유지하는 RSS 리더기

+0

두 가지로 나옵니다. 여러 색상으로 항목을 표시하고 읽은 내용을 기억합니다. 더 구체적인 질문은 좋을 것입니다. – Thilo

답변

3

다음과 같은 모델이 있다고 가정합니다.

public class RSSItem { 
    public bool IsUnread { get; set; } 
    public string Title { get; set; } 
} 

당신은 bool를 취하고 Color를 반환하는 IValueConverter를 사용하여 IsUnread 속성에 TextBlockForegroundColor을 바인딩 할 수 있습니다. 따라서 XAML은 다음과 같이 보일 수 있습니다.

<phone:PhoneApplicationPage.Resources> 
    <converters:UnreadForegroundConverter x:Key="UnreadForegroundConverter" /> 
</phone:PhoneApplicationPage.Resources> 

<ListBox x:Name="RSSItems"> 
    <DataTemplate> 
    <TextBlock Text="{Binding Title}" Foreground="{Binding IsUnread, Converter={StaticResource UnreadForegroundConverter}}" /> 
    </DataTemplate> 
</ListBox> 

페이지의 태그에 xmlns:converters 속성을 추가하는 것을 잊지 마십시오.

그런 다음 부울 - 색 변환을 수행하려면 IValueConverter을 구현해야합니다.

public class UnreadForegroundConverter : IValueConverter { 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { 
    if ((bool)value == true) { 
     return Application.Current.Resources["PhoneAccentColor"]; 
    } 

    return Application.Current.Resources["PhoneForegroundColor"]; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { 
    throw new NotImplementedException(); 
    } 

} 

그리고 분명히 당신은 RSSItem의 컬렉션에, 목록 상자, RSSItems을 결합해야합니다. 예 :

ObservableCollection<RSSItem> items = new ObservableCollection<RSSItem>(); 
// populate items somehow 
RSSItems.ItemsSource = items; 

희망이 있습니다.

+0

우수한 MrDavidson! –

관련 문제