我想根據當前選定的主題更改Windows Phone應用程序中邊框的顏色。我寫了以下內容,但不起作用。無論選擇的主題如何,它都是白色的邊框。使用C#Windows Phone 7.1更改Border.BorderBrush值
這是用於應用程序(contacts.xaml)的xaml代碼。
[XAML代碼]
<StackPanel x:Name="StackPost_Viewer">
<Border BorderBrush="White" BorderThickness="3" HorizontalAlignment="Left" Height="100" Margin="10,10,0,0" VerticalAlignment="Top" Width="436" Tap="Show_ContactList_gsecs">
<TextBlock TextWrapping="Wrap" Text="General Secretaries Social and Cultural" FontSize="36" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border BorderBrush="White" BorderThickness="3" HorizontalAlignment="Left" Height="100" Margin="10,10,0,0" VerticalAlignment="Top" Width="436" Tap="Show_ContactList_publicity">
<TextBlock TextWrapping="Wrap" Text="Publicity" FontSize="36" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border BorderBrush="White" BorderThickness="3" HorizontalAlignment="Left" Height="100" Margin="10,10,0,0" VerticalAlignment="Top" Width="436" Tap="Show_ContactList_events">
<TextBlock TextWrapping="Wrap" Text="Events" FontSize="36" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border BorderBrush="White" BorderThickness="3" HorizontalAlignment="Left" Height="100" Margin="10,10,0,0" VerticalAlignment="Top" Width="436" Tap="Show_ContactList_spons">
<TextBlock TextWrapping="Wrap" Text="Marketing and Sponsorship" FontSize="36" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border BorderBrush="White" BorderThickness="3" HorizontalAlignment="Left" Height="100" Margin="10,10,0,0" VerticalAlignment="Top" Width="436" Tap="Show_ContactList_finance">
<TextBlock TextWrapping="Wrap" Text="Finance" FontSize="36" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</StackPanel>
相應的C#代碼(contacts.xaml.cs)
[C#代碼]
public contacts()
{
InitializeComponent();
if (!isDarkTheme())
{
StackPanel main_stack = StackContact_Viewer;
var borders = main_stack.Children.OfType<Border>();
foreach (Border each in borders)
{
each.BorderBrush = new SolidColorBrush(Colors.Black);
}
}
else
{
StackPanel main_stack = StackContact_Viewer;
var borders = main_stack.Children.OfType<Border>();
foreach (var each in borders)
{
each.BorderBrush = new SolidColorBrush(Colors.White);
}
}
}
private bool isDarkTheme()
{
return Visibility.Visible == (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];
}
其實我需要的光的主題,反之亦然反向黑色邊框。所以PhoneBackgroundBrush在這裏沒有任何幫助。告訴我一些其他的方法。 – bytestorm
哦,順便說一句PhoneForegroundBrush做的工作,感謝您的想法@Kanishk – bytestorm