Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

XamlReader.Load throws error : Item has already been added. Key in dictionary: 'NewBrushKey' Key being added: 'NewBrushKey'

$
0
0

Hi,

I am getting the below error while i am cloning my WPF control using XamlReader.Load method.

XamlReader.Load throws error : Item has already been added. Key in dictionary: 'NewBrushKey'  Key being added: 'NewBrushKey'

XAML:
<UserControl x:Class="TestProject.UIControl">
    <UserControl.Resources>
 <SolidColorBrush x:Key="NewBrushKey" Color="Red" />
    </UserControl.Resources>
    <Border BorderBrush="{StaticResource NewBrushKey}" BorderThickness="2">
 <Grid>
     ...
     ...
     ...
 </Grid>
    </Border>
</UserControl

//User control is reused in this window.
<Window>
    <Grid x:Name="UIControlContainer">
 ...
 ...
 <ctrl:UIControl x:Name="firstUIControl" />
 <ctrl:UIControl x:Name="secondUIControl" />
    </Grid>
<Window>

C#:
//UIControlContainer object is closed using XAML Parser in code behind.

string _containerStr = XamlWriter.Save(UIControlContainer);
StringReader _strReader = new StringReader(_containerStr);
XmlTextReader _xmlReader = new XmlTextReader(_strReader);
UIElement _containerClone = (UIElement)XamlReader.Load(_xmlReader);


But XamlReader.Load(_xmlReader) method throws "Item has already been added. Key in dictionary: 'NewBrushKey'  Key being added: 'NewBrushKey'"

Please help me how to solve this problem.


Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This will help other members to find the solution easily.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>