2

我想将 MyEnum 的具体值作为 GetValues 方法的参数从 MyItemSourceProvider 传递。请问怎么写?

<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type local:MyItemSourceProvider}">
    <ObjectDataProvider.MethodParameters>
        <!-- ENUM value (e.g. MyEnum.Record1) -->       
    </ObjectDataProvider.MethodParameters>        
</ObjectDataProvider>

方法:

public System.Collections.IEnumerable GetValues(MyEnum key) {}
public enum MyEnum {Record1, ...}
4

3 回答 3

3

您可以按以下方式实现它:

<ObjectDataProvider MethodName="GetValues" 
                    ObjectType="{x:Type local:MyItemSourceProvider}" 
                    x:Key="getValues">
    <ObjectDataProvider.MethodParameters>
        <local:MyEnum>Record1</local:MyEnum>
    </ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

或者你也可以这样做:

<ObjectDataProvider MethodName="GetValues" 
                    ObjectType="{x:Type local:MyItemSourceProvider}" 
                    x:Key="getValues">
    <ObjectDataProvider.MethodParameters>
        <x:Static Member="local:MyEnum.Record1" />
    </ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

和:

public enum MyEnum {Record1, Record2, ...}
于 2011-10-10T15:37:51.910 回答
1

尝试这个:

<Window.Resources>    
  <local:MyEnum x:Key="valueToPassIn">Record1</local:MyEnum>
  <x:Type x:Key="typeToPassIn" TypeName="local:MyEnum" />      

  <ObjectDataProvider MethodName="GetValues"        
      ObjectType="{x:Type sys:Enum}"        
      x:Key="ExampleEnumValues"
      MethodParameters="{StaticResource valueToPassIn}">        
   </ObjectDataProvider>
 </Window.Resources>
于 2010-09-20T12:58:44.380 回答
0

你可能已经找到答案了。如果没有你可以看这里 -

http://msdn.microsoft.com/en-us/library/bb613576.aspx

或者

<Window x:Class="SimpleXmlDataSourceExample.MainWindow2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Sys="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:SimpleXmlDataSourceExample"
    Title="MainWindow2" Height="300" Width="403">
<Window.Resources>
    <ObjectDataProvider x:Key="deptEnumSource" ObjectType="{x:Type Sys:Enum}" MethodName="GetValues" >
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="local:DeptEnum"></x:Type>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</Window.Resources>
<Grid>
    <ComboBox Height="23" HorizontalAlignment="Left" Margin="69,68,0,0" Name="comboBox1" 
              VerticalAlignment="Top" 
              Width="156"  
              ItemsSource="{Binding Source={StaticResource deptEnumSource}}"  
              >
    </ComboBox>
</Grid>

在这个链接中:

http://wpfgrid.blogspot.com/2013/01/v-behaviorurldefaultvmlo_10.html

于 2013-01-10T20:56:37.377 回答