2014-02-19 2 views
0

시각 장애인 용 WP8 응용 프로그램을 개발 중이며 응용 프로그램 내에서 글꼴 색상을 변경할 수 있도록 노력하고 있습니다. 나에게 도움이되는 API가 없다. 내가 뭘 하려는지 longlistselector에 색상 목록이있을 것입니다 그리고 사용자가 색상을 선택하고 전체 응용 프로그램 글꼴 색상이 변경됩니다. 나는 방금 시작한이 세상에서 최고의 프로그래머가 아니며,이 응용 프로그램은 내 가족 중 한 사람에게 갈 것입니다. 내가 붙어있는 부분은 그것을 바꾸려고 노력하고있다. 나는 그것을 선택할 수는 있지만, 아무데도 가지 않는다. 어떤 조언이나 조언이 좋을 것이다.WP8 응용 프로그램 내에서 글꼴 색상을 변경하는 방법

public MainPage() 
{ 
    InitializeComponent(); 
    font.Add(new Theme1() { ThemeText = "White", ThemeFontSize = "40" }); 
    font.Add(new Theme1() { ThemeText = "Green", ThemeFontSize = "40" }); 
    font.Add(new Theme1() { ThemeText = "Blue", ThemeFontSize = "40" }); 

    LLsFontList.ItemsSource = font; 
} 


private void LLsFontList_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
{ 
    if (LLsFontList != null && LLsFontList.SelectedItem != null) 
    { 
     var selectedItem = LLsFontList.SelectedItem as Theme1; 
     SayWords(selectedItem.ThemeText + "\r\n"); 
     var id = selectedItem.ThemeText.FirstOrDefault(); 
    } 
} 

여기가 멈춰서 고,이 호출을 리소스 파일에 보내야 전체 응용 프로그램이 변경됩니다.

+0

그러나 텍스트에 테마를 어떻게 적용합니까? Theme1 클래스 란 무엇입니까? – Romasz

+0

테마 1 클래스는 모든 집합과 가져 오기가있는 곳입니다. –

답변

1

내 솔루션이 가장 우아하지는 않지만 이것이 당신을 끌어들일 수 있기를 희망합니다.

좋아, 여기처럼 테마 클래스가 보일 것입니다 방법은 다음과 같습니다

<TextBlock x:Name="TextBlock" Text="{Binding ThemeText}" FontSize="{Binding FontSize}" Foreground="{Binding FontColor}"/> 

하는 코드 숨김 : 당신이해야 그런 다음 textblocks 및 테마 클래스의 객체 사이의 바인딩을 만들

public class Theme : INotifyPropertyChanged  
{ 
public event PropertyChangedEventHandler PropertyChanged; 

private string themeText; 
public string ThemeText 
{ 
    get 
    { 
     return themeText; 
    } 
    set 
    { 
     themeText = value; 
     OnPropertyChanged("ThemeText"); 
    } 
} 

private int fontSize; 
public int FontSize 
{ 
    get 
    { 
     return fontSize; 
    } 
    set 
    { 
     fontSize = value; 
     OnPropertyChanged("FontSize"); 
    } 
} 

private Brush fontColor; 
public Brush FontColor 
{ 
    get 
    { 
     return fontColor; 
    } 
    set 
    { 
     fontColor = value; 
     OnPropertyChanged("FontColor"); 
    } 
} 

protected void OnPropertyChanged(string name) 
{ 
    PropertyChangedEventHandler handler = this.PropertyChanged; 
    if (handler != null) 
     handler(this, new PropertyChangedEventArgs(name)); 
} 
} 

일부 기본값을 가진 전역 테마 객체 :

Theme theme = new Theme 
{ 
    ThemeText = "Red", 
    FontColor = new SolidColorBrush(Colors.Red), 
    FontSize = 40 
}; 

그런 다음 사용자의 DataContext를 설정합니다. (페이지 생성자 내부) 그것에 r에 TextBlock의 :

TextBlock.DataContext = theme; 

그리고 당신이 그것을 변경하려는 경우, 그냥 이런 식으로 할 : 당신은 질문이있는 경우

theme.ThemeText = "Blue"; 
theme.FontColor = new SolidColorBrush(Colors.Blue); 
theme.FontSize = 60; 

은 주저하지 않습니다를 그들.

관련 문제