sss hima

sss hima

  • 0
  • 6
  • 0

Dynamic Resource Style in WPF

Feb 18 2010 11:50 PM

Hi All,
In my WPF application I Wrote some styles for button in App.xaml and in my Window.xaml    I mentioned Style="{DynamicResource MyStyle1}" for a button but that style is not getting reflected when i run the application. Let me know how do i get those styles..

This is the code i placed in App.xaml
<Application x:Class="WpfInDetail.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Page2.xaml">
<Application.Resources>
<Style x:Name="MyButtonStyle" TargetType="Button">
<Setter Property="Foreground" Value="Red" />
<Setter Property="Background" Value="Yellow"></Setter>
<Setter Property="FontSize" Value="14"></Setter>
</Style>
</Application.Resources>
</Application>

and the following is the code in window. xaml
<Window x:Class="WpfInDetail.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300">
<Grid>
<StackPanel >
<Button Name="MyTextBlock" Height="50" Width="80" VerticalAlignment="Center" HorizontalAlignment="Center" Style="{DynamicResource MyButtonStyle}" Content="Hyma...." />
</StackPanel>
</Grid>
</Window>

Now as i added i am not getting the styles reflected in UI let me know if there are any issues in thecode and what is a Dynamic Resource in WPF

 


Brought to you by:

Answers (2)