Tech Off Thread

1 post

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

problems using resources in wpf-winfx

Back to Forum: Tech Off
  • User profile image
    trun_gup

    i am using resources in stringresources.xaml

    <
    ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:sys="clr-namespace:System">
    <
    sys:String x:Key="StringOne">This is the first string</sys:String>
    </ResourceDictionary>

    and made changes to application file as:

    <Application x:Class="locRes1.MyApp"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">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="StringResources.xaml" /></ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>

    </Application.Resources>

    </Application>

    and written following code to retreive the resource:

    button1 = new Button();
    button1.Style = style1;
    String str1 = (String)Application.Current.FindResource("StringOne");
    button1.Content = str1;
    button1.Height = 60;
    button1.Width = 250;

     
    its working fine, but problem is if i try to add resources to "StringResources.xaml" throgh:


    ResourceDictionary rd=new ResourceDictionary();
    rd.Add(
    "str", "abc"); Application.Current.Resources.MergedDictionaries.Add(rd);


    m not able to write or add resources into it. 

    please guide
    how to add resource to an existing xaml file programatically

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.