开发者

Data binding causing WPF designer error

开发者 https://www.devze.com 2022-12-18 07:15 出处:网络
Does anyone know why this binding is causing an error in the WPF designer? (\"Exception has been thrown by the target of an invocation.\")

Does anyone know why this binding is causing an error in the WPF designer? ("Exception has been thrown by the target of an invocation.")

XAML (partial):

<Window xmlns:local="clr-namespace:MyAppNa开发者_如何转开发mespace">
    <DataGrid ItemsSource="{Binding Source={x:Static local:Clients.Instance},
                                    Path=ClientList}" />
</Window>

C#:

namespace MyAppNamespace
{
    public sealed class Clients
    {
        // Singleton pattern
        public static readonly Clients Instance = new Clients();
        private Clients() { }
        static Clients()
        {
            clientList = new ObservableCollection<Client>();
            PopulateClientList();
        }

        private static ObservableCollection<Client> clientList;
        public static ObservableCollection<Client> ClientList
        {
            get { return clientList; }
            set { clientList = value; }
        }

        public static void PopulateClientList()
        {
            // .. load client data from xml
        }

        public class Client
        {
            // ... expose public properties for fields in provided xml element
        }
    }
}


I would bet there's some code inside PopulateClientList() that's failing when run from the AppDomain the designer is running the code from.

If you're loading XML from a file, maybe the physical path isn't in the same relative location, or something like that.


try replacing your include statement with "clr-namespace:MyAppNamespace;assembly=" adding the assembly. you dont have to enter the assembly name. its a bug with visual studio.

0

精彩评论

暂无评论...
验证码 换一张
取 消