0
我正試圖完成一個應用程序,並且我還有一個小的煩惱。我無法使用listpicker在「設置」頁面的主頁上更改文本框上的字體。我創建了一個小測試應用程序,所以我不會搞亂我的真實應用程序。我希望有人能幫幫忙。使用設置頁面來更改主頁上的字體顏色
我所擁有的是2頁app主頁和文本頁面。我在主頁上有一個文本框,我從文本頁面的文本頁面填充,允許用戶選擇字體樣式和顏色。我可以改變風格而不是顏色......一些文本框僅用於測試。 txtMain文本框是將包含該字體的文本框。
炫魅
public partial class MainPage : PhoneApplicationPage
{
private IsolatedStorageSettings appsettings = IsolatedStorageSettings.ApplicationSettings;
public MainPage()
{
InitializeComponent();
if (appsettings.Contains("font"))
{
txtMain.Text = appsettings["font"].ToString();
}
if (appsettings.Contains("fontColor"))
{
string newColor = appsettings["fontColor"].ToString();
txtColor.Text = newColor;
}
if (appsettings.Contains("colorSelect"))
{
string _colorSelect = appsettings["colorSelect"].ToString();
txtColorSelect.Text = _colorSelect;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/text.xaml", UriKind.Relative));
}
}
文本頁面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Media;
using System.IO.IsolatedStorage;
namespace test_font_color
{
public partial class text : PhoneApplicationPage
{
private IsolatedStorageSettings appsettings = IsolatedStorageSettings.ApplicationSettings;
public SolidColorBrush colorSelection;
public text()
{
InitializeComponent();
//**********************for list box*************************
List<colorChoices> source = new List<colorChoices>();
source.Add(new colorChoices() { pickedColorBlock = Colors.Black.ToString(), pickedColor = "Black", pickedSolidColorBrush = new SolidColorBrush(Colors.Black) });
source.Add(new colorChoices() { pickedColorBlock = Colors.White.ToString(), pickedColor = "White", pickedSolidColorBrush = new SolidColorBrush(Colors.White) });
source.Add(new colorChoices() { pickedColorBlock = Colors.Red.ToString(), pickedColor = "Red", pickedSolidColorBrush = new SolidColorBrush(Colors.Red) });
this.lstColors.ItemsSource = source;
this.lstColors.SelectionChanged += new SelectionChangedEventHandler(lstColors_SelectionChanged);
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
if (appsettings.Contains("font"))
{
appsettings.Remove("font");
appsettings.Add("font", txtEnter.Text);
}
else
{
appsettings.Add("font", txtEnter.Text);
}
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
public class colorChoices
{
//public Color pickedColorBlock
public string pickedColorBlock
{
get;
set;
}
public string pickedColor
{
get;
set;
}
public SolidColorBrush pickedSolidColorBrush
{
get;
set;
}
}
void lstColors_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
colorSelection = ((colorChoices)(lstColors.Items[lstColors.SelectedIndex])).pickedSolidColorBrush;
}
private void changeColor_Click(object sender, RoutedEventArgs e)
{
txtEnter.Foreground = colorSelection;
appsettings.Add("fontColor", txtEnter.Foreground);
appsettings.Add("colorSelect", colorSelection);
}
}
}
我不明白你的意思。你想要一個設置頁面,用戶可以選擇顏色和字體。在主頁面中,您希望txtMain中的文本具有選定的顏色和字體(例如黑色和Arial)? – venerik 2014-10-01 18:55:24
沒錯。在「設置」頁面中,用戶將輸入他們想要的文本,選擇字體,然後選擇字體的顏色。那麼這將覆蓋他們之前選擇的照片,並顯示在主頁上 – branedge 2014-10-02 02:02:36