Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XamlReader Wall
Message
De
07/03/2009 15:01:18
 
 
À
06/03/2009 13:40:49
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Titre:
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01386282
Message ID:
01386442
Vues:
37
>Hi,
>
>How to avoid the problem below (I see what the problem is : you get two items with the same name) but I can't find any working code for a fix. Simple UserControl:
UserControl x:Class="WpfApplication1.MinimalControl"
>    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>    Height="300" Width="300">
>    <TextBlock x:Name="Fred" />
></UserControl>
Used in this form:
<Window x:Class="WpfApplication1.MinimalForm"
>    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>    xmlns:uc="clr-namespace:WpfApplication1"
>    Title="MinimalForm" Height="300" Width="300">
>    <StackPanel>
>        <Canvas x:Name="ACanvas">
>            <uc:MinimalControl />
>            <uc:MinimalControl />
>        </Canvas>
>        <Button Click="Button_Click" >Try</Button>
>    </StackPanel>
></Window>
Here's the test code behind:
using System.Windows;
>using System.Windows.Controls;
>
>namespace WpfApplication1
>{
>    /// <summary>
>    /// Interaction logic for MinimalForm.xaml
>    /// </summary>
>    public partial class MinimalForm : Window
>    {
>        public MinimalForm()
>        {
>            InitializeComponent();
>        }
>
>        private void Button_Click(object sender, RoutedEventArgs e)
>        {
>            string s = System.Windows.Markup.XamlWriter.Save(ACanvas);
>            System.IO.StringReader stringReader = new System.IO.StringReader(s);
>            System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader);
>            //Exception here:
>            Canvas x = (Canvas)System.Windows.Markup.XamlReader.Load(xmlReader);
>        }
>    }
>}
Any way of manipulating the NameScope (or something) to avoid this ?
>Regards,
>Viv

I don't see an easy way around it. But here is one solution:

http://www.ddj.com/windows/209800469?pgno=2
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform