这个ObjectDataProvider声明有什么问题? [英] What is wrong with this ObjectDataProvider declaration?

查看:52
本文介绍了这个ObjectDataProvider声明有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个小应用程序来显示System.Windows.Media.Colors和System.Drawing.SystemColors,使用ObjectDataProvider来包装两个数据源。奇怪的是,Colors有效,但SystemColors没有。这是令人困惑的,因为
两者都定义为公共静态颜色xxx {get;}

I was attempting to create a small application to display both System.Windows.Media.Colors and System.Drawing.SystemColors using ObjectDataProvider to wrap the two data sources. Oddly, Colors works but SystemColors does not. This is confusing given that the two are both defined as public static Color xxx {get;}

这是XAML。

<Window x:Class="WpfColors.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:d="clr-namespace:System.Drawing;assembly=System.Drawing"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="800" Width="1000">
    
    <Window.Resources>
        
        <ObjectDataProvider 
            ObjectType="{x:Type sys:Type}"
            x:Key="colorsTypeOdp"
            MethodName="GetType" 
            >
            <ObjectDataProvider.MethodParameters>
                <sys:String>
                    System.Windows.Media.Colors, 
                    PresentationCore
                </sys:String>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider 
            ObjectInstance="{StaticResource colorsTypeOdp}" 
            MethodName="GetProperties" 
            x:Key="colorPropertiesOdp">
        </ObjectDataProvider>

        <ObjectDataProvider 
            ObjectType="{x:Type sys:Type}"
            x:Key="colorsSystem"
            MethodName="GetType" 
            >
            <ObjectDataProvider.MethodParameters>
                <sys:String>
                    System.Drawing.SystemColors, 
                    System.Drawing
                </sys:String>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider 
            ObjectInstance="{StaticResource colorsSystem}" 
            MethodName="GetProperties" 
            x:Key="colorPropertiesSysColors">
        </ObjectDataProvider>

    </Window.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>

        <ListBox 
            Grid.Row="0"
            ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ScrollViewer.VerticalScrollBarVisibility="Auto" >
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <Rectangle Fill="{Binding Path=Name}" Stroke="Black" Margin="4" StrokeThickness="1" Height="50" Width="130"/>
                        <Label Content="{Binding Path=Name}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <ListBox 
            Grid.Row="1"
            ItemsSource="{Binding Source={StaticResource colorPropertiesSysColors}}"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ScrollViewer.VerticalScrollBarVisibility="Auto" >
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <Rectangle Fill="{Binding Path=Name}" Stroke="Black" Margin="4" StrokeThickness="1" Height="50" Width="130"/>
                        <Label Content="{Binding Path=Name}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>


    </Grid>
</Window>

在设计时我们是这样的:

At design time we something like this:

因此,Colors在设计期间正在运行。显示颜色和颜色名称。但是,SystemColors只在中途进行。从插入的图像中可以看到,颜色的名称可用,但Rectangle.Fill不是
工作。建议?

So, Colors is working during design time. Both a color and a name of the color are displayed. However, SystemColors is only making it halfway there. As you can see from the inserted image, the name of the color is available but the Rectangle.Fill is not working. Suggestions?

Richard Lewis Haggard

Richard Lewis Haggard

推荐答案

你好,

我使用xaml代码进行了一些测试,在某个级别我发现了" Type.GetType()"方法在运行时没有工作,它只是通过调试cs代码并调用

i did some tests using the xaml code, at certain level I found that the "Type.GetType()" method is not working at runtime, and it was just by debugging the cs code and calling the

Type.GetType("qualified assembly name", throwOnError:
 true) // this time using the throwOnError parameter, to see stacktrace if there is an error

方法在Window上加载事件,发现运行时无法加载所需的程序集, 然后我测试了在构建时将它们复制到localy,然后现在一切正常,但仍然试图理解为什么运行时没有加载这些程序集? 

method on Window load event, and found that the runtime is unable to load needed assemblies,  and then I tested to copy them localy on build, and then all is working fine now, but still try to understand why the runtime didnt load those assemblies ? 

希望有所帮助,

良好的编码;


这篇关于这个ObjectDataProvider声明有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆