Global WPF Application Resources

Topics: CAB & Smart Client Software Factory
Jul 23, 2007 at 11:23 PM
I am trying to set styles and control templates for the WPF views in my SCSF application. In a Native WPF app, you would have app.xaml with something like:

<Application x:Class="SimpleStyles.app"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml"
>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources\Shared.xaml" />
<ResourceDictionary Source="Resources\Button.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>


Then, in your xaml files, you can access any style definitions in these resources, just by setting the style property on your Control/Window/UserControl etc. Since SCSF uses WPF interop, I'm not sure how to set up the styles so that they are picked up by the application, and made available to the Interop WPF smart parts.

I tried dropping this file into the root directory of one of the modules, but as expected, it didnt work.
Developer
Jul 24, 2007 at 7:58 PM
Hi, try adding the following in your views:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources\Shared.xaml"/>
            <ResourceDictionary Source="Resources\Button.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>
Please let me know if this helps,

Ezequiel Jadib
http://staff.southworks.net/blogs/ejadib
Dec 6, 2007 at 4:52 AM
I am having the same problem... Here is what I have....

<UserControl x:Class="KeeWise.EZVote.SettingsModule.UpdateCounty"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="204.276666666667" Width="240.976666666667" Padding="0,0,0,0" FontFamily="Times New Roman" FontSize="12">

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources\ButtonStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>

....

<Button Style="{DynamicResource SaveButtonStyle}" Grid.Row="5" Name="btnSave" Margin="79.0000000000002,0,0,0">Save</Button>
<Button Style="{DynamicResource CancelButtonStyle}" Grid.Column="1" Grid.Row="5" Name="btnCancel" Grid.ColumnSpan="2" Margin="11.9766666666668,0,0,0">Cancel</Button>
</Grid>
</UserControl>

In my project I added a Resources Folder.. and a ButtonStyles.xaml file with my styles defined.... But no matter what I try I get the Value cannot be assigned to source error...