2012-08-28 4 views
7
<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 

<LinearGradientBrush x:Key="ButtonNormalBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0"> 
    <GradientStop Color="#C10099FF" Offset="0"/> 
    <GradientStop Color="#C16699CC" Offset="1"/> 
    <GradientStop Color="#C1006699" Offset="0.49"/> 
</LinearGradientBrush> 
<ResourceDictionary/> 

Jetzt möchte ich LinearGradientBrush von ResourceDictorary erhalten und es dynamisch auf eine Schaltfläche als Hintergrundfarbe in WPF anwenden.Wie bekomme ich Brushes vom Resource Dictionary und wende es auf ein dynamisches Element in wpf an?

Ich möchte die obige Farbe stattdessen (Brushes.Green) anwenden. Was soll ich dafür tun?

Antwort

14

Angenommen, Ihre Resource im Kontext zur Verfügung:

<Button Background="{DynamicResource ResourceKey=ButtonNormalBackgroundBrush}" /> 

oder in dem Code

button.Background = (Brush)FindResource("ButtonNormalBackgroundBrush"); 
4
BtnGetBrushes.Background = this.Resources["ButtonNormalBackgroundBrush"] as LinearGradientBrush; 
+0

Works für mich auf Windows Phone 8.0 Silverlight – aloisdg

Verwandte Themen