Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4258824
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:42:04+00:00 2026-05-21T05:42:04+00:00

I have a XAML Window that has a set of strings that are bound

  • 0

I have a XAML Window that has a set of strings that are bound to objects like so:

<Label Content="{StaticResource LabelUserName}" HorizontalAlignment="Right" Name="Label1" VerticalAlignment="Center" />

This code works fine when I define my ResouceDictionary like this:

<Window.Resources>
    <ResourceDictionary >
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Strings/Strings_en-US.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <ObjectDataProvider x:Key="objLogon" ObjectType="{x:Type StarUtilities:Logon}" />
    </ResourceDictionary>
</Window.Resources>

However, I want to beable to change where the strings are bound from, so I created a module that looks like this:

Public Module LocalizationChooser
    Public ReadOnly Property GetLocalization As Uri
        Get
            Return New Uri("/Strings/Strings_en-US.xaml", UriKind.Relative)
        End Get
    End Property
End Module

Then I decided I would try changing the Source to a Binding string. However, I’ve tried the following and none work:

<ResourceDictionary Source="{Binding Source={x:Static Member=StarUI:LocalizationChooser.GetLocalization}}" />
<ResourceDictionary Source="{x:Static Member=StarUI:LocalizationChooser.GetLocalization}" />
<ResourceDictionary Source="{Binding Source=StarUI:LocalizationChooser.GetLocalization}" />
<ResourceDictionary Source="{Binding Source=LocalizationChooser, Path=GetLocalization}" />
<ResourceDictionary Source="{Binding Source=StarUI:LocalizationChooser, Path=GetLocalization}" />
<ResourceDictionary Source="{Binding Source={x:Static Member=StarUI:LocalizationChooser.GetLocalization}, Path=GetLocalization}" />
<ResourceDictionary Source="{Binding Source={x:Static Member=StarUI:LocalizationChooser.GetLocalization}, Path=LocalizationChooser.GetLocalization}" />
<ResourceDictionary Source="{Binding Source={x:Static Member=StarUI:LocalizationChooser.GetLocalization}, Path=StarUI:LocalizationChooser.GetLocalization}" />

All generate the same error:

ArgumentNullException was thrown on “ResourceDictionary”: Value cannot be null.
Parameter name: item

What can I do to get this working?

I should mention that the StarUI namespace is already defined as the following:

xmlns:StarUI="clr-namespace:StarUI"

EDIT:
I found that with the change I made to the module I can get the code to compile and run if I use:

<ResourceDictionary Source="{x:Static StarUI:LocalizationChooser.GetLocalization}" />

However, I still don’t have design-time support. Since the module is returning a static item that doesn’t need to lookup anything, is there a way to get design-time support here? If not, is there a way to specify in the XAML a static reference for design-time and then they dynamic reference for run-time?

EDIT 2:
What I finally did was to write the XAML specifying the Source statically and then setting the constructor to ‘overwrite’ that. Since dictionary entries with the same name will be referenced based on the last one added, I can add a dictionary at run-time but still have a dictionary at design-time.

I used the following to localize my code simply, including design-time support and enabling dynamic changing of languages.

In my XAML I included:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary x:Name="LocalizationStrings" Source="/Strings/Strings_en-US.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <ObjectDataProvider x:Key="objLogon" ObjectType="{x:Type StarUtilities:Logon}" />
    </ResourceDictionary>
</Window.Resources>

In my code-behind:

Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.
    Me.Resources.MergedDictionaries.Add(GetLocalization)
End Sub

GetLocation is in a Public Module:

Public ReadOnly Property GetLocalization As ResourceDictionary
    Get
        Dim resourceLocalization As New ResourceDictionary
        resourceLocalization.Source = New Uri("/Strings/Strings_zh-cn.xaml", UriKind.Relative)
        Return resourceLocalization
    End Get
End Property

A sample of my ResourceDictionary XAML is:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <sys:String x:Key="ButtonLogon">Logon</sys:String>
    <sys:String x:Key="ButtonCancel">Cancel</sys:String>
    <sys:String x:Key="LabelUserName">User Name:</sys:String>
    <sys:String x:Key="LabelPassword">Password:</sys:String>
    <sys:String x:Key="LabelKey">Decryption Key:</sys:String>
</ResourceDictionary>

Then I just access the language string via:

<Label Content="{DynamicResource LabelUserName}" Name="Label1" />

Now everything works great!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:42:05+00:00Added an answer on May 21, 2026 at 5:42 am

    You would need to switch from StaticResource to DynamicResource, since your resource isn’t immediately available.

    But you cannot using Bindings on the ResourceDictionary properties, as it does not derive from DependencyObject.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a context menu that's bound to a list of strings so that
I have a very simple list of objects that represt people. Each object has
I have a user control that has a Title property bound to the Text
I have an app that has a ListBox of ListBoxes. I would like to
I have a simple WPF window that has 12 buttons on it. I want
I have an WPF usercontrol that has a TextBox. I set the text Underline
I have a window that has a StackPanel, and the StackPanel has a ContentControl,
I have two projects, a resourcelibrary which holds a xaml file that simply has
I have a UserControl (XAML below) that has a ListBox that I want to
I have a XAML window with multiple TextBoxes, each with a corresponding TextBlock tag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.